-
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.
- Loading branch information
1 parent
342a9e8
commit db66d56
Showing
4 changed files
with
146 additions
and
17 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
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 |
---|---|---|
|
@@ -3,7 +3,13 @@ import { ObjectId } from 'bson' | |
import { pick, times } from 'lodash' | ||
import moment from 'moment-timezone' | ||
import mongoose from 'mongoose' | ||
import { SubmissionMetadata, SubmissionType } from 'shared/types' | ||
import { | ||
BasicField, | ||
SubmissionMetadata, | ||
SubmissionType, | ||
WorkflowStatus, | ||
WorkflowType, | ||
} from 'shared/types' | ||
|
||
import getSubmissionModel, { | ||
getEmailSubmissionModel, | ||
|
@@ -24,6 +30,34 @@ describe('Multirespondent Submission Model', () => { | |
const MOCK_ENCRYPTED_SUBMISSION_SECRET_KEY = 'This is an encrypted secret key' | ||
const MOCK_ENCRYPTED_CONTENT = 'abcdefg encryptedContent' | ||
|
||
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 = { | ||
_id: 'step_1_id', | ||
workflow_type: WorkflowType.Static, | ||
emails: ['[email protected]'], | ||
edit: [], | ||
} | ||
const WORKFLOW_STEP_2 = { | ||
_id: 'step_2_id', | ||
workflow_type: WorkflowType.Static, | ||
emails: ['[email protected]'], | ||
edit: [YES_NO_FIELD._id], | ||
} | ||
const WORKFLOW_APPROVAL_STEP = { | ||
_id: 'approval_step_id', | ||
workflow_type: WorkflowType.Static, | ||
emails: ['[email protected]'], | ||
edit: [YES_NO_FIELD._id], | ||
approval_field: YES_NO_FIELD._id, | ||
} | ||
|
||
describe('Statics', () => { | ||
describe('findSingleMetadata', () => { | ||
it('should return submission metadata', async () => { | ||
|
@@ -34,15 +68,26 @@ describe('Multirespondent Submission Model', () => { | |
const validSubmission = await MultirespondentSubmission.create({ | ||
form: validFormId, | ||
submissionType: SubmissionType.Multirespondent, | ||
form_fields: [], | ||
form_fields: [YES_NO_FIELD, WORKFLOW_APPROVAL_STEP], | ||
form_logics: [], | ||
workflow: [], | ||
workflow: [WORKFLOW_STEP_1, WORKFLOW_APPROVAL_STEP], | ||
submissionPublicKey: MOCK_SUBMISSION_PUBLIC_KEY, | ||
encryptedSubmissionSecretKey: MOCK_ENCRYPTED_SUBMISSION_SECRET_KEY, | ||
encryptedContent: MOCK_ENCRYPTED_CONTENT, | ||
version: 3, | ||
created: createdDate, | ||
workflowStep: 0, | ||
workflowStep: 1, | ||
submittedSteps: [ | ||
{ | ||
isApproval: false, | ||
submittedAt: '2024-01-01T00:00:00.000Z', | ||
}, | ||
{ | ||
isApproval: true, | ||
status: WorkflowStatus.REJECTED, | ||
submittedAt: '2024-01-01T00:00:00.000Z', | ||
}, | ||
], | ||
}) | ||
|
||
// Act | ||
|
@@ -59,6 +104,11 @@ describe('Multirespondent Submission Model', () => { | |
submissionTime: moment(createdDate) | ||
.tz('Asia/Singapore') | ||
.format('Do MMM YYYY, h:mm:ss a'), | ||
mrf: { | ||
workflowCurrentStepNumber: 2, | ||
workflowNumTotalSteps: 2, | ||
workflowStatus: WorkflowStatus.REJECTED, | ||
}, | ||
} | ||
expect(result).toEqual(expected) | ||
}) | ||
|
@@ -118,13 +168,19 @@ describe('Multirespondent Submission Model', () => { | |
submissionType: SubmissionType.Multirespondent, | ||
form_fields: [], | ||
form_logics: [], | ||
workflow: [], | ||
workflow: [WORKFLOW_STEP_1], | ||
submissionPublicKey: MOCK_SUBMISSION_PUBLIC_KEY, | ||
encryptedSubmissionSecretKey: MOCK_ENCRYPTED_SUBMISSION_SECRET_KEY, | ||
encryptedContent: MOCK_ENCRYPTED_CONTENT, | ||
version: 3, | ||
created: MOCK_CREATED_DATES_ASC[idx], | ||
workflowStep: 0, | ||
submittedSteps: [ | ||
{ | ||
isApproval: false, | ||
submittedAt: '2024-01-01T00:00:00.000Z', | ||
}, | ||
], | ||
}), | ||
) | ||
const validSubmissions: IMultirespondentSubmissionSchema[] = | ||
|
@@ -146,6 +202,11 @@ describe('Multirespondent Submission Model', () => { | |
submissionTime: moment(data.created) | ||
.tz('Asia/Singapore') | ||
.format('Do MMM YYYY, h:mm:ss a'), | ||
mrf: { | ||
workflowCurrentStepNumber: 1, | ||
workflowNumTotalSteps: 1, | ||
workflowStatus: WorkflowStatus.COMPLETED, | ||
}, | ||
})) | ||
.reverse(), | ||
} | ||
|
@@ -161,13 +222,24 @@ describe('Multirespondent Submission Model', () => { | |
submissionType: SubmissionType.Multirespondent, | ||
form_fields: [], | ||
form_logics: [], | ||
workflow: [], | ||
workflow: [WORKFLOW_STEP_1, WORKFLOW_APPROVAL_STEP], | ||
submissionPublicKey: MOCK_SUBMISSION_PUBLIC_KEY, | ||
encryptedSubmissionSecretKey: MOCK_ENCRYPTED_SUBMISSION_SECRET_KEY, | ||
encryptedContent: MOCK_ENCRYPTED_CONTENT, | ||
version: 3, | ||
created: MOCK_CREATED_DATES_ASC[idx], | ||
workflowStep: 0, | ||
workflowStep: 1, | ||
submittedSteps: [ | ||
{ | ||
isApproval: false, | ||
submittedAt: '2024-01-01T00:00:00.000Z', | ||
}, | ||
{ | ||
isApproval: true, | ||
status: WorkflowStatus.APPROVED, | ||
submittedAt: '2024-01-01T00:00:00.000Z', | ||
}, | ||
], | ||
}), | ||
) | ||
const validSubmissions: IMultirespondentSubmissionSchema[] = | ||
|
@@ -194,6 +266,11 @@ describe('Multirespondent Submission Model', () => { | |
submissionTime: moment(secondSubmission.created) | ||
.tz('Asia/Singapore') | ||
.format('Do MMM YYYY, h:mm:ss a'), | ||
mrf: { | ||
workflowCurrentStepNumber: 2, | ||
workflowNumTotalSteps: 2, | ||
workflowStatus: WorkflowStatus.APPROVED, | ||
}, | ||
}, | ||
], | ||
} | ||
|
@@ -209,13 +286,23 @@ describe('Multirespondent Submission Model', () => { | |
submissionType: SubmissionType.Multirespondent, | ||
form_fields: [], | ||
form_logics: [], | ||
workflow: [], | ||
workflow: [WORKFLOW_STEP_1, WORKFLOW_STEP_2], | ||
submissionPublicKey: MOCK_SUBMISSION_PUBLIC_KEY, | ||
encryptedSubmissionSecretKey: MOCK_ENCRYPTED_SUBMISSION_SECRET_KEY, | ||
encryptedContent: MOCK_ENCRYPTED_CONTENT, | ||
version: 3, | ||
created: MOCK_CREATED_DATES_ASC[idx], | ||
workflowStep: 0, | ||
workflowStep: 1, | ||
submittedSteps: [ | ||
{ | ||
isApproval: false, | ||
submittedAt: '2024-01-01T00:00:00.000Z', | ||
}, | ||
{ | ||
isApproval: false, | ||
submittedAt: '2024-01-02T00:00:00.000Z', | ||
}, | ||
], | ||
}), | ||
) | ||
const validSubmissions: IMultirespondentSubmissionSchema[] = | ||
|
@@ -242,6 +329,11 @@ describe('Multirespondent Submission Model', () => { | |
submissionTime: moment(latestSubmission.created) | ||
.tz('Asia/Singapore') | ||
.format('Do MMM YYYY, h:mm:ss a'), | ||
mrf: { | ||
workflowCurrentStepNumber: 2, | ||
workflowNumTotalSteps: 2, | ||
workflowStatus: WorkflowStatus.COMPLETED, | ||
}, | ||
}, | ||
], | ||
} | ||
|
@@ -332,6 +424,8 @@ describe('Multirespondent Submission Model', () => { | |
'encryptedContent', | ||
'submissionType', | ||
'version', | ||
'submittedSteps', | ||
'workflowStep', | ||
) | ||
// Native-ify arrays as mongoose documents contain a mongoose-specific array type. | ||
expectedSubmission.form_fields = JSON.parse( | ||
|
@@ -417,6 +511,7 @@ describe('Multirespondent Submission Model', () => { | |
'submissionType', | ||
'version', | ||
'workflowStep', | ||
'submittedSteps', | ||
) | ||
expect(actual).not.toBeNull() | ||
expect(actual?.toJSON()).toEqual(expected) | ||
|
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
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 |
---|---|---|
|
@@ -16,6 +16,7 @@ import { | |
ShortTextResponseV3, | ||
SubmissionType, | ||
TableResponseV3, | ||
WorkflowStatus, | ||
WorkflowType, | ||
} from 'shared/types' | ||
|
||
|
@@ -41,18 +42,38 @@ import { | |
} from '../multirespondent-submission.utils' | ||
|
||
describe('multirespondent-submission.utils', () => { | ||
const WORKFLOW_STEP_1 = { | ||
_id: 'step_1_id', | ||
workflow_type: WorkflowType.Static, | ||
emails: ['[email protected]'], | ||
edit: [], | ||
} | ||
|
||
describe('createMultirespondentSubmissionDto', () => { | ||
it('should create an encrypted submission DTO sucessfully', () => { | ||
// Arrange | ||
const createdDate = new Date() | ||
const submissionData = { | ||
submissionType: SubmissionType.Multirespondent, | ||
_id: new ObjectId(), | ||
created: createdDate, | ||
submissionPublicKey: 'some public key', | ||
encryptedSubmissionSecretKey: 'some encrypted secret key', | ||
encryptedContent: 'some encrypted content', | ||
submissionType: SubmissionType.Multirespondent, | ||
} as MultirespondentSubmissionData | ||
workflow: [WORKFLOW_STEP_1], | ||
workflowStep: 0, | ||
form_fields: [], | ||
form_logics: [], | ||
attachmentMetadata: {}, | ||
version: 3, | ||
mrfVersion: 3, | ||
submittedSteps: [ | ||
{ | ||
isApproval: false, | ||
submittedAt: '2024-01-01T00:00:00.000Z', | ||
}, | ||
], | ||
} as unknown as MultirespondentSubmissionData | ||
const attachmentPresignedUrls = { | ||
someSubmissionId: 'some presigned url', | ||
} | ||
|
@@ -75,6 +96,17 @@ describe('multirespondent-submission.utils', () => { | |
submissionData.encryptedSubmissionSecretKey, | ||
attachmentMetadata: attachmentPresignedUrls, | ||
submissionType: SubmissionType.Multirespondent, | ||
workflow: submissionData.workflow, | ||
form_fields: submissionData.form_fields, | ||
form_logics: submissionData.form_logics, | ||
version: submissionData.version, | ||
workflowStep: submissionData.workflowStep, | ||
mrfVersion: submissionData.mrfVersion, | ||
mrfMeta: { | ||
workflowCurrentStepNumber: 1, | ||
workflowNumTotalSteps: 1, | ||
workflowStatus: WorkflowStatus.COMPLETED, | ||
}, | ||
}) | ||
}) | ||
}) | ||
|