Skip to content

Commit b5fcdbc

Browse files
committed
fix: tc for field type
1 parent 0602f28 commit b5fcdbc

File tree

6 files changed

+133
-54
lines changed

6 files changed

+133
-54
lines changed

src/app/modules/submission/email-submission/__tests__/email-submission.util.spec.ts

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,8 @@ describe('email-submission.util', () => {
207207
]
208208

209209
const expectedAutoReplyData = [
210-
{ question, answerTemplate: [firstRow] },
211-
{ question, answerTemplate: [secondRow] },
210+
{ question, answerTemplate: [firstRow], fieldType: BasicField.Table },
211+
{ question, answerTemplate: [secondRow], fieldType: BasicField.Table },
212212
]
213213

214214
const expectedFormData = [
@@ -240,17 +240,19 @@ describe('email-submission.util', () => {
240240
FormAuthType.NIL,
241241
)
242242

243-
const question = response.question
244-
const answer = response.answerArray.join(', ')
243+
const { question, answerArray, fieldType } = response
244+
const answer = answerArray.join(', ')
245245

246246
const expectedDataCollationData = [{ question, answer }]
247-
const expectedAutoReplyData = [{ question, answerTemplate: [answer] }]
247+
const expectedAutoReplyData = [
248+
{ question, answerTemplate: [answer], fieldType },
249+
]
248250
const expectedFormData = [
249251
{
250252
question,
251253
answer,
252254
answerTemplate: [answer],
253-
fieldType: BasicField.Checkbox,
255+
fieldType,
254256
},
255257
]
256258

@@ -268,19 +270,20 @@ describe('email-submission.util', () => {
268270
FormAuthType.NIL,
269271
)
270272

271-
const question = response.question
272-
const answer = response.answer
273+
const { question, answer, fieldType } = response
273274

274275
const expectedDataCollationData = [
275276
{ question: `${ATTACHMENT_PREFIX}${question}`, answer },
276277
]
277-
const expectedAutoReplyData = [{ question, answerTemplate: [answer] }]
278+
const expectedAutoReplyData = [
279+
{ question, answerTemplate: [answer], fieldType },
280+
]
278281
const expectedFormData = [
279282
{
280283
question: `${ATTACHMENT_PREFIX}${question}`,
281284
answer,
282285
answerTemplate: [answer],
283-
fieldType: BasicField.Attachment,
286+
fieldType,
284287
},
285288
]
286289

@@ -301,18 +304,18 @@ describe('email-submission.util', () => {
301304
FormAuthType.NIL,
302305
)
303306

304-
const question = response.question
307+
const { question, fieldType } = response
305308

306309
const expectedDataCollationData = [{ question, answer }]
307310
const expectedAutoReplyData = [
308-
{ question, answerTemplate: answer.split('\n') },
311+
{ question, answerTemplate: answer.split('\n'), fieldType },
309312
]
310313
const expectedFormData = [
311314
{
312315
question,
313316
answer,
314317
answerTemplate: answer.split('\n'),
315-
fieldType: BasicField.ShortText,
318+
fieldType,
316319
},
317320
]
318321

@@ -333,21 +336,22 @@ describe('email-submission.util', () => {
333336
FormAuthType.NIL,
334337
)
335338

336-
const question = response.question
339+
const { question, fieldType } = response
340+
337341
const answer = answerArray[0].join(',')
338342

339343
const expectedDataCollationData = [
340344
{ question: `${TABLE_PREFIX}${question}`, answer },
341345
]
342346
const expectedAutoReplyData = [
343-
{ question, answerTemplate: answer.split('\n') },
347+
{ question, answerTemplate: answer.split('\n'), fieldType },
344348
]
345349
const expectedFormData = [
346350
{
347351
question: `${TABLE_PREFIX}${question}`,
348352
answer,
349353
answerTemplate: answer.split('\n'),
350-
fieldType: BasicField.Table,
354+
fieldType,
351355
},
352356
]
353357

@@ -366,19 +370,19 @@ describe('email-submission.util', () => {
366370
FormAuthType.NIL,
367371
)
368372

369-
const question = response.question
373+
const { question, fieldType } = response
370374
const answer = answerArray.join(', ')
371375

372376
const expectedDataCollationData = [{ question, answer }]
373377
const expectedAutoReplyData = [
374-
{ question, answerTemplate: answer.split('\n') },
378+
{ question, answerTemplate: answer.split('\n'), fieldType },
375379
]
376380
const expectedFormData = [
377381
{
378382
question,
379383
answer,
380384
answerTemplate: answer.split('\n'),
381-
fieldType: BasicField.Checkbox,
385+
fieldType,
382386
},
383387
]
384388

@@ -398,11 +402,12 @@ describe('email-submission.util', () => {
398402
FormAuthType.NIL,
399403
)
400404

401-
const question = response.question
402-
const answer = response.answer
405+
const { question, answer, fieldType } = response
403406

404407
const expectedDataCollationData = [{ question, answer }]
405-
const expectedAutoReplyData = [{ question, answerTemplate: [answer] }]
408+
const expectedAutoReplyData = [
409+
{ question, answerTemplate: [answer], fieldType },
410+
]
406411
const expectedFormData = [
407412
{
408413
question: `${VERIFIED_PREFIX}${question}`,
@@ -453,10 +458,12 @@ describe('email-submission.util', () => {
453458
{
454459
question: nameResponse.question,
455460
answerTemplate: [nameResponse.answer],
461+
fieldType: nameResponse.fieldType,
456462
},
457463
{
458464
question: vehicleResponse.question,
459465
answerTemplate: [vehicleResponse.answer],
466+
fieldType: vehicleResponse.fieldType,
460467
},
461468
]
462469
const expectedFormData = [
@@ -534,6 +541,7 @@ describe('email-submission.util', () => {
534541
answerTemplate: (response1 as ResponseFormattedForEmail).answer.split(
535542
'\n',
536543
),
544+
fieldType: response1.fieldType,
537545
},
538546
// Note that response2 is not shown in Email Confirmation as isVisible is false
539547
]
@@ -560,11 +568,13 @@ describe('email-submission.util', () => {
560568
answerTemplate: (response1 as ResponseFormattedForEmail).answer.split(
561569
'\n',
562570
),
571+
fieldType: response1.fieldType,
563572
},
564573
// Note that response2 is not shown in Email Confirmation as isVisible is false
565574
{
566575
question: responseCPUID.question,
567576
answerTemplate: ['*****567A'],
577+
fieldType: responseCPUID.fieldType,
568578
},
569579
]
570580
expect(submissionEmailObjCP.autoReplyData).toEqual(correctConfirmation)

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
DateString,
77
FormResponseMode,
88
PaymentChannel,
9-
SubmissionType
9+
SubmissionType,
1010
} from '../../../../../shared/types'
1111
import {
1212
EmailAdminDataField,
@@ -20,10 +20,11 @@ import { createLoggerWithLabel } from '../../../config/logger'
2020
import { getEncryptSubmissionModel } from '../../../models/submission.server.model'
2121
import { AutoreplyPdfGenerationError } from '../../../services/mail/mail.errors'
2222
import MailService from '../../../services/mail/mail.service'
23+
import { AutoReplyMailData } from '../../../services/mail/mail.types'
2324
import {
24-
AutoReplyMailData
25-
} from '../../../services/mail/mail.types'
26-
import { generateAutoreplyPdf, generatePdfRenderData } from '../../../services/mail/mail.utils'
25+
generateAutoreplyPdf,
26+
generatePdfRenderData,
27+
} from '../../../services/mail/mail.utils'
2728
import { createQueryWithDateParam } from '../../../utils/date'
2829
import { getMongoErrorMessage } from '../../../utils/handle-mongo-error'
2930
import { DatabaseError, PossibleDatabaseError } from '../../core/core.errors'

src/app/modules/submission/multirespondent-submission/__tests__/multirespondent-submission.utils.spec.ts

Lines changed: 66 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -436,9 +436,17 @@ describe('multirespondent-submission.utils', () => {
436436
})
437437

438438
expect(result).toEqual([
439-
{ question: 'Short Text', answer: 'Test answer' },
440-
{ question: 'Number', answer: '42' },
441-
{ question: 'Email', answer: '[email protected]' },
439+
{
440+
question: 'Short Text',
441+
answer: 'Test answer',
442+
fieldType: BasicField.ShortText,
443+
},
444+
{ question: 'Number', answer: '42', fieldType: BasicField.Number },
445+
{
446+
question: 'Email',
447+
answer: '[email protected]',
448+
fieldType: BasicField.Email,
449+
},
442450
])
443451
})
444452

@@ -463,7 +471,11 @@ describe('multirespondent-submission.utils', () => {
463471
})
464472

465473
expect(result).toEqual([
466-
{ question: '[Attachment] File Upload', answer: 'file.pdf' },
474+
{
475+
question: '[Attachment] File Upload',
476+
answer: 'file.pdf',
477+
fieldType: BasicField.Attachment,
478+
},
467479
])
468480
})
469481

@@ -514,18 +526,22 @@ describe('multirespondent-submission.utils', () => {
514526
{
515527
question: '[Table] Table of Name and Age (Name; Age)',
516528
answer: 'Alice; 30',
529+
fieldType: BasicField.Table,
517530
},
518531
{
519532
question: '[Table] Table of Name and Age (Name; Age)',
520533
answer: 'Bob; 25',
534+
fieldType: BasicField.Table,
521535
},
522536
{
523537
question: '[Table] Table of Hobbies (Hobby; Years)',
524538
answer: 'Swimming; 5',
539+
fieldType: BasicField.Table,
525540
},
526541
{
527542
question: '[Table] Table of Hobbies (Hobby; Years)',
528543
answer: 'Reading; 10',
544+
fieldType: BasicField.Table,
529545
},
530546
])
531547
})
@@ -554,7 +570,11 @@ describe('multirespondent-submission.utils', () => {
554570
})
555571

556572
expect(result).toEqual([
557-
{ question: 'Checkbox', answer: 'Option 1,Option 2,Custom Option' },
573+
{
574+
question: 'Checkbox',
575+
answer: 'Option 1,Option 2,Custom Option',
576+
fieldType: BasicField.Checkbox,
577+
},
558578
])
559579
})
560580

@@ -591,11 +611,48 @@ describe('multirespondent-submission.utils', () => {
591611
{
592612
question: 'Address',
593613
answer: '161, BUKIT BATOK STREET 11, #1-1, SINGAPORE 650161',
614+
fieldType: BasicField.Address,
615+
},
616+
])
617+
})
618+
619+
it('should handle signature fields correctly when includeSignatureDataPngUri is true', () => {
620+
const formFields: FormFieldSchema[] = [
621+
{
622+
_id: '1',
623+
title: 'Signature',
624+
fieldType: BasicField.Signature,
625+
} as ISignatureFieldSchema,
626+
]
627+
628+
const responses: FieldResponsesV3 = {
629+
'1': {
630+
fieldType: BasicField.Signature,
631+
answer: {
632+
type: 'draw',
633+
value: [[[10, 20, 0.5]], [[40, 40, 0.5]]],
634+
} as SignatureFieldResponseV3,
635+
},
636+
}
637+
638+
const result = getQuestionAnswerPairsForMultipleFields({
639+
formFields,
640+
responses,
641+
includeSignatureDataPngDataUri: true,
642+
})
643+
644+
expect(result).toEqual([
645+
{
646+
question: '[signature] Signature',
647+
answer: 'Signature captured',
648+
fieldType: BasicField.Signature,
649+
signatureDataPngDataUri:
650+
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAJYAAAB4CAYAAAAQTwsQAAAABmJLR0QA/wD/AP+gvaeTAAAF+klEQVR4nO3dv0tybRzH8c+tNxg2VFuWJ8iGaJKgHzQHeiZpamsJmhqCqCHHoK1Rmvv1BzQE0ebmIoGQQqUOmlSjLmF1uJ7peeC+n8qHzvd7bq6ezwva6ntd0JvrHE3thzHGgEhY6E9vgL4nhkUqGBapYFikgmGRCoZFKhgWqWBYpIJhkQqGRSoYFqlgWKSCYZEKhkUqGBap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U6HZPNZk00Gu35wcF/f0WjUbO5uWmen5/V9sXPILXY4+MjXNdFqVT60s+n02mcnZ2hr69PeGf8cFtr1Wo1pFIp1Ot1X3O04mJYFnp5ecHc3NyXT6rfacTFpxsstLe3JxYVAFxeXmJtbU1sHsATyzq1Wg1TU1N4fX0Vn53L5bC+vi4yiyeWZU5OTlSiAoCNjQ1UKhWRWQzLIsYYnJ6eqs33PA87Ozsis3gptMjt7S0mJydV14hEInh6esLAwICvOTyxLHJ/f6++RrfbxdHRke85DMsirVYrkHUKhYLvGQzLIt1uN5B17u7ufM9gWBZJJBKBrCPx/yIZlkUmJiYCWafdbvuewbAs4jgOHMdRX2dsbMz3DIZlkVAohNXVVfV1Zmdnfc/g81iWaTabGB8fh+d5amtcXV1henra1wyeWJZxHAdbW1tq80dHR5FMJn3PYVgW2t3dxczMjMrsbDYr8qiQl0JLVatVLC4uotFoiM10XRfn5+cIh8O+ZzEsiz08PCCTyaBYLPqeNTg4iHK5jJGREYGd8VJotVgshnw+j5WVFV9zhoaGkM/nxaICGJb1+vv7cXx8jFwu96V7I9d1cX19LXLD/gu19/9Q4MrlsslkMiYSifR8C1g8HjcHBwfG8zyVvfAe6xtqt9s4PDxEoVBAtVoFAHQ6HcTjcczPz2N5eRnJZFLk0d9HGBap4D0WqWBYpIJhkQqGRSoYFqlgWKSCYZEKhkUqGBapYFikgmGRCoZFKhgWqWBYpIJhkYq/ACr2ePA6eqVSAAAAAElFTkSuQmCC',
594651
},
595652
])
596653
})
597654

598-
it('should handle signature fields correctly', () => {
655+
it('should handle signature fields correctly when includeSignatureDataPngUri is false', () => {
599656
const formFields: FormFieldSchema[] = [
600657
{
601658
_id: '1',
@@ -623,6 +680,8 @@ describe('multirespondent-submission.utils', () => {
623680
{
624681
question: '[signature] Signature',
625682
answer: 'Signature captured',
683+
fieldType: BasicField.Signature,
684+
signatureDataPngDataUri: undefined,
626685
},
627686
])
628687
})
@@ -645,6 +704,7 @@ describe('multirespondent-submission.utils', () => {
645704
{
646705
question: 'SingPass Validated NRIC (Step 1)',
647706
answer: 'S1234567A',
707+
fieldType: BasicField.Nric,
648708
},
649709
])
650710
})

src/app/modules/submission/multirespondent-submission/multirespondent-submission.service.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ import {
3737
MailSendError,
3838
} from '../../../services/mail/mail.errors'
3939
import MailService from '../../../services/mail/mail.service'
40-
import { generateAutoreplyPdf, generatePdfRenderData } from '../../../services/mail/mail.utils'
40+
import {
41+
generateAutoreplyPdf,
42+
generatePdfRenderData,
43+
} from '../../../services/mail/mail.utils'
4144
import { transformMongoError } from '../../../utils/handle-mongo-error'
4245
import { DatabaseError } from '../../core/core.errors'
4346
import { isFormMultirespondent } from '../../form/form.utils'
@@ -61,9 +64,10 @@ import { reportSubmissionResponseTime } from '../submissions.statsd-client'
6164
import { MultirespondentSubmissionContent } from './multirespondent-submission.types'
6265
import {
6366
extractRespondentCopyEmailDatas,
64-
getEmailFromResponses, getQuestionAnswerPairsForMultipleFields,
67+
getEmailFromResponses,
68+
getQuestionAnswerPairsForMultipleFields,
6569
getResponsesDataFromMrfResponses,
66-
retrieveWorkflowStepEmailAddresses
70+
retrieveWorkflowStepEmailAddresses,
6771
} from './multirespondent-submission.utils'
6872

6973
const logger = createLoggerWithLabel(module)
@@ -896,7 +900,7 @@ const generatePdfAttachmentIfRequired = ({
896900
refNo: submissionId,
897901
formTitle: form.title,
898902
submissionDateTime: submission.created ?? new Date(),
899-
responsesData,
903+
responsesData,
900904
formUrl: `${config.app.appUrl}/${form._id}`,
901905
})
902906

src/app/services/mail/mail.service.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -840,15 +840,16 @@ export class MailService {
840840
!isPaymentEnabled && mailData.includeFormSummary
841841

842842
if (shouldPdfAttachmentBeIncluded && !pdfAttachment) {
843-
logger.error({
844-
message: 'Could not find PDF attachment required for autoReply email. Continuing to send without PDF attachment.',
843+
logger.error({
844+
message:
845+
'Could not find PDF attachment required for autoReply email. Continuing to send without PDF attachment.',
845846
meta: {
846847
action: 'sendAutoReplyEmails',
847848
formId: String(form._id),
848849
submissionId: String(submission.id),
849850
},
850851
})
851-
}
852+
}
852853

853854
return pdfAttachment && shouldPdfAttachmentBeIncluded
854855
? [...submissionAttachments, pdfAttachment]

0 commit comments

Comments
 (0)