-
Notifications
You must be signed in to change notification settings - Fork 299
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b7da18f
commit 17ca1cb
Showing
8 changed files
with
131 additions
and
68 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
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
33 changes: 33 additions & 0 deletions
33
packages/shared/src/utils/config/__tests__/adapters.spec.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,33 @@ | ||
import { formatIDVFormValues } from '../adapters'; | ||
|
||
describe('Adapter functions tests', () => { | ||
it('should return the correct IDV form values', () => { | ||
const form_data = { | ||
document_type: { id: 'test' }, | ||
document_additional: 'additional text', | ||
document_number: '123456789', | ||
}; | ||
|
||
expect(formatIDVFormValues(form_data, 'US')).toEqual({ | ||
document_number: '123456789', | ||
document_additional: 'additional text', | ||
document_type: 'test', | ||
issuing_country: 'US', | ||
}); | ||
}); | ||
|
||
it('should render the correct IDV form values when document type is not applicable', () => { | ||
const form_data = { | ||
document_type: { id: 'none' }, | ||
document_additional: '', | ||
document_number: '123456789', | ||
}; | ||
|
||
expect(formatIDVFormValues(form_data, 'US')).toEqual({ | ||
document_number: 'none', | ||
document_additional: '', | ||
document_type: 'none', | ||
issuing_country: 'US', | ||
}); | ||
}); | ||
}); |
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,40 @@ | ||
import { IDV_NOT_APPLICABLE_OPTION } from '../constants/idv-options'; | ||
import { FormikValues } from 'formik'; | ||
|
||
type TDocumentList = Array<{ | ||
id: string; | ||
text: string; | ||
value?: string; | ||
sample_image?: string; | ||
example_format?: string; | ||
additional?: { | ||
display_name: string; | ||
format: string; | ||
}; | ||
}>; | ||
|
||
type TIDVFormValues = { | ||
document_type: TDocumentList[0]; | ||
document_number: string; | ||
document_additional?: string; | ||
error_message?: string; | ||
}; | ||
|
||
/** | ||
* Formats the IDV form values to be sent to the API | ||
* @param idv_form_value - Formik values of the IDV form | ||
* @param country_code - Country code of the user | ||
* @returns IDV form values | ||
*/ | ||
export const formatIDVFormValues = (idv_form_value: FormikValues, country_code: string) => { | ||
const idv_submit_data = { | ||
document_number: | ||
idv_form_value.document_type.id === IDV_NOT_APPLICABLE_OPTION.id | ||
? IDV_NOT_APPLICABLE_OPTION.value | ||
: idv_form_value.document_number, | ||
document_additional: idv_form_value.document_additional, | ||
document_type: idv_form_value.document_type.id, | ||
issuing_country: country_code, | ||
}; | ||
return idv_submit_data; | ||
}; |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './config'; | ||
export * from './app-config'; | ||
export * from './platform-config'; | ||
export * from './adapters'; |