From f9b4035947ab6143a66824c6d776ab7e1b059e58 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E2=80=9Cyauheni-kryzhyk-deriv=E2=80=9D?=
<“yauheni@deriv.me”>
Date: Fri, 24 Mar 2023 17:28:44 +0800
Subject: [PATCH] fix: remove validation for sequental and repetitive digits
idv
---
.../__tests__/idv-document-submit.spec.js | 49 -----------------
.../idv-document-submit.jsx | 21 +-------
.../poi/idv-document-submit/utils.js | 52 +------------------
.../idv-doc-submit-on-signup.jsx | 14 +----
4 files changed, 4 insertions(+), 132 deletions(-)
diff --git a/packages/account/src/Components/poi/idv-document-submit/__tests__/idv-document-submit.spec.js b/packages/account/src/Components/poi/idv-document-submit/__tests__/idv-document-submit.spec.js
index 40b62b8829a0..9e6c3d3fd745 100644
--- a/packages/account/src/Components/poi/idv-document-submit/__tests__/idv-document-submit.spec.js
+++ b/packages/account/src/Components/poi/idv-document-submit/__tests__/idv-document-submit.spec.js
@@ -2,7 +2,6 @@ import React from 'react';
import { fireEvent, render, screen, waitFor } from '@testing-library/react';
import { isDesktop, isMobile } from '@deriv/shared';
import IdvDocumentSubmit from '../idv-document-submit';
-import { isSequentialNumber, isRecurringNumberRegex } from '../utils';
jest.mock('react-router');
jest.mock('Assets/ic-document-submit-icon.svg', () => jest.fn(() => 'DocumentSubmitLogo'));
@@ -25,9 +24,6 @@ jest.mock('../utils.js', () => ({
return data[country_code][key];
},
getRegex: jest.fn(() => /5436454364243/i),
- isSequentialNumber: jest.fn(() => false),
- isRecurringNumberRegex: jest.fn(() => false),
- isIDVWhitelistDocumentNumber: jest.fn(() => false),
}));
jest.mock('@deriv/shared', () => ({
@@ -104,54 +100,9 @@ describe('', () => {
});
});
- it('should not allow users to fill in repetitive document numbers', async () => {
- //invalid document number- error should be shown
- isDesktop.mockReturnValue(false);
- isMobile.mockReturnValue(true);
- isSequentialNumber.mockReturnValue(true);
- isRecurringNumberRegex.mockReturnValue(true);
-
- const selected_doc_msg =
- 'Please ensure all your personal details are the same as in your chosen document. If you wish to update your personal details, go to account settings.';
-
- render();
-
- const verifyBtn = screen.getByRole('button', { name: /verify/i });
- expect(verifyBtn).toBeDisabled();
-
- const document_type_input = screen.getByRole('combobox');
- expect(document_type_input.name).toBe('document_type');
- const document_number_input = screen.getByPlaceholderText('Enter your document number');
- expect(document_number_input.name).toBe('document_number');
- expect(document_number_input).toBeDisabled();
- expect(screen.queryByText(selected_doc_msg)).not.toBeInTheDocument();
-
- fireEvent.change(document_type_input, { target: { value: 'Test document 2 name' } });
- expect(document_number_input).not.toBeDisabled();
- expect(screen.getByText(selected_doc_msg)).toBeInTheDocument();
-
- fireEvent.blur(document_number_input);
- expect(await screen.findByText(/please enter your document number/i)).toBeInTheDocument();
-
- Object.defineProperty(window, 'location', {
- get() {
- return { hash: '#toggle_id_validation' };
- },
- });
-
- fireEvent.keyUp(document_number_input);
- fireEvent.change(document_number_input, { target: { value: 'A-54321' } });
- expect(await screen.findByText(/please enter a valid ID number/i)).toBeInTheDocument();
-
- fireEvent.change(document_number_input, { target: { value: '111112' } });
- expect(await screen.findByText(/please enter a valid ID number/i)).toBeInTheDocument();
- });
-
it('should change inputs, check document_number validation and trigger "Verify" button after rendering IdvDocumentSubmit component', async () => {
isDesktop.mockReturnValue(false);
isMobile.mockReturnValue(true);
- isSequentialNumber.mockReturnValue(false);
- isRecurringNumberRegex.mockReturnValue(false);
const selected_doc_msg =
'Please ensure all your personal details are the same as in your chosen document. If you wish to update your personal details, go to account settings.';
diff --git a/packages/account/src/Components/poi/idv-document-submit/idv-document-submit.jsx b/packages/account/src/Components/poi/idv-document-submit/idv-document-submit.jsx
index ae42fd1d24c9..5789f46b376b 100644
--- a/packages/account/src/Components/poi/idv-document-submit/idv-document-submit.jsx
+++ b/packages/account/src/Components/poi/idv-document-submit/idv-document-submit.jsx
@@ -5,15 +5,7 @@ import { Autocomplete, Button, DesktopWrapper, Input, MobileWrapper, Text, Selec
import { Formik, Field } from 'formik';
import { localize, Localize } from '@deriv/translations';
import { formatInput, WS } from '@deriv/shared';
-import {
- documentAdditionalError,
- getDocumentData,
- getRegex,
- isRecurringNumberRegex,
- isSequentialNumber,
- preventEmptyClipboardPaste,
- isIDVWhitelistDocumentNumber,
-} from './utils';
+import { documentAdditionalError, getDocumentData, getRegex, preventEmptyClipboardPaste } from './utils';
import FormFooter from 'Components/form-footer';
import BackButtonIcon from 'Assets/ic-poi-back-btn.svg';
import DocumentSubmitLogo from 'Assets/ic-document-submit-icon.svg';
@@ -112,17 +104,8 @@ const IdvDocumentSubmit = ({ handleBack, handleViewComplete, selected_country, i
const validateFields = values => {
const errors = {};
const { document_type, document_number, document_additional } = values;
- const is_sequential_number = isSequentialNumber(document_number);
- const is_recurring_number = isRecurringNumberRegex(document_number);
const needs_additional_document = !!document_type.additional;
- const is_idv_whitelist_document_number = isIDVWhitelistDocumentNumber(
- country_code,
- document_type.id,
- document_number
- );
- const is_document_number_invalid =
- (!is_idv_whitelist_document_number && (is_recurring_number || is_sequential_number)) ||
- document_number === document_type.example_format;
+ const is_document_number_invalid = document_number === document_type.example_format;
if (!document_type || !document_type.text || !document_type.value) {
errors.document_type = localize('Please select a document type.');
diff --git a/packages/account/src/Components/poi/idv-document-submit/utils.js b/packages/account/src/Components/poi/idv-document-submit/utils.js
index 719f7a729ace..a7e40e095b0e 100644
--- a/packages/account/src/Components/poi/idv-document-submit/utils.js
+++ b/packages/account/src/Components/poi/idv-document-submit/utils.js
@@ -1,25 +1,4 @@
-import { getPlatformFromUrl, getUrlBase } from '@deriv/shared';
-
-const PATTERN_SIZE = 5;
-
-export const isRecurringNumberRegex = document_number => document_number.replace(/[.-]*/g, '').match(/([0-9])\1{4,}/g);
-
-const createDocumentPatterns = () => {
- const ID_PATTERN = '0123456789';
- const STEPS = 5; // Steps start at 0
- const reverse_pattern = ID_PATTERN.split('').reverse().join('');
- const pattern_array = [];
-
- for (let step = 0; step < STEPS; step++) {
- const pattern_end = PATTERN_SIZE + step;
- pattern_array.push(ID_PATTERN.substring(step, pattern_end));
-
- // Reverse version of the pattern, example: 9876543210
- pattern_array.push(reverse_pattern.substring(step, pattern_end));
- }
-
- return pattern_array;
-};
+import { getUrlBase } from '@deriv/shared';
export const documentAdditionalError = (document_additional, document_additional_format) => {
let error_message = null;
@@ -35,28 +14,6 @@ export const documentAdditionalError = (document_additional, document_additional
return error_message;
};
-export const isSequentialNumber = document_number => {
- const trimmed_document_number = document_number.replace(/[.-]*/g, '');
- const pattern_results = [];
-
- if (document_number.length >= PATTERN_SIZE) {
- createDocumentPatterns().forEach(pattern => {
- pattern_results.push(trimmed_document_number.includes(pattern));
- });
- }
-
- return pattern_results.includes(true);
-};
-
-// function for skipping validation of exact document numbers for QA smileidentity sandbox testing
-export const isIDVWhitelistDocumentNumber = (country, document_type, document_number) => {
- const is_whitelisted_number =
- idv_test_document_whitelist.has(country) &&
- idv_test_document_whitelist.get(country)[document_type] === document_number;
-
- return is_whitelisted_number && (getPlatformFromUrl().is_test_link || getPlatformFromUrl().is_staging);
-};
-
export const getRegex = target_regex => {
const output_regex = regex.find(r => r.regex_string === target_regex);
if (output_regex) {
@@ -215,10 +172,3 @@ const idv_document_data = {
},
},
};
-
-export const idv_test_document_whitelist = new Map([
- ['gh', { drivers_license: 'B0000000', passport: 'G0000000', ssnit: 'C000000000000', voter_id: '0000000000' }],
- ['ke', { alien_card: '000000', passport: 'A00000000', national_id: '00000000' }],
- ['ng', { drivers_license: 'ABC000000000', nin_slip: '00000000000', voter_id: '0000000000000000000' }],
- ['za', { national_id: '0000000000000', national_id_no_photo: '0000000000000' }],
-]);
diff --git a/packages/account/src/Components/poi/poi-form-on-signup/idv-doc-submit-on-signup/idv-doc-submit-on-signup.jsx b/packages/account/src/Components/poi/poi-form-on-signup/idv-doc-submit-on-signup/idv-doc-submit-on-signup.jsx
index 627224a57346..adc77ecf4bc1 100644
--- a/packages/account/src/Components/poi/poi-form-on-signup/idv-doc-submit-on-signup/idv-doc-submit-on-signup.jsx
+++ b/packages/account/src/Components/poi/poi-form-on-signup/idv-doc-submit-on-signup/idv-doc-submit-on-signup.jsx
@@ -18,10 +18,7 @@ import {
documentAdditionalError,
getDocumentData,
getRegex,
- isRecurringNumberRegex,
- isSequentialNumber,
preventEmptyClipboardPaste,
- isIDVWhitelistDocumentNumber,
} from '../../idv-document-submit/utils';
import DocumentSubmitLogo from 'Assets/ic-document-submit-icon.svg';
@@ -94,17 +91,8 @@ export const IdvDocSubmitOnSignup = ({ citizen_data, has_previous, onPrevious, o
const validateFields = values => {
const errors = {};
const { document_type, document_number, document_additional } = values;
- const is_sequential_number = isSequentialNumber(document_number);
- const is_recurring_number = isRecurringNumberRegex(document_number);
const needs_additional_document = !!document_type.additional;
- const is_idv_whitelist_document_number = isIDVWhitelistDocumentNumber(
- country_code,
- document_type.id,
- document_number
- );
- const is_document_number_invalid =
- (!is_idv_whitelist_document_number && (is_recurring_number || is_sequential_number)) ||
- document_number === document_type.example_format;
+ const is_document_number_invalid = document_number === document_type.example_format;
if (!document_type || !document_type.text || !document_type.value) {
errors.document_type = localize('Please select a document type.');