-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use identity number from yourInformation in pdf, if the forms have be…
…en upgraded to new format.
- Loading branch information
Showing
5 changed files
with
129 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
packages/shared-domain/src/utils/yourInformationUtils.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import { NavFormType, SubmissionData } from '../form'; | ||
import { yourInformationUtils } from '../index'; | ||
|
||
describe('getYourInformationUtils', () => { | ||
it('returns your information object when present in submission data', () => { | ||
const form = { | ||
components: [ | ||
{ | ||
key: 'yourInfo', | ||
yourInformation: true, | ||
label: '', | ||
type: '', | ||
}, | ||
], | ||
} as NavFormType; | ||
const submission: SubmissionData = { | ||
yourInfo: { name: 'John Doe' }, | ||
}; | ||
|
||
const result = yourInformationUtils.getYourInformation(form, submission); | ||
expect(result).toEqual({ name: 'John Doe' }); | ||
}); | ||
|
||
it('returns the first your information object present in submission data', () => { | ||
const form = { | ||
components: [ | ||
{ | ||
key: 'yourInfo', | ||
yourInformation: true, | ||
label: '', | ||
type: '', | ||
}, | ||
{ | ||
key: 'yourInfo2', | ||
yourInformation: true, | ||
label: '', | ||
type: '', | ||
}, | ||
], | ||
} as NavFormType; | ||
const submission: SubmissionData = { | ||
yourInfo2: { name: 'John Doe' }, | ||
yourInfo: { name: 'Jane Doe' }, | ||
}; | ||
|
||
const result = yourInformationUtils.getYourInformation(form, submission); | ||
expect(result).toEqual({ name: 'Jane Doe' }); | ||
}); | ||
|
||
it('returns undefined when your information object is not present in submission data', () => { | ||
const form = { | ||
components: [ | ||
{ | ||
key: 'yourInfo', | ||
yourInformation: true, | ||
label: '', | ||
type: '', | ||
}, | ||
], | ||
} as NavFormType; | ||
const submission: SubmissionData = {}; | ||
|
||
const result = yourInformationUtils.getYourInformation(form, submission); | ||
expect(result).toBeUndefined(); | ||
}); | ||
|
||
it('returns undefined when no your information component is found in form', () => { | ||
const form = { | ||
components: [ | ||
{ | ||
key: 'otherInfo', | ||
yourInformation: false, | ||
label: '', | ||
type: '', | ||
}, | ||
], | ||
} as NavFormType; | ||
const submission: SubmissionData = { | ||
otherInfo: { name: 'John Doe' }, | ||
}; | ||
|
||
const result = yourInformationUtils.getYourInformation(form, submission); | ||
expect(result).toBeUndefined(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { NavFormType, SubmissionData } from '../form'; | ||
import { navFormUtils } from '../index'; | ||
import SubmissionYourInformation from '../submission/yourInformation'; | ||
|
||
/** | ||
* Returns the first your information object from the submission data. | ||
* @param form | ||
* @param submission | ||
*/ | ||
const getYourInformation = (form: NavFormType, submission: SubmissionData): SubmissionYourInformation | undefined => { | ||
const yourInformationForm = navFormUtils | ||
.flattenComponents(form.components) | ||
.find((component) => component.yourInformation && submission[component.key]); | ||
|
||
if (yourInformationForm) { | ||
return submission[yourInformationForm.key] as SubmissionYourInformation; | ||
} | ||
}; | ||
|
||
const yourInformationUtils = { | ||
getYourInformation, | ||
}; | ||
|
||
export default yourInformationUtils; |