Skip to content

Commit

Permalink
bug(api): added status persistence and testing for it
Browse files Browse the repository at this point in the history
  • Loading branch information
tatarco committed Nov 7, 2024
1 parent fea19a7 commit 0e84187
Show file tree
Hide file tree
Showing 7 changed files with 509 additions and 485 deletions.
24 changes: 12 additions & 12 deletions apps/api/src/app/workflows-v2/generate-preview.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ describe('Generate Preview', () => {
.exist;

if (type !== StepTypeEnum.EMAIL) {
expect(previewResponseDto.result!.preview).to.deep.equal(getControlValues(stepId)[type]);
expect(previewResponseDto.result!.preview).to.deep.equal(getTestControlValues(stepId)[type]);
} else {
assertEmail(previewResponseDto);
}
Expand All @@ -99,7 +99,7 @@ describe('Generate Preview', () => {
workflowId,
stepDatabaseId,
{
controlValues: getControlValues(stepId)[StepTypeEnum.EMAIL],
controlValues: getTestControlValues(stepId)[StepTypeEnum.EMAIL],
previewPayload: { payload: { params: { isPayedUser: 'false' } } },
},
'email'
Expand All @@ -115,7 +115,7 @@ describe('Generate Preview', () => {
workflowId,
stepDatabaseId,
{
controlValues: getControlValues(stepId)[StepTypeEnum.EMAIL],
controlValues: getTestControlValues(stepId)[StepTypeEnum.EMAIL],
previewPayload: { payload: { params: { isPayedUser: 'true' } } },
},
'email'
Expand All @@ -131,7 +131,7 @@ describe('Generate Preview', () => {
workflowId,
stepDatabaseId,
{
controlValues: getControlValues(stepId)[StepTypeEnum.EMAIL],
controlValues: getTestControlValues(stepId)[StepTypeEnum.EMAIL],
previewPayload: { payload: { params: { isPayedUser: true } } },
},
'email'
Expand All @@ -147,7 +147,7 @@ describe('Generate Preview', () => {
workflowId,
stepDatabaseId,
{
controlValues: getControlValues(stepId)[StepTypeEnum.EMAIL],
controlValues: getTestControlValues(stepId)[StepTypeEnum.EMAIL],
previewPayload: { payload: { params: { isPayedUser: 'true' } } },
},
'email'
Expand Down Expand Up @@ -269,19 +269,19 @@ describe('Generate Preview', () => {

function buildDtoNoPayload(stepTypeEnum: StepTypeEnum, stepId: string): GeneratePreviewRequestDto {
return {
controlValues: getControlValues(stepId)[stepTypeEnum],
controlValues: getTestControlValues(stepId)[stepTypeEnum],
};
}

function buildDtoWithPayload(stepTypeEnum: StepTypeEnum, stepId: string): GeneratePreviewRequestDto {
return {
controlValues: getControlValues(stepId)[stepTypeEnum],
controlValues: getTestControlValues(stepId)[stepTypeEnum],
previewPayload: { payload: { subject: PLACEHOLDER_SUBJECT_INAPP_PAYLOAD_VALUE } },
};
}

function buildDtoWithMissingControlValues(stepTypeEnum: StepTypeEnum, stepId: string): GeneratePreviewRequestDto {
const stepTypeToElement = getControlValues(stepId)[stepTypeEnum];
const stepTypeToElement = getTestControlValues(stepId)[stepTypeEnum];
if (stepTypeEnum === StepTypeEnum.EMAIL) {
delete stepTypeToElement.subject;
} else {
Expand All @@ -294,7 +294,7 @@ function buildDtoWithMissingControlValues(stepTypeEnum: StepTypeEnum, stepId: st
};
}

function buildEmailControlValuesPayload(stepId: string): EmailStepControlSchemaDto {
function buildEmailControlValuesPayload(stepId?: string): EmailStepControlSchemaDto {
return {
subject: `Hello, World! ${SUBJECT_TEST_PAYLOAD}`,
emailEditor: JSON.stringify(fullCodeSnippet(stepId)),
Expand All @@ -306,10 +306,10 @@ function buildSimpleForEmail(): EmailStepControlSchemaDto {
emailEditor: JSON.stringify(forSnippet),
};
}
function buildInAppControlValues(stepId: string) {
function buildInAppControlValues(stepId?: string) {
return {
subject: `{{subscriber.firstName}} Hello, World! ${PLACEHOLDER_SUBJECT_INAPP}`,
body: 'Hello, World! {{payload.placeholder.body}}',
body: `${stepId ? `steps.${stepId}.origins` : '{{payload.origins}}'} Hello, World! {{payload.placeholder.body}}`,
avatar: 'https://www.example.com/avatar.png',
primaryAction: {
label: '{{payload.secondaryUrl}}',
Expand Down Expand Up @@ -354,7 +354,7 @@ function buildChatControlValuesPayload() {
};
}

const getControlValues = (stepId: string) => ({
export const getTestControlValues = (stepId?: string) => ({
[StepTypeEnum.SMS]: buildSmsControlValuesPayload(),
[StepTypeEnum.EMAIL]: buildEmailControlValuesPayload(stepId) as unknown as Record<string, unknown>,
[StepTypeEnum.PUSH]: buildPushControlValuesPayload(),
Expand Down
Loading

0 comments on commit 0e84187

Please sign in to comment.