Skip to content

Commit

Permalink
bug(api): fix test assertion
Browse files Browse the repository at this point in the history
  • Loading branch information
tatarco committed Nov 7, 2024
1 parent 9245910 commit cfa57b2
Showing 1 changed file with 29 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
StepIssuesDto,
WorkflowIssueTypeEnum,
WorkflowResponseDto,
WorkflowStatusEnum,
} from '@novu/shared';
import {
ControlValuesEntity,
Expand Down Expand Up @@ -34,17 +35,41 @@ export class ValidateAndPersistWorkflowIssuesUsecase {
return await this.getWorkflow(command);
}

private async persistWorkflow(command: ValidateWorkflowCommand, workflowWithIssues) {
private async persistWorkflow(command: ValidateWorkflowCommand, workflowWithIssues: NotificationTemplateEntity) {
const isGoodWorkflow = this.isTriggerableWorkflow(workflowWithIssues);

Check warning on line 39 in apps/api/src/app/workflows-v2/usecases/upsert-workflow/validate-and-persist-workflow-issues.usecase.ts

View workflow job for this annotation

GitHub Actions / Spell check

Unknown word (Triggerable)
await this.notificationTemplateRepository.update(
{
_id: command.workflow._id,
_environmentId: command.user.environmentId,
},
{
...workflowWithIssues,
status: this.calculateStatus(isGoodWorkflow, workflowWithIssues),
}
);
}

private calculateStatus(isGoodWorkflow: boolean, workflowWithIssues) {
if (workflowWithIssues.status === WorkflowStatusEnum.INACTIVE) {
return WorkflowStatusEnum.INACTIVE;
}

return isGoodWorkflow ? WorkflowStatusEnum.ERROR : WorkflowStatusEnum.ACTIVE;
}

private isTriggerableWorkflow(workflowWithIssues) {

Check warning on line 60 in apps/api/src/app/workflows-v2/usecases/upsert-workflow/validate-and-persist-workflow-issues.usecase.ts

View workflow job for this annotation

GitHub Actions / Spell check

Unknown word (Triggerable)
const workflowIssues = workflowWithIssues.issues && Object.keys(workflowWithIssues.issues).length;
const hasStepIssues =
workflowWithIssues.steps
.map((step) => step.issues)
.filter((issue) => issue != null)
.filter((issue) => issue.body && Object.keys(issue.body).length > 0)
.filter((issue) => issue.controls && Object.keys(issue.controls).length > 0).length > 0;
const active = !hasStepIssues && !workflowIssues;

return active;
}

private async getWorkflow(command: ValidateWorkflowCommand) {
const entity = await this.notificationTemplateRepository.findById(command.workflow._id, command.user.environmentId);
if (entity == null) {
Expand Down Expand Up @@ -91,7 +116,7 @@ export class ValidateAndPersistWorkflowIssuesUsecase {
): Promise<Record<keyof WorkflowResponseDto, RuntimeIssue[]>> {
// @ts-ignore
const issues: Record<keyof WorkflowResponseDto, RuntimeIssue[]> = {};
await this.addTriggerIdentifierNotUnuiqeIfApplicable(command, issues);
await this.addTriggerIdentifierNotUniqueIfApplicable(command, issues);
this.addNameMissingIfApplicable(command, issues);
this.addDescriptionTooLongIfApplicable(command, issues);

Expand All @@ -118,25 +143,9 @@ export class ValidateAndPersistWorkflowIssuesUsecase {
];
}
}
private async addTriggerIdentifierNotUnuiqeIfApplicable(
private async addTriggerIdentifierNotUniqueIfApplicable(
command: ValidateWorkflowCommand,
issues: Record<
| '_id'
| 'slug'
| 'updatedAt'
| 'createdAt'
| 'steps'
| 'origin'
| 'preferences'
| 'status'
| 'issues'
| 'workflowId'
| 'tags'
| 'active'
| 'name'
| 'description',
RuntimeIssue[]
>
issues: Record<keyof WorkflowResponseDto, RuntimeIssue[]>
) {
const findAllByTriggerIdentifier = await this.notificationTemplateRepository.findAllByTriggerIdentifier(
command.user.environmentId,
Expand Down

0 comments on commit cfa57b2

Please sign in to comment.