Skip to content

Commit

Permalink
fix: sub task COJ-209
Browse files Browse the repository at this point in the history
  • Loading branch information
likhith-deriv committed Nov 10, 2023
1 parent 231f0ef commit bef7322
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
12 changes: 10 additions & 2 deletions packages/account/src/Helpers/__tests__/utils.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,20 @@ describe('generatePlaceholderText', () => {
});

describe('documentAdditionalError', () => {
const config = {
format: /^[a-z]+$/,
display_name: 'additional doc number',
};
it('should set the correct additional document error when format is incorrect', () => {
expect(documentAdditionalError('testdoc', '/[a-z]/')).toEqual('Please enter the correct format. ');
expect(documentAdditionalError('test1doc', config)).toEqual('Please enter the correct format. ');
});

it('should set the correct additional document error when value is not provided', () => {
expect(documentAdditionalError('', '/[a-z]+/')).toEqual('Please enter your document number. ');
expect(documentAdditionalError('', config)).toEqual('Please enter your additional doc number. ');
});

it('should return no error when input matches the config', () => {
expect(documentAdditionalError('testdoc', config)).toBeNull();
});
});

Expand Down
21 changes: 13 additions & 8 deletions packages/account/src/Helpers/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,17 @@ import { TServerError } from '../Types';
import { LANGUAGE_CODES } from '../Constants/onfido';

export const documentAdditionalError = (
document_additional: string | undefined,
document_additional_format: string
additional_document_value: string | undefined,
document_additional_config: FormikValues
) => {
let error_message = null;
if (!document_additional) {
error_message = localize('Please enter your document number. ');
if (!additional_document_value) {
error_message = localize('Please enter your {{document_name}}. ', {
document_name: document_additional_config?.display_name ?? localize('document number'),
});
} else {
const format_regex = getRegex(document_additional_format);
if (!format_regex.test(document_additional)) {
const format_regex = getRegex(document_additional_config?.format);
if (!format_regex.test(additional_document_value)) {
error_message = localize('Please enter the correct format. ');
}
}
Expand Down Expand Up @@ -149,8 +151,8 @@ export const isDocumentTypeValid = (document_type: FormikValues) => {
return undefined;
};

export const isAdditionalDocumentValid = (document_type: FormikValues, document_additional?: string) => {
const error_message = documentAdditionalError(document_additional, document_type.additional?.format);
export const isAdditionalDocumentValid = (document_type: FormikValues, additional_document_value?: string) => {
const error_message = documentAdditionalError(additional_document_value, document_type?.additional);
if (error_message) {
return localize(error_message) + getExampleFormat(document_type.additional?.example_format);
}
Expand All @@ -169,6 +171,9 @@ export const isDocumentNumberValid = (document_number: string, document_type: Fo
case 'ssnit':
document_name = 'SSNIT number';
break;
case 'national_id_no_photo':
document_name = 'NIN';
break;
default:
document_name = 'document number';
break;
Expand Down

0 comments on commit bef7322

Please sign in to comment.