-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add tc for testing the metadata builder
- Loading branch information
1 parent
75ac070
commit 448f2d0
Showing
1 changed file
with
148 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ import { | |
ChildBirthRecordsResponseV3, | ||
EmailResponseV3, | ||
FieldResponsesV3, | ||
FormFieldDto, | ||
FormWorkflowStepDto, | ||
LongTextResponseV3, | ||
NumberResponseV3, | ||
|
@@ -34,6 +35,7 @@ import { | |
|
||
import * as fieldValidation from '../../../../utils/field-validation' | ||
import { ValidateFieldErrorV3 } from '../../submission.errors' | ||
import { buildMrfMetadata } from '../../submission.utils' | ||
import { | ||
createMultirespondentSubmissionDto, | ||
getQuestionTitleAnswerString, | ||
|
@@ -42,13 +44,155 @@ import { | |
} from '../multirespondent-submission.utils' | ||
|
||
describe('multirespondent-submission.utils', () => { | ||
const WORKFLOW_STEP_1 = { | ||
const YES_NO_FIELD = { | ||
_id: 'yes_no_field_id', | ||
title: 'Yes or No', | ||
description: '', | ||
required: true, | ||
disabled: false, | ||
fieldType: BasicField.YesNo, | ||
} | ||
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: [YES_NO_FIELD._id], | ||
} | ||
const WORKFLOW_APPROVAL_STEP: FormWorkflowStepDto = { | ||
_id: 'approval_step_id', | ||
workflow_type: WorkflowType.Static, | ||
emails: ['[email protected]'], | ||
edit: [YES_NO_FIELD._id], | ||
approval_field: YES_NO_FIELD._id, | ||
} | ||
|
||
describe('buildMrfMetadata', () => { | ||
it('should build mrf metadata successfully for pending submission without approval step', () => { | ||
const metadata = buildMrfMetadata({ | ||
workflow: [WORKFLOW_STEP_1, WORKFLOW_STEP_2], | ||
workflowStep: 0, | ||
submittedSteps: [ | ||
{ | ||
isApproval: false, | ||
submittedAt: '2024-01-01T00:00:00.000Z', | ||
}, | ||
], | ||
}) | ||
|
||
expect(metadata).toEqual({ | ||
workflowCurrentStepNumber: 1, | ||
workflowNumTotalSteps: 2, | ||
workflowStatus: WorkflowStatus.PENDING, | ||
}) | ||
}) | ||
|
||
it('should build mrf metadata successfully for completed submission without approval step', () => { | ||
const metadata = buildMrfMetadata({ | ||
workflow: [WORKFLOW_STEP_1, WORKFLOW_STEP_2], | ||
workflowStep: 1, | ||
submittedSteps: [ | ||
{ | ||
isApproval: false, | ||
submittedAt: '2024-01-01T00:00:00.000Z', | ||
}, | ||
{ | ||
isApproval: false, | ||
submittedAt: '2024-01-02T00:00:00.000Z', | ||
}, | ||
], | ||
}) | ||
|
||
expect(metadata).toEqual({ | ||
workflowCurrentStepNumber: 2, | ||
workflowNumTotalSteps: 2, | ||
workflowStatus: WorkflowStatus.COMPLETED, | ||
}) | ||
}) | ||
|
||
it('should build mrf metadata successfully for pending submission with approval step', () => { | ||
const metadata = buildMrfMetadata({ | ||
workflow: [WORKFLOW_STEP_1, WORKFLOW_APPROVAL_STEP, WORKFLOW_STEP_2], | ||
workflowStep: 1, | ||
submittedSteps: [ | ||
{ | ||
isApproval: false, | ||
submittedAt: '2024-01-01T00:00:00.000Z', | ||
}, | ||
{ | ||
isApproval: true, | ||
status: WorkflowStatus.APPROVED, | ||
submittedAt: '2024-01-02T00:00:00.000Z', | ||
}, | ||
], | ||
}) | ||
|
||
expect(metadata).toEqual({ | ||
workflowCurrentStepNumber: 2, | ||
workflowNumTotalSteps: 3, | ||
workflowStatus: WorkflowStatus.PENDING, | ||
}) | ||
}) | ||
|
||
it('should build mrf metadata successfully for approval submission with approval step', () => { | ||
const metadata = buildMrfMetadata({ | ||
workflow: [WORKFLOW_STEP_1, WORKFLOW_APPROVAL_STEP, WORKFLOW_STEP_2], | ||
workflowStep: 2, | ||
submittedSteps: [ | ||
{ | ||
isApproval: false, | ||
submittedAt: '2024-01-01T00:00:00.000Z', | ||
}, | ||
{ | ||
isApproval: true, | ||
status: WorkflowStatus.APPROVED, | ||
submittedAt: '2024-01-02T00:00:00.000Z', | ||
}, | ||
{ | ||
isApproval: false, | ||
submittedAt: '2024-01-03T00:00:00.000Z', | ||
}, | ||
], | ||
}) | ||
|
||
expect(metadata).toEqual({ | ||
workflowCurrentStepNumber: 3, | ||
workflowNumTotalSteps: 3, | ||
workflowStatus: WorkflowStatus.APPROVED, | ||
}) | ||
}) | ||
|
||
it('should build mrf metadata successfully for rejected submission with approval step', () => { | ||
const metadata = buildMrfMetadata({ | ||
workflow: [WORKFLOW_STEP_1, WORKFLOW_APPROVAL_STEP, WORKFLOW_STEP_2], | ||
workflowStep: 1, | ||
submittedSteps: [ | ||
{ | ||
isApproval: false, | ||
submittedAt: '2024-01-01T00:00:00.000Z', | ||
}, | ||
{ | ||
isApproval: true, | ||
status: WorkflowStatus.REJECTED, | ||
submittedAt: '2024-01-02T00:00:00.000Z', | ||
}, | ||
], | ||
}) | ||
|
||
expect(metadata).toEqual({ | ||
workflowCurrentStepNumber: 2, | ||
workflowNumTotalSteps: 3, | ||
workflowStatus: WorkflowStatus.REJECTED, | ||
}) | ||
}) | ||
}) | ||
|
||
describe('createMultirespondentSubmissionDto', () => { | ||
it('should create an encrypted submission DTO sucessfully', () => { | ||
// Arrange | ||
|
@@ -140,7 +284,7 @@ describe('multirespondent-submission.utils', () => { | |
const result = validateMrfFieldResponses({ | ||
formId: mockFormId, | ||
visibleFieldIds: mockVisibleFieldIds, | ||
formFields: mockFormFields, | ||
formFields: mockFormFields as FormFieldDto[], | ||
responses: mockResponses, | ||
}) | ||
|
||
|
@@ -174,7 +318,7 @@ describe('multirespondent-submission.utils', () => { | |
validateMrfFieldResponses({ | ||
formId: mockFormId, | ||
visibleFieldIds: mockVisibleFieldIds, | ||
formFields: mockFormFields, | ||
formFields: mockFormFields as FormFieldDto[], | ||
responses: mockResponses, | ||
}) | ||
|
||
|
@@ -217,7 +361,7 @@ describe('multirespondent-submission.utils', () => { | |
validateMrfFieldResponses({ | ||
formId: mockFormId, | ||
visibleFieldIds: mockVisibleFieldIds, | ||
formFields: mockFormFields, | ||
formFields: mockFormFields as FormFieldDto[], | ||
responses: mockResponses, | ||
}) | ||
|
||
|