Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(api): Resolve circular import issue for workflow update validation #7151

Merged
merged 9 commits into from
Nov 28, 2024
19 changes: 19 additions & 0 deletions apps/api/src/app/workflows-v2/workflow.controller.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
3 changes: 1 addition & 2 deletions libs/application-generic/src/usecases/workflow/index.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './upsert-validation-constants';
export * from './update-workflow.command';
export * from './update-workflow.usecase';
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,11 @@ 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,
NotificationStep,
} from '../..';
} from './upsert-validation-constants';
import { ContentIssue, IStepControl, NotificationStep } from '../..';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These import statements from index files ('../..' ) are usually the problematic ones for creating circular import dependencies. I think changing the line above to include an absolute path reference will be all that's required here.

That said, having the validation constants in a separate file is much cleaner.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I pushed a fix for this so that we can merge it asap.


export class UpdateWorkflowCommand extends EnvironmentWithUserCommand {
@IsDefined()
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Loading