22import dbHandler from '__tests__/unit/backend/helpers/jest-db'
33import { ObjectId } from 'bson'
44import mongoose from 'mongoose'
5+ import { ok , okAsync } from 'neverthrow'
6+ import {
7+ BasicField ,
8+ FormAuthType ,
9+ FormResponseMode ,
10+ MyInfoAttribute ,
11+ PaymentChannel ,
12+ } from 'shared/types'
513
614import { getEncryptSubmissionModel } from 'src/app/models/submission.server.model'
7- import { FormFieldSchema , IAttachmentInfo , IEncryptedSubmissionSchema , IPopulatedEncryptedForm , SgidFieldTitle } from 'src/types'
8-
9- import { ok , okAsync } from 'neverthrow'
1015import * as FormService from 'src/app/modules/form/form.service'
1116import MailService from 'src/app/services/mail/mail.service'
12- import { createEncryptSubmissionWithoutSave , performEncryptPostSubmissionActions } from '../encrypt-submission.service'
13- import { BasicField , FieldResponse , FormAuthType , FormResponseMode , MyInfoAttribute , PaymentChannel } from 'shared/types'
1417import * as MailUtils from 'src/app/services/mail/mail.utils'
18+ import {
19+ FormFieldSchema ,
20+ IAttachmentInfo ,
21+ IEncryptedSubmissionSchema ,
22+ IPopulatedEncryptedForm ,
23+ SgidFieldTitle ,
24+ } from 'src/types'
25+
1526import { ProcessedFieldResponse } from '../../submission.types'
27+ import {
28+ createEncryptSubmissionWithoutSave ,
29+ performEncryptPostSubmissionActions ,
30+ } from '../encrypt-submission.service'
1631
1732const EncryptSubmission = getEncryptSubmissionModel ( mongoose )
1833
@@ -68,7 +83,6 @@ describe('encrypt-submission.service', () => {
6883 } )
6984
7085 describe ( 'performEncryptPostSubmissionActions' , ( ) => {
71-
7286 const MOCK_NON_PAYMENT_ENCRYPT_FORM = {
7387 _id : new ObjectId ( ) ,
7488 title : 'Test Form' ,
@@ -86,36 +100,40 @@ describe('encrypt-submission.service', () => {
86100 } as IPopulatedEncryptedForm
87101
88102 describe ( 'pdfAttachment generation' , ( ) => {
89- it ( 'should generate pdf attachment if required and sendSubmissionToAdmin with pdf attachment' , async ( ) => { } )
103+ it ( 'should generate pdf attachment if required and sendSubmissionToAdmin with pdf attachment' , async ( ) => { } )
90104
91- it ( 'should not generate pdf attachment if not required and sendSubmissionToAdmin without pdf attachment' , async ( ) => { } )
105+ it ( 'should not generate pdf attachment if not required and sendSubmissionToAdmin without pdf attachment' , async ( ) => { } )
92106 } )
93107
94108 describe ( 'sendEmailConfirmations' , ( ) => {
95109 describe ( 'pdfAttachment' , ( ) => {
96- it ( 'should pass pdf attachment to sendEmailConfirmations if required' , async ( ) => { } )
110+ it ( 'should pass pdf attachment to sendEmailConfirmations if required' , async ( ) => { } )
97111
98- it ( 'should not pass pdf attachment to sendEmailConfirmations if not required, even if it exists' , async ( ) => { } )
112+ it ( 'should not pass pdf attachment to sendEmailConfirmations if not required, even if it exists' , async ( ) => { } )
99113 } )
100114 } )
101115
102116 describe ( 'sendSubmissionToAdmin' , ( ) => {
103117 beforeEach ( ( ) => {
104118 jest . clearAllMocks ( )
105119 MockMailService . sendSubmissionToAdmin . mockReturnValue ( okAsync ( true ) )
106- MockFormService . retrieveFullFormById . mockReturnValue ( okAsync ( MOCK_NON_PAYMENT_ENCRYPT_FORM ) )
107- MockMailUtils . generateAutoreplyPdf . mockReturnValue ( okAsync ( Buffer . from ( 'mock pdf buffer' ) ) )
120+ MockFormService . retrieveFullFormById . mockReturnValue (
121+ okAsync ( MOCK_NON_PAYMENT_ENCRYPT_FORM ) ,
122+ )
123+ MockMailUtils . generateAutoreplyPdf . mockReturnValue (
124+ okAsync ( Buffer . from ( 'mock pdf buffer' ) ) ,
125+ )
108126 } )
109127
110128 describe ( 'pdfAttachment' , ( ) => {
111- it ( 'should pass pdf attachment to sendSubmissionToAdmin if required' , async ( ) => { } )
129+ it ( 'should pass pdf attachment to sendSubmissionToAdmin if required' , async ( ) => { } )
112130
113- it ( 'should not pass pdf attachment to sendSubmissionToAdmin if not required, even if it exists' , async ( ) => { } )
131+ it ( 'should not pass pdf attachment to sendSubmissionToAdmin if not required, even if it exists' , async ( ) => { } )
114132 } )
115133
116134 describe ( 'emailFields' , ( ) => {
117135 it ( 'should include nric field in notification email if provided' , async ( ) => {
118- // Arrange
136+ // Arrange
119137 const MOCK_NRIC = 'S1234567A'
120138 const mockSubmission = {
121139 _id : new ObjectId ( ) ,
@@ -133,29 +151,36 @@ describe('encrypt-submission.service', () => {
133151 ]
134152
135153 // Act
136- const postSubmissionActionStatus = await performEncryptPostSubmissionActions ( {
137- submission : mockSubmission ,
138- responses : mockResponses ,
139- emailFields : mockResponses ,
140- submissionAttachments : [ ] ,
141- respondentEmails : [ ] ,
142- } )
154+ const postSubmissionActionStatus =
155+ await performEncryptPostSubmissionActions ( {
156+ submission : mockSubmission ,
157+ responses : mockResponses ,
158+ emailFields : mockResponses ,
159+ submissionAttachments : [ ] ,
160+ respondentEmails : [ ] ,
161+ } )
143162
144163 // Assert
145164 expect ( postSubmissionActionStatus ) . toEqual ( ok ( true ) )
146165
147- expect ( MockMailService . sendSubmissionToAdmin . mock . calls [ 0 ] [ 0 ] . formData ) . toEqual
148- expect . arrayContaining ( [
149- expect . objectContaining ( {
150- answer : MOCK_NRIC ,
151- fieldType : BasicField . Nric ,
152- isVisible : true ,
153- question : SgidFieldTitle . SgidNric ,
154- } ) ,
155- ] )
166+ expect (
167+ MockMailService . sendSubmissionToAdmin . mock . calls [ 0 ] [ 0 ] . formData ,
168+ ) . toEqual (
169+ expect . arrayContaining ( [
170+ expect . objectContaining ( {
171+ answer : MOCK_NRIC ,
172+ fieldType : BasicField . Nric ,
173+ isVisible : true ,
174+ question : SgidFieldTitle . SgidNric ,
175+ } ) ,
176+ ] ) ,
177+ )
156178
157179 // Does not contain any other fields
158- expect ( MockMailService . sendSubmissionToAdmin . mock . calls [ 0 ] [ 0 ] . formData . length ) . toEqual ( 1 )
180+ expect (
181+ MockMailService . sendSubmissionToAdmin . mock . calls [ 0 ] [ 0 ] . formData
182+ . length ,
183+ ) . toEqual ( 1 )
159184 } )
160185 } )
161186
@@ -171,14 +196,14 @@ describe('encrypt-submission.service', () => {
171196 } as IEncryptedSubmissionSchema
172197
173198 // Act
174- const postSubmissionActionStatus = await performEncryptPostSubmissionActions ( {
175- submission : mockSubmission ,
176- responses : [ ] ,
177- emailFields : [ ] ,
178- submissionAttachments : noAttachments ,
179- respondentEmails : [ ] ,
180- } )
181-
199+ const postSubmissionActionStatus =
200+ await performEncryptPostSubmissionActions ( {
201+ submission : mockSubmission ,
202+ responses : [ ] ,
203+ emailFields : [ ] ,
204+ submissionAttachments : noAttachments ,
205+ respondentEmails : [ ] ,
206+ } )
182207
183208 // Assert
184209 expect ( postSubmissionActionStatus ) . toEqual ( ok ( true ) )
@@ -224,10 +249,9 @@ describe('encrypt-submission.service', () => {
224249 } )
225250 } )
226251
227-
228252 describe ( 'dataCollationData' , ( ) => {
229253 it ( 'should pass expected dataCollationData to sendSubmissionToAdmin' , async ( ) => {
230- // Arrange
254+ // Arrange
231255 const mockResponses : ProcessedFieldResponse [ ] = [
232256 {
233257 _id : new ObjectId ( ) . toHexString ( ) ,
0 commit comments