Skip to content

Commit

Permalink
feat(api): compilation issues fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
tatarco committed Oct 29, 2024
1 parent cc591c6 commit f8b76bf
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ export * from './push-output-renderer.usecase';
export * from './sms-output-renderer.usecase';
export * from './in-app-output-renderer.usecase';
export * from './email-schema-expander.usecase';
export { HydrateEmailSchemaUseCase } from './hydrate-email-schema-use-case.service';
export { HydrateEmailSchemaUseCase } from './hydrate-email-schema.usecase';
export { HydrateEmailSchemaCommand } from './hydrate-email-schema.command';
157 changes: 92 additions & 65 deletions apps/api/src/app/workflows-v2/generate-preview.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,75 +79,99 @@ describe('Generate Preview', () => {
});
});
describe('email specific features', () => {
it('show -> should hide element based on payload', async () => {
const { stepUuid, workflowId } = await createWorkflowAndReturnId(StepTypeEnum.EMAIL);
const previewResponseDto = await generatePreview(
workflowId,
stepUuid,
{
validationStrategies: [],
controlValues: stepTypeTo[StepTypeEnum.EMAIL],
payloadValues: { params: { isPayedUser: 'false' } },
},
'email'
);
expect(previewResponseDto.result!.preview).to.exist;

const preview = previewResponseDto.result!.preview.body;
expect(preview).to.not.contain('should be the fallback value');
});
});
it('show -> should show element based on payload - string', async () => {
const { stepUuid, workflowId } = await createWorkflowAndReturnId(StepTypeEnum.EMAIL);
const previewResponseDto = await generatePreview(
workflowId,
stepUuid,
{
validationStrategies: [],
controlValues: stepTypeTo[StepTypeEnum.EMAIL],
payloadValues: { params: { isPayedUser: 'true' } },
},
'email'
);
expect(previewResponseDto.result!.preview).to.exist;
describe('show', () => {
it('show -> should hide element based on payload', async () => {
const { stepUuid, workflowId } = await createWorkflowAndReturnId(StepTypeEnum.EMAIL);
const previewResponseDto = await generatePreview(
workflowId,
stepUuid,
{
validationStrategies: [],
controlValues: stepTypeTo[StepTypeEnum.EMAIL],
payloadValues: { params: { isPayedUser: 'false' } },
},
'email'
);
expect(previewResponseDto.result!.preview).to.exist;

const preview = previewResponseDto.result!.preview.body;
expect(preview).to.contain('should be the fallback value');
});
it('show -> should show element based on payload - boolean', async () => {
const { stepUuid, workflowId } = await createWorkflowAndReturnId(StepTypeEnum.EMAIL);
const previewResponseDto = await generatePreview(
workflowId,
stepUuid,
{
validationStrategies: [],
controlValues: stepTypeTo[StepTypeEnum.EMAIL],
payloadValues: { params: { isPayedUser: true } },
},
'email'
);
expect(previewResponseDto.result!.preview).to.exist;
const preview = previewResponseDto.result!.preview.body;
expect(preview).to.not.contain('should be the fallback value');
});
it('show -> should show element based on payload - string', async () => {
const { stepUuid, workflowId } = await createWorkflowAndReturnId(StepTypeEnum.EMAIL);
const previewResponseDto = await generatePreview(
workflowId,
stepUuid,
{
validationStrategies: [],
controlValues: stepTypeTo[StepTypeEnum.EMAIL],
payloadValues: { params: { isPayedUser: 'true' } },
},
'email'
);
expect(previewResponseDto.result!.preview).to.exist;

const preview = previewResponseDto.result!.preview.body;
expect(preview).to.contain('should be the fallback value');
});
const preview = previewResponseDto.result!.preview.body;
expect(preview).to.contain('should be the fallback value');
});
it('show -> should show element based on payload - boolean', async () => {
const { stepUuid, workflowId } = await createWorkflowAndReturnId(StepTypeEnum.EMAIL);
const previewResponseDto = await generatePreview(
workflowId,
stepUuid,
{
validationStrategies: [],
controlValues: stepTypeTo[StepTypeEnum.EMAIL],
payloadValues: { params: { isPayedUser: true } },
},
'email'
);
expect(previewResponseDto.result!.preview).to.exist;

it('show -> should show element if payload is missing', async () => {
const { stepUuid, workflowId } = await createWorkflowAndReturnId(StepTypeEnum.EMAIL);
const previewResponseDto = await generatePreview(
workflowId,
stepUuid,
{
validationStrategies: [],
controlValues: stepTypeTo[StepTypeEnum.EMAIL],
payloadValues: { params: { isPayedUser: 'true' } },
},
'email'
);
expect(previewResponseDto.result!.preview).to.exist;
const preview = previewResponseDto.result!.preview.body;
expect(preview).to.contain('should be the fallback value');
});
it('show -> should show element if payload is missing', async () => {
const { stepUuid, workflowId } = await createWorkflowAndReturnId(StepTypeEnum.EMAIL);
const previewResponseDto = await generatePreview(
workflowId,
stepUuid,
{
validationStrategies: [],
controlValues: stepTypeTo[StepTypeEnum.EMAIL],
payloadValues: { params: { isPayedUser: 'true' } },
},
'email'
);
expect(previewResponseDto.result!.preview).to.exist;

const preview = previewResponseDto.result!.preview.body;
expect(preview).to.contain('should be the fallback value');
const preview = previewResponseDto.result!.preview.body;
expect(preview).to.contain('should be the fallback value');
});
});
describe('for', () => {
it('should populate for if payload exist with actual values', async () => {
const { stepUuid, workflowId } = await createWorkflowAndReturnId(StepTypeEnum.EMAIL);
const body1 = 'ball is round';
const body2 = 'square is square';
const previewResponseDto = await generatePreview(
workflowId,
stepUuid,
{
validationStrategies: [],
controlValues: stepTypeTo[StepTypeEnum.EMAIL],
payloadValues: { items: [{ body: body1 }, { body: body2 }] },
},
'email'
);
expect(previewResponseDto.result!.preview).to.exist;
const preview = previewResponseDto.result!.preview.body;
expect(preview).not.to.contain('{{item.body}}1');
expect(preview).not.to.contain('{{item.body}}1');
expect(preview).to.contain(body1);
expect(preview).to.contain(body2);
});
});
});

