Skip to content

Commit 3ecbbe9

Browse files
committed
fix: lint and fix tc
1 parent e211a79 commit 3ecbbe9

File tree

7 files changed

+245
-184
lines changed

7 files changed

+245
-184
lines changed

src/app/modules/submission/__tests__/submission.service.spec.ts

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,9 @@ describe('submission.service', () => {
467467
expect(MockMailService.sendAutoReplyEmails).toHaveBeenCalledWith({
468468
form: mockForm,
469469
submission: MOCK_SUBMISSION,
470-
attachments: MOCK_ATTACHMENTS,
470+
submissionAttachments: MOCK_ATTACHMENTS,
471+
pdfAttachment: undefined,
472+
isPaymentEnabled: false,
471473
responsesData: MOCK_AUTOREPLY_DATA,
472474
autoReplyMailDatas: expectedAutoReplyData,
473475
})
@@ -607,7 +609,9 @@ describe('submission.service', () => {
607609
expect(MockMailService.sendAutoReplyEmails).toHaveBeenCalledWith({
608610
form: mockForm,
609611
submission: MOCK_SUBMISSION,
610-
attachments: MOCK_ATTACHMENTS,
612+
submissionAttachments: MOCK_ATTACHMENTS,
613+
pdfAttachment: undefined,
614+
isPaymentEnabled: false,
611615
responsesData: MOCK_AUTOREPLY_DATA,
612616
autoReplyMailDatas: expectedAutoReplyData,
613617
})
@@ -675,9 +679,11 @@ describe('submission.service', () => {
675679
expect(MockMailService.sendAutoReplyEmails).toHaveBeenCalledWith({
676680
form: mockForm,
677681
submission: MOCK_SUBMISSION,
678-
attachments: MOCK_ATTACHMENTS,
682+
submissionAttachments: MOCK_ATTACHMENTS,
679683
responsesData: [],
680684
autoReplyMailDatas: expectedAutoReplyData,
685+
pdfAttachment: undefined,
686+
isPaymentEnabled: false,
681687
})
682688
expect(result._unsafeUnwrap()).toBe(true)
683689
})
@@ -827,13 +833,13 @@ describe('submission.service', () => {
827833
expect(result._unsafeUnwrap()).toBe(true)
828834
})
829835

830-
it('should generate pdfAttachment when form summary for respondent is enabled', async () => {})
836+
it('should generate pdfAttachment when form summary for respondent is enabled', async () => { })
831837

832-
it('should not generate pdfAttachment for payment form', () => {})
838+
it('should not generate pdfAttachment for payment form', () => { })
833839

834-
it('should generate pdfAttachment for admin email notification', () => {})
840+
it('should generate pdfAttachment for admin email notification', () => { })
835841

836-
it('should return pdf generation error when pdf generation fails', () => {})
842+
it('should return pdf generation error when pdf generation fails', () => { })
837843

838844
it('should return SendEmailConfirmationError when mail service errors', async () => {
839845
const mockForm = {
@@ -2886,7 +2892,11 @@ describe('submission.service', () => {
28862892

28872893
// Act
28882894
// empty string for version id to simulate failure
2889-
const actualResult = await downloadCleanFile(MOCK_VALID_UUID, '', 'mock-bucket-name')
2895+
const actualResult = await downloadCleanFile(
2896+
MOCK_VALID_UUID,
2897+
'',
2898+
'mock-bucket-name',
2899+
)
28902900

28912901
// Assert
28922902
expect(awsSpy).toHaveBeenCalledOnce()
@@ -2921,7 +2931,11 @@ describe('submission.service', () => {
29212931

29222932
// Act
29232933
// empty strings for invalid keys and version ids
2924-
const actualResult = await downloadCleanFile(MOCK_VALID_UUID, versionId, 'mock-bucket-name')
2934+
const actualResult = await downloadCleanFile(
2935+
MOCK_VALID_UUID,
2936+
versionId,
2937+
'mock-bucket-name',
2938+
)
29252939

29262940
// Assert
29272941
expect(awsSpy).toHaveBeenCalledOnce()

src/app/modules/submission/encrypt-submission/__tests__/encrypt-submission.controller.spec.ts

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
BasicField,
1313
ErrorCode,
1414
FormAuthType,
15-
MyInfoAttribute
15+
MyInfoAttribute,
1616
} from 'shared/types'
1717

1818
import { getEncryptSubmissionModel } from 'src/app/models/submission.server.model'
@@ -563,7 +563,7 @@ describe('encrypt-submission.controller', () => {
563563
1,
564564
)
565565
expect(saveIfSubmitterIdIsUniqueSpy).toHaveBeenCalledTimes(1)
566-
566+
567567
// Assert that status is not called, which defaults to intended 200 OK
568568
expect(mockRes.status).not.toHaveBeenCalled()
569569
// Assert that response does not any error codes
@@ -1182,12 +1182,16 @@ describe('encrypt-submission.controller', () => {
11821182
// email notification should be sent
11831183
expect(performEncryptPostSubmissionActionsSpy).toHaveBeenCalledTimes(1)
11841184
// Assert nric is not contained - formData empty array since no parsed responses to be included in email
1185-
expect(performEncryptPostSubmissionActionsSpy.mock.calls[0][0].emailFields).not.toContain(expect.objectContaining({
1186-
answer: MOCK_NRIC,
1187-
fieldType: BasicField.Nric,
1188-
isVisible: true,
1189-
question: SgidFieldTitle.SgidNric,
1190-
}))
1185+
expect(
1186+
performEncryptPostSubmissionActionsSpy.mock.calls[0][0].emailFields,
1187+
).not.toContain(
1188+
expect.objectContaining({
1189+
answer: MOCK_NRIC,
1190+
fieldType: BasicField.Nric,
1191+
isVisible: true,
1192+
question: SgidFieldTitle.SgidNric,
1193+
}),
1194+
)
11911195
})
11921196

11931197
it('should include nric in email fields to be included in notification email and store nric in verifiedContent if form isSubmitterIdCollectionEnabled is true for SgId authType', async () => {
@@ -1261,17 +1265,20 @@ describe('encrypt-submission.controller', () => {
12611265

12621266
// email fields for generating email notification include nric
12631267
expect(performEncryptPostSubmissionActionsSpy).toHaveBeenCalledTimes(1)
1264-
expect(performEncryptPostSubmissionActionsSpy.mock.calls[0][0].emailFields[0]).toEqual(expect.objectContaining({
1265-
answer: MOCK_NRIC,
1266-
fieldType: BasicField.Nric,
1267-
isVisible: true,
1268-
question: SgidFieldTitle.SgidNric,
1269-
}))
1268+
expect(
1269+
performEncryptPostSubmissionActionsSpy.mock.calls[0][0].emailFields[0],
1270+
).toEqual(
1271+
expect.objectContaining({
1272+
answer: MOCK_NRIC,
1273+
fieldType: BasicField.Nric,
1274+
isVisible: true,
1275+
question: SgidFieldTitle.SgidNric,
1276+
}),
1277+
)
12701278
})
12711279
})
12721280

12731281
describe('passes the required correct data used to generate content for post-submission notification emails', () => {
1274-
12751282
it('passes the required isVisible values in email fields, submission attachments, and respondent emails', async () => {
12761283
// Arrange
12771284
const performEncryptPostSubmissionActionsSpy = jest.spyOn(
@@ -1312,7 +1319,7 @@ describe('encrypt-submission.controller', () => {
13121319
answer: 'this is a short answer',
13131320
fieldType: 'textfield',
13141321
isVisible: false,
1315-
}
1322+
},
13161323
]
13171324

13181325
const mockUnencryptedAttachments: IAttachmentInfo[] = [
@@ -1325,7 +1332,7 @@ describe('encrypt-submission.controller', () => {
13251332
filename: 'test2.pdf',
13261333
content: Buffer.from('this is another test file'),
13271334
fieldId: 'test-field-id-2',
1328-
}
1335+
},
13291336
]
13301337

13311338
const mockRespondentEmails = ['[email protected]', '[email protected]']
@@ -1359,9 +1366,15 @@ describe('encrypt-submission.controller', () => {
13591366
performEncryptPostSubmissionActionsSpy.mock.calls[0][0].emailFields,
13601367
).toEqual(mockResponses)
13611368

1362-
expect(performEncryptPostSubmissionActionsSpy.mock.calls[0][0].submissionAttachments).toEqual(mockUnencryptedAttachments)
1369+
expect(
1370+
performEncryptPostSubmissionActionsSpy.mock.calls[0][0]
1371+
.submissionAttachments,
1372+
).toEqual(mockUnencryptedAttachments)
13631373

1364-
expect(performEncryptPostSubmissionActionsSpy.mock.calls[0][0].respondentEmails).toEqual(mockRespondentEmails)
1374+
expect(
1375+
performEncryptPostSubmissionActionsSpy.mock.calls[0][0]
1376+
.respondentEmails,
1377+
).toEqual(mockRespondentEmails)
13651378
})
13661379
})
13671380
})

src/app/modules/submission/encrypt-submission/__tests__/encrypt-submission.service.spec.ts

Lines changed: 66 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,32 @@
22
import dbHandler from '__tests__/unit/backend/helpers/jest-db'
33
import { ObjectId } from 'bson'
44
import 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

614
import { 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'
1015
import * as FormService from 'src/app/modules/form/form.service'
1116
import 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'
1417
import * 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+
1526
import { ProcessedFieldResponse } from '../../submission.types'
27+
import {
28+
createEncryptSubmissionWithoutSave,
29+
performEncryptPostSubmissionActions,
30+
} from '../encrypt-submission.service'
1631

1732
const 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

Comments
 (0)