Skip to content

Commit

Permalink
bug(api): added new test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
tatarco committed Nov 13, 2024
1 parent a2e11e3 commit e9dcb02
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions apps/api/src/app/workflows-v2/generate-preview.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,42 @@ describe('Generate Preview', () => {
});
});
});
describe('payload sanitation', () => {
it('Should produce a correct payload when pipe is used etc {{payload.variable | upper}}', async () => {
const { stepDatabaseId, workflowId } = await createWorkflowAndReturnId(StepTypeEnum.SMS);
const requestDto = {
controlValues: {
body: 'some text that illegal placeholder[{{payload.variableName | upper}}this text should be alone in brackets]',
},
};
const previewResponseDto = await generatePreview(workflowId, stepDatabaseId, requestDto, 'email');
expect(
previewResponseDto.previewPayloadExample?.payload?.varaiableName,
JSON.stringify(previewResponseDto.previewPayloadExample, null, 2)
).to.exist;

expect(previewResponseDto.issues).to.be.empty;
});
});

describe('Error Handling', () => {
it('Should not fail on illegal placeholder {{}} ', async () => {
const { stepDatabaseId, workflowId } = await createWorkflowAndReturnId(StepTypeEnum.SMS);
const requestDto = {
controlValues: { body: 'some text that illegal placeholder[{{}}this text should be alone in brackets]' },
};
const previewResponseDto = await generatePreview(workflowId, stepDatabaseId, requestDto, 'email');
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('{{}}');
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

0 comments on commit e9dcb02

Please sign in to comment.