Skip to content

Commit

Permalink
fix(api): tests
Browse files Browse the repository at this point in the history
  • Loading branch information
djabarovgeorge committed Oct 20, 2024
1 parent 9acc2b9 commit e44ea5c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
NotificationGroupRepository,
NotificationStepEntity,
NotificationTemplateEntity,
NotificationTemplateRepository,
PreferencesEntity,
} from '@novu/dal';
import {
Expand Down Expand Up @@ -273,7 +272,7 @@ export class UpsertWorkflowUseCase {
controls: step.controls,
content: '',
},
stepId: step.stepId || slugifyName(step.name),
stepId: slugifyName(step.name),
name: step.name,
};
}
Expand Down
24 changes: 20 additions & 4 deletions apps/api/src/app/workflows-v2/workflow.controller.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
ListWorkflowResponse,
StepCreateDto,
StepDto,
StepResponseDto,
StepTypeEnum,
StepUpdateDto,
UpdateWorkflowDto,
Expand Down Expand Up @@ -226,7 +227,7 @@ async function createWorkflowAndValidate(nameSuffix: string = ''): Promise<Workf
'type'
);
createdWorkflowWithoutUpdateDate.steps = createdWorkflowWithoutUpdateDate.steps.map((step) =>
removeFields(step, 'stepUuid')
removeFields(step, 'stepUuid', 'stepId')
);
expect(createdWorkflowWithoutUpdateDate).to.deep.equal(
removeFields(createWorkflowDto, '__source'),
Expand All @@ -243,7 +244,6 @@ function buildEmailStep(): StepDto {
schema: channelStepSchemas.email.output,
},
name: 'Email Test Step',
stepId: 'email-test-step',
type: StepTypeEnum.EMAIL,
};
}
Expand All @@ -255,7 +255,6 @@ function buildInAppStep(): StepDto {
schema: channelStepSchemas.in_app.output,
},
name: 'In-App Test Step',
stepId: 'in-app-test-step',
type: StepTypeEnum.IN_APP,
};
}
Expand Down Expand Up @@ -317,6 +316,18 @@ function findStepOnRequestBasedOnId(workflowUpdateRequest: UpdateWorkflowDto, st
return undefined;
}

/*
* There's a side effect on the backend where the stepId gets updated based on the step name.
* We need to make a design decision on the client side, should we allow users to update the stepId separately.
*/
function updateStepId(step: StepResponseDto): StepResponseDto {
if (step.stepId) {
return { ...step, stepId: slugifyName(step.name) };
}

return step;
}

function validateUpdatedWorkflowAndRemoveResponseFields(
workflowResponse: WorkflowResponseDto,
workflowUpdateRequest: UpdateWorkflowDto
Expand Down Expand Up @@ -355,8 +366,12 @@ async function updateWorkflowAndValidate(
updatedWorkflow,
updateRequest
);
const expectedUpdateRequest = {
...updateRequest,
steps: updateRequest.steps.map(updateStepId),
};
expect(updatedWorkflowWithResponseFieldsRemoved, 'workflow after update does not match as expected').to.deep.equal(
updateRequest
expectedUpdateRequest
);
expect(convertToDate(updatedWorkflow.updatedAt)).to.be.greaterThan(convertToDate(updatedAt));
}
Expand Down Expand Up @@ -587,6 +602,7 @@ function buildUpdateDtoWithValues(workflowCreated: WorkflowResponseDto): UpdateW
steps: [updatedStep, newStep],
};
}

function createStep(): StepCreateDto {
return {
name: 'someStep',
Expand Down
4 changes: 0 additions & 4 deletions packages/shared/src/dto/workflows/workflow-commons-fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ export class StepDto {
@IsDefined()
name: string;

@IsString()
@IsOptional()
stepId?: string;

@IsString()
@IsDefined()
type: StepTypeEnum;
Expand Down

0 comments on commit e44ea5c

Please sign in to comment.