describe('Missing Required ControlValues', () => {
Expand Down Expand Up @@ -206,6 +230,7 @@ function buildDtoNoPayload(stepTypeEnum: StepTypeEnum): GeneratePreviewRequestDt
controlValues: stepTypeTo[stepTypeEnum],
};
}

function buildDtoWithPayload(stepTypeEnum: StepTypeEnum): GeneratePreviewRequestDto {
return {
validationStrategies: [],
Expand Down Expand Up @@ -237,6 +262,7 @@ function buildEmailControlValuesPayload(): EmailStepControlSchemaDto {
emailEditor: JSON.stringify(fullCodeSnippet),
};
}

function buildInAppControlValues(): InAppOutput {
return {
subject: `Hello, World! ${PLACEHOLDER_SUBJECT_INAPP}`,
Expand Down Expand Up @@ -284,6 +310,7 @@ function buildChatControlValuesPayload() {
body: 'Hello, World!',
};
}

const FOR_ITEM_VALUE_PLACEHOLDER = '{#item.body#}';
const TEST_SHOW_VALUE = 'TEST_SHOW_VALUE';
const stepTypeTo = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Injectable } from '@nestjs/common';
import { TransformPlaceholderMapUseCase } from './transform-placeholder.usecase';
import { AddKeysToPayloadBasedOnHydrationStrategyCommand } from './add-keys-to-payload-based-on-hydration-strategy-command';
import { HydrateEmailSchemaUseCase } from '../../../environments-v1/usecases/output-renderers/hydrate-email-schema.usecase';
import { HydrateEmailSchemaUseCase } from '../../../environments-v1/usecases/output-renderers';

@Injectable()
export class CreateMockPayloadForSingleControlValueUseCase {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
import { PlaceholderMap } from './collect-placeholders-from-tip-tap-schema.usecase';

export type PlaceholderMap = {
for?: {
[key: string]: string[];
};
show?: {
[key: string]: any[];
};
regular?: {
[key: string]: any[];
};
};
export class TransformPlaceholderMapCommand {
input: PlaceholderMap;
}
Expand Down
4 changes: 4 additions & 0 deletions apps/api/src/app/workflows-v2/workflow.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import { GeneratePreviewUsecase } from './usecases/generate-preview/generate-pre
import { CreateMockPayloadForSingleControlValueUseCase } from './usecases/placeholder-enrichment/payload-preview-value-generator.usecase';
import { ExtractDefaultsUsecase } from './usecases/get-default-values-from-schema/extract-defaults.usecase';
import { TransformPlaceholderMapUseCase } from './usecases/placeholder-enrichment/transform-placeholder.usecase';
import { ConstructPayloadFromPlaceholdersWithDefaultsUseCase } from './usecases/generate-preview/construct-payload-from-placeholders-with-defaults-use-case.service';
import { HydrateEmailSchemaUseCase } from '../environments-v1/usecases/output-renderers';

@Module({
imports: [SharedModule, MessageTemplateModule, ChangeModule, AuthModule, BridgeModule, IntegrationModule],
Expand All @@ -45,6 +47,8 @@ import { TransformPlaceholderMapUseCase } from './usecases/placeholder-enrichmen
CreateMockPayloadForSingleControlValueUseCase,
ExtractDefaultsUsecase,
TransformPlaceholderMapUseCase,
ConstructPayloadFromPlaceholdersWithDefaultsUseCase,
HydrateEmailSchemaUseCase,
],
})
export class WorkflowModule implements NestModule {
Expand Down

0 comments on commit f8b76bf

Please sign in to comment.