Skip to content

Commit

Permalink
bug(api): fix merge on upsert
Browse files Browse the repository at this point in the history
  • Loading branch information
tatarco committed Nov 13, 2024
1 parent e9dcb02 commit 6e06417
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
18 changes: 17 additions & 1 deletion apps/api/src/app/workflows-v2/generate-preview.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ describe('Generate Preview', () => {
const requestDto = {
controlValues: { body: 'some text that illegal placeholder[{{}}this text should be alone in brackets]' },
};
const previewResponseDto = await generatePreview(workflowId, stepDatabaseId, requestDto, 'email');
const previewResponseDto = await generatePreview(workflowId, stepDatabaseId, requestDto, 'sms');
expect(previewResponseDto.result!.preview).to.exist;
if (previewResponseDto.result!.type === 'sms') {
expect(previewResponseDto.result!.preview.body).to.contain('[this text should be alone in brackets]');
Expand All @@ -227,6 +227,22 @@ describe('Generate Preview', () => {
expect(issue[0].variableName).to.equal('{{}}');
expect(issue[0].issueType).to.equal('ILLEGAL_VARIABLE_IN_CONTROL_VALUE');
});
it('Should return a clear error on illegal placeholder {{name}} ', async () => {
const { stepDatabaseId, workflowId } = await createWorkflowAndReturnId(StepTypeEnum.SMS);
const requestDto = {
controlValues: { body: 'some text that illegal placeholder[{{name}}this text should be alone in brackets]' },
};
const previewResponseDto = await generatePreview(workflowId, stepDatabaseId, requestDto, 'sms');
expect(previewResponseDto.result!.preview).to.exist;
if (previewResponseDto.result!.type === 'sms') {
expect(previewResponseDto.result!.preview.body).to.contain('[this text should be alone in brackets]');
}
const issue = previewResponseDto.issues.body;
expect(issue).to.exist;
expect(issue[0].message).to.equal('Illegal placeholder found');
expect(issue[0].variableName).to.equal('{{name}}');
expect(issue[0].issueType).to.equal('ILLEGAL_VARIABLE_IN_CONTROL_VALUE');
});
});
describe('Missing Required ControlValues', () => {
const channelTypes = [{ type: StepTypeEnum.IN_APP, description: 'InApp' }];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { JSONSchemaDto } from '@novu/shared';
import { Injectable } from '@nestjs/common';
import { ExtractDefaultValuesFromSchemaCommand } from './extract-default-values-from-schema-command';

@Injectable()
export class ExtractDefaultValuesFromSchemaUsecase {
/**
* Executes the use case to extract default values from the JSON Schema.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { JSONSchemaDefinition, JSONSchemaDto, JSONSchemaTypeName } from '@novu/shared';
import { Injectable } from '@nestjs/common';
import { ValidatePlaceholderCommand } from './validate-placeholder.command';
import { ValidatedPlaceholderAggregation } from './validated-placeholder-aggregation';
import { PlaceholderAggregation } from '../collect-placeholders';

@Injectable()
export class ValidatePlaceholderUsecase {
execute(command: ValidatePlaceholderCommand): Record<string, ValidatedPlaceholderAggregation> {
const validatedPlaceholders: Record<string, ValidatedPlaceholderAggregation> = {};
Expand Down
6 changes: 6 additions & 0 deletions apps/api/src/app/workflows-v2/workflow.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,15 @@ import {
BuildStepDataUsecase,
BuildWorkflowTestDataUseCase,
CollectPlaceholderWithDefaultsUsecase,
ExtractDefaultValuesFromSchemaUsecase,
GeneratePreviewUsecase,
GetWorkflowUseCase,
ListWorkflowsUseCase,
PrepareAndValidateContentUsecase,
SyncToEnvironmentUseCase,
UpsertWorkflowUseCase,
ValidateAndPersistWorkflowIssuesUsecase,
ValidatePlaceholderUsecase,
} from './usecases';
import { BridgeModule } from '../bridge';
import { HydrateEmailSchemaUseCase } from '../environments-v1/usecases/output-renderers';
Expand Down Expand Up @@ -54,6 +57,9 @@ import { HydrateEmailSchemaUseCase } from '../environments-v1/usecases/output-re
BuildDefaultPayloadUsecase,
BuildAvailableVariableSchemaUsecase,
CollectPlaceholderWithDefaultsUsecase,
PrepareAndValidateContentUsecase,
ValidatePlaceholderUsecase,
ExtractDefaultValuesFromSchemaUsecase,
],
})
export class WorkflowModule implements NestModule {
Expand Down

0 comments on commit 6e06417

Please sign in to comment.