From 98bc719ac30a0714b6fb8f7839b6e06048922435 Mon Sep 17 00:00:00 2001 From: GalTidhar <39020298+tatarco@users.noreply.github.com> Date: Thu, 28 Nov 2024 11:32:17 +0100 Subject: [PATCH] fix(api): Resolve circular import issue for workflow update validation (#7151) Co-authored-by: Richard Fontein <32132657+rifont@users.noreply.github.com> Co-authored-by: George Desipris <73396808+desiprisg@users.noreply.github.com> Co-authored-by: Dima Grossman Co-authored-by: Pawan Jain Co-authored-by: Sokratis Vidros --- .../workflows-v2/workflow.controller.e2e.ts | 19 ++++++++++++++++ .../create-workflow.command.ts | 22 +++++++++---------- .../src/usecases/workflow/index.ts | 3 +-- .../workflow/update-workflow/index.ts | 3 +++ .../update-workflow.command.ts | 9 ++++---- .../upsert-validation-constants.ts | 4 ++++ 6 files changed, 43 insertions(+), 17 deletions(-) create mode 100644 libs/application-generic/src/usecases/workflow/update-workflow/index.ts create mode 100644 libs/application-generic/src/usecases/workflow/update-workflow/upsert-validation-constants.ts diff --git a/apps/api/src/app/workflows-v2/workflow.controller.e2e.ts b/apps/api/src/app/workflows-v2/workflow.controller.e2e.ts index 5ed9e099fcc..83de5476f4d 100644 --- a/apps/api/src/app/workflows-v2/workflow.controller.e2e.ts +++ b/apps/api/src/app/workflows-v2/workflow.controller.e2e.ts @@ -113,6 +113,25 @@ describe('Workflow Controller E2E API Testing', () => { expect(res.isSuccessResult()).to.be.false; expect(res.error?.responseText).to.include('description must be shorter than or equal to 256 characters'); }); + it('should respond with 400 when description is too long on an update call', async () => { + const createWorkflowDto: CreateWorkflowDto = buildCreateWorkflowDto('nameSuffix'); + + const res = await workflowsClient.createWorkflow(createWorkflowDto); + expect(res.isSuccessResult()).to.be.true; + if (res.isSuccessResult()) { + const updateWorkflowDto = { + ...buildUpdateRequest(res.value), + description: Array.from({ length: 260 }).join('X'), + }; + const updateResult = await workflowsClient.updateWorkflow(res.value?._id, updateWorkflowDto); + expect(updateResult.isSuccessResult(), JSON.stringify(updateResult.value)).to.be.false; + if (!updateResult.isSuccessResult()) { + expect(updateResult.error?.responseText).to.include( + 'description must be shorter than or equal to 256 characters' + ); + } + } + }); it('should respond with 400 when a tag is too long', async () => { const createWorkflowDto: CreateWorkflowDto = buildCreateWorkflowDto('nameSuffix', { diff --git a/libs/application-generic/src/usecases/create-workflow/create-workflow.command.ts b/libs/application-generic/src/usecases/create-workflow/create-workflow.command.ts index 4d30515b0bd..8f5eb79f2d8 100644 --- a/libs/application-generic/src/usecases/create-workflow/create-workflow.command.ts +++ b/libs/application-generic/src/usecases/create-workflow/create-workflow.command.ts @@ -17,32 +17,32 @@ import { BuilderFieldType, BuilderGroupValues, ChannelCTATypeEnum, + ContentIssue as ContentIssueDto, FilterParts, IMessageAction, INotificationGroup, IStepVariant, - StepIssuesDto, - StepIssue as StepIssueDto, - ContentIssue as ContentIssueDto, IWorkflowStepMetadata, JSONSchemaDto, NotificationTemplateCustomData, - WorkflowOriginEnum, - WorkflowTypeEnum, - StepIssueEnum, StepContentIssueEnum, StepCreateAndUpdateKeys, + StepIssue as StepIssueDto, + StepIssueEnum, + StepIssuesDto, + WorkflowOriginEnum, WorkflowStatusEnum, + WorkflowTypeEnum, } from '@novu/shared'; import { Type } from 'class-transformer'; import { EnvironmentWithUserCommand } from '../../commands'; import { PreferencesRequired } from '../upsert-preferences'; - -export const MAX_TAG_ELEMENTS = 16; -export const MAX_TAG_LENGTH = 32; -export const MAX_NAME_LENGTH = 64; -export const MAX_DESCRIPTION_LENGTH = 256; +import { + MAX_DESCRIPTION_LENGTH, + MAX_NAME_LENGTH, + MAX_TAG_LENGTH, +} from '../workflow'; export class CreateWorkflowCommand extends EnvironmentWithUserCommand { @IsDefined() diff --git a/libs/application-generic/src/usecases/workflow/index.ts b/libs/application-generic/src/usecases/workflow/index.ts index 3084619f907..5be92e68ce9 100644 --- a/libs/application-generic/src/usecases/workflow/index.ts +++ b/libs/application-generic/src/usecases/workflow/index.ts @@ -1,5 +1,4 @@ -export * from './update-workflow/update-workflow.usecase'; -export * from './update-workflow/update-workflow.command'; +export * from './update-workflow'; export * from './delete-workflow/delete-workflow.usecase'; export * from './delete-workflow/delete-workflow.command'; export * from './get-workflow-by-ids/get-workflow-by-ids.usecase'; diff --git a/libs/application-generic/src/usecases/workflow/update-workflow/index.ts b/libs/application-generic/src/usecases/workflow/update-workflow/index.ts new file mode 100644 index 00000000000..35417311611 --- /dev/null +++ b/libs/application-generic/src/usecases/workflow/update-workflow/index.ts @@ -0,0 +1,3 @@ +export * from './upsert-validation-constants'; +export * from './update-workflow.command'; +export * from './update-workflow.usecase'; diff --git a/libs/application-generic/src/usecases/workflow/update-workflow/update-workflow.command.ts b/libs/application-generic/src/usecases/workflow/update-workflow/update-workflow.command.ts index afff4658e89..0d1ffc3981b 100644 --- a/libs/application-generic/src/usecases/workflow/update-workflow/update-workflow.command.ts +++ b/libs/application-generic/src/usecases/workflow/update-workflow/update-workflow.command.ts @@ -24,14 +24,15 @@ import { Type } from 'class-transformer'; import { EnvironmentWithUserCommand } from '../../../commands'; import { PreferencesRequired } from '../../upsert-preferences'; import { - ContentIssue, - IStepControl, MAX_DESCRIPTION_LENGTH, MAX_NAME_LENGTH, - MAX_TAG_ELEMENTS, MAX_TAG_LENGTH, +} from './upsert-validation-constants'; +import { + ContentIssue, + IStepControl, NotificationStep, -} from '../..'; +} from '../../create-workflow/create-workflow.command'; export class UpdateWorkflowCommand extends EnvironmentWithUserCommand { @IsDefined() diff --git a/libs/application-generic/src/usecases/workflow/update-workflow/upsert-validation-constants.ts b/libs/application-generic/src/usecases/workflow/update-workflow/upsert-validation-constants.ts new file mode 100644 index 00000000000..73d6bedf5f3 --- /dev/null +++ b/libs/application-generic/src/usecases/workflow/update-workflow/upsert-validation-constants.ts @@ -0,0 +1,4 @@ +export const MAX_TAG_ELEMENTS = 16; +export const MAX_TAG_LENGTH = 32; +export const MAX_NAME_LENGTH = 64; +export const MAX_DESCRIPTION_LENGTH = 256;