Skip to content

Commit 227f176

Browse files
committed
feat: make fieldtype mandatory for pdf render signature check
1 parent d1ca7b2 commit 227f176

File tree

5 files changed

+38
-23
lines changed

5 files changed

+38
-23
lines changed

__tests__/unit/backend/helpers/generate-email-data.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export const generateSingleAnswerAutoreply = (
1616
): EmailRespondentConfirmationField => ({
1717
question: response.question,
1818
answerTemplate: response.answer.split('\n'),
19+
fieldType: response.fieldType,
1920
})
2021

2122
export const generateSingleAnswerFormData = (

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ const MOCK_AUTOREPLY_DATA = [
9191
{
9292
question: 'Email',
9393
answerTemplate: ['[email protected]'],
94+
fieldType: BasicField.Email,
9495
},
9596
]
9697
const AUTOREPLY_OPTIONS_1: AutoReplyOptions = {

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/email-submission/email-submission.util.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ export const getFormattedResponse = (
280280
autoReplyData = {
281281
question, // No prefixes for autoreply
282282
answerTemplate: answerSplitByNewLine,
283+
fieldType,
283284
}
284285
}
285286

@@ -560,6 +561,7 @@ const maskUidOnLastField = (
560561
return {
561562
question: autoReplyField.question,
562563
answerTemplate: maskedAnswerTemplate,
564+
fieldType: autoReplyField.fieldType,
563565
}
564566
} else {
565567
return autoReplyField
@@ -638,6 +640,7 @@ const getAutoReplyFormattedResponse = (
638640
...(response.fieldType === BasicField.Signature && {
639641
answer: response.answer,
640642
}), // add signature answer for PDF generation
643+
fieldType: response.fieldType,
641644
}
642645
}
643646
return undefined

src/types/email_mode_data.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { BasicField } from '../../shared/types'
33
export type EmailRespondentConfirmationField = {
44
question: string
55
answerTemplate: string[]
6-
fieldType?: BasicField
6+
fieldType: BasicField
77
answer?: string
88
}
99

0 commit comments

Comments
 (0)