Skip to content

Commit c97a4f5

Browse files
authored
fix: myinfo children missing prefix (#8916)
* draft changes with console logs for testing * revamped logging for debugging * revert children dev code change * added childName to responseId * updated getMyInfoPrefix function to check for child ids * revert path update on FE component * added formatMyInfoStorageResponseTests, removed console testing logs * removed remaining debugging logs * reverted middleware functions changed to support debugging logs
1 parent 76cf7bd commit c97a4f5

File tree

2 files changed

+86
-1
lines changed

2 files changed

+86
-1
lines changed

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

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { IPopulatedEncryptedForm, StorageModeSubmissionData } from 'src/types'
66

77
import {
88
createStorageModeSubmissionDto,
9+
formatMyInfoStorageResponseData,
910
getPaymentAmount,
1011
getPaymentIntentDescription,
1112
} from '../encrypt-submission.utils'
@@ -150,4 +151,80 @@ describe('encrypt-submission.utils', () => {
150151
expect(result).toContain(expectedValue)
151152
})
152153
})
154+
155+
describe('formatMyInfoStorageResponseData', () => {
156+
it('should return original responses when no hashed fields are provided', () => {
157+
// Arrange
158+
const parsedResponses: any[] = [
159+
{ _id: 'field1', question: 'Question 1' },
160+
{ _id: 'field2', question: 'Question 2' },
161+
]
162+
163+
// Act
164+
const actual = formatMyInfoStorageResponseData(parsedResponses)
165+
166+
// Assert
167+
expect(actual).toEqual(parsedResponses)
168+
})
169+
170+
it('should prefix MyInfo fields in responses when hashed fields are provided', () => {
171+
// Arrange
172+
const parsedResponses: any[] = [
173+
{
174+
_id: 'field1',
175+
question: 'Question 1',
176+
myInfo: { attr: 'NAME' },
177+
answer: 'John Doe',
178+
fieldType: 'textfield',
179+
},
180+
{
181+
_id: 'field2',
182+
question: 'Question 2',
183+
answer: 'Some answer',
184+
fieldType: 'textfield',
185+
},
186+
{
187+
_id: 'childrenbirthrecords.692411846d1da146b503aada.childname.0',
188+
question: 'Question Child',
189+
myInfo: { attr: 'childname' },
190+
answer: 'Child Name',
191+
fieldType: 'children',
192+
},
193+
]
194+
const hashedFields = new Set([
195+
'field1',
196+
'childrenbirthrecords.692411846d1da146b503aada.childname.0',
197+
])
198+
199+
// Act
200+
const actual = formatMyInfoStorageResponseData(
201+
parsedResponses,
202+
hashedFields,
203+
)
204+
205+
// Assert
206+
expect(actual).toEqual([
207+
{
208+
_id: 'field1',
209+
question: '[MyInfo] Question 1',
210+
myInfo: { attr: 'NAME' },
211+
answer: 'John Doe',
212+
fieldType: 'textfield',
213+
},
214+
{
215+
_id: 'field2',
216+
question: 'Question 2',
217+
answer: 'Some answer',
218+
fieldType: 'textfield',
219+
},
220+
{
221+
_id: 'childrenbirthrecords.692411846d1da146b503aada.childname.0',
222+
question: '[MyInfo] Question Child',
223+
myInfo: { attr: 'childname' },
224+
answer: 'Child Name',
225+
fieldType: 'children',
226+
},
227+
])
228+
})
229+
})
153230
})

src/app/modules/submission/submission.utils.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -776,7 +776,15 @@ export const getMyInfoPrefix = (
776776
response: ResponseFormattedForEmail | ProcessedFieldResponse,
777777
hashedFields: Set<MyInfoKey>,
778778
): string => {
779-
return !!response.myInfo?.attr && hashedFields.has(response._id)
779+
/* encrypt mode children fields have ids e.g. childrenbirthrecords.67585515e1ced6d790a91e14.childname.0
780+
* without the suffixed child name. So we check if any hashed fields starts with response id
781+
*/
782+
const isResponseMyInfoChildren =
783+
response.fieldType === BasicField.Children &&
784+
Array.from(hashedFields).some((field) => field.startsWith(response._id))
785+
786+
return !!response.myInfo?.attr &&
787+
(hashedFields.has(response._id) || isResponseMyInfoChildren)
780788
? MYINFO_PREFIX
781789
: ''
782790
}

0 commit comments

Comments
 (0)