From 2384693ed39813eb04b83850e2a6620f1349e989 Mon Sep 17 00:00:00 2001 From: Kevin Foong <55353265+kevin9foong@users.noreply.github.com> Date: Fri, 13 Dec 2024 23:08:32 +0800 Subject: [PATCH] feat: add tc for appending mrf meta to mrf submission stream --- .../__tests__/submission.service.spec.ts | 90 ++++++++++++++++++- 1 file changed, 89 insertions(+), 1 deletion(-) diff --git a/src/app/modules/submission/__tests__/submission.service.spec.ts b/src/app/modules/submission/__tests__/submission.service.spec.ts index 6436e1a4dc..673754027b 100644 --- a/src/app/modules/submission/__tests__/submission.service.spec.ts +++ b/src/app/modules/submission/__tests__/submission.service.spec.ts @@ -41,9 +41,12 @@ import { AutoReplyOptions, BasicField, FormResponseMode, + FormWorkflowStepDto, SubmissionId, SubmissionMetadata, SubmissionType, + SubmittedNonApprovalStep, + WorkflowType, } from '../../../../../shared/types' import { PaymentNotFoundError } from '../../payments/payments.errors' import * as PaymentsService from '../../payments/payments.service' @@ -66,7 +69,10 @@ import { transformAttachmentMetasToSignedUrls, triggerVirusScanning, } from '../submission.service' -import { extractEmailConfirmationData } from '../submission.utils' +import { + buildMrfMetadata, + extractEmailConfirmationData, +} from '../submission.utils' jest.mock('src/app/services/mail/mail.service') const MockMailService = jest.mocked(MailService) @@ -1637,6 +1643,88 @@ describe('submission.service', () => { }) }) + describe('addMrfMetadata', () => { + it('should return original object without mrf metadata when submission is not multirespondent submission type', () => { + // Arrange + const mockInput = new PassThrough() + const actualTransformedData: any[] = [] + + // Act + // Build pipeline for testing + mockInput.pipe(SubmissionService.addMrfMetadata()).on('data', (data) => { + actualTransformedData.push(data) + }) + + // Emit events + const mockData = { + submissionType: SubmissionType.Encrypt, + formId: 'mockFormId', + submissionId: 'mockSubmissionId', + } + mockInput.emit('data', mockData) + mockInput.end() + + // Assert + expect(actualTransformedData).toEqual([mockData]) + }) + + it('should add mrf metadata when submission is multirespondent type', () => { + // Arrange + const WORKFLOW_STEP_1: FormWorkflowStepDto = { + _id: 'step_1_id', + workflow_type: WorkflowType.Static, + emails: ['example@example.com'], + edit: [], + } + const WORKFLOW_STEP_2: FormWorkflowStepDto = { + _id: 'step_2_id', + workflow_type: WorkflowType.Static, + emails: ['example@example.com'], + edit: [], + } + + const mockInput = new PassThrough() + const actualTransformedData: any[] = [] + + // Act + // Build pipeline for testing + mockInput.pipe(SubmissionService.addMrfMetadata()).on('data', (data) => { + actualTransformedData.push(data) + }) + + // Emit events + const mockData = { + submissionType: SubmissionType.Multirespondent, + formId: 'mockFormId', + submissionId: 'mockSubmissionId', + workflow: [WORKFLOW_STEP_1, WORKFLOW_STEP_2], + workflowStep: 0, + submittedSteps: [ + { + isApproval: false, + submittedAt: '2024-01-01T00:00:00.000Z', + } as SubmittedNonApprovalStep, + ], + } + mockInput.emit('data', mockData) + mockInput.end() + + // Assert + expect(actualTransformedData).toEqual([ + { + submissionType: SubmissionType.Multirespondent, + formId: 'mockFormId', + submissionId: 'mockSubmissionId', + mrfMeta: buildMrfMetadata({ + workflow: mockData.workflow, + workflowStep: mockData.workflowStep, + submittedSteps: mockData.submittedSteps, + }), + }, + ]) + }) + }) + describe('getSubmissionPaymentDto', () => { const MOCK_PAYMENT_ID = 'mockPaymentId'