Skip to content

Commit

Permalink
feat: add tc for appending mrf meta to mrf submission stream
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin9foong committed Dec 13, 2024
1 parent 90eb8e5 commit 2384693
Showing 1 changed file with 89 additions and 1 deletion.
90 changes: 89 additions & 1 deletion src/app/modules/submission/__tests__/submission.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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)
Expand Down Expand Up @@ -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: ['[email protected]'],
edit: [],
}
const WORKFLOW_STEP_2: FormWorkflowStepDto = {
_id: 'step_2_id',
workflow_type: WorkflowType.Static,
emails: ['[email protected]'],
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'

Expand Down

0 comments on commit 2384693

Please sign in to comment.