Skip to content

Commit 5c319f5

Browse files
committed
added formatMyInfoStorageResponseTests, removed console testing logs
1 parent 1cb0228 commit 5c319f5

File tree

3 files changed

+77
-7
lines changed

3 files changed

+77
-7
lines changed

src/app/modules/myinfo/myinfo.service.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,8 +389,6 @@ export class MyInfoServiceClass {
389389
},
390390
).andThen((hashes) => {
391391
if (hashes) {
392-
console.log('hashes!')
393-
console.log(hashes)
394392
return okAsync(hashes)
395393
} else {
396394
logger.info({

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/encrypt-submission/encrypt-submission.utils.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,19 +144,14 @@ export const formatMyInfoStorageResponseData = (
144144
parsedResponses: ProcessedFieldResponse[],
145145
hashedFields?: Set<MyInfoKey>,
146146
) => {
147-
console.log(`formatMyInfoStorageResponseData`)
148147
if (!hashedFields) {
149148
return parsedResponses
150149
} else {
151150
return parsedResponses.flatMap((response) => {
152151
if (isProcessedChildResponse(response)) {
153-
console.log(`isProcessedChildResponse)`)
154152
return getAnswersForChild(response).map((childField) => {
155-
console.log(`childField`)
156-
console.log(childField)
157153
const myInfoPrefix = getMyInfoPrefix(childField, hashedFields)
158154
childField.question = `${myInfoPrefix}${childField.question}`
159-
console.log(childField.question)
160155
return childField
161156
})
162157
} else {

0 commit comments

Comments
 (0)