Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

likhith/chore: incorporated the API response to save the opt-out user data #9618

Merged
2 changes: 1 addition & 1 deletion packages/account/src/Helpers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
} from '@deriv/shared';
import { localize } from '@deriv/translations';
import { ResidenceList, GetSettings, GetAccountStatus } from '@deriv/api-types';
import { FormikErrors, FormikValues } from 'formik';
import { FormikValues } from 'formik';

const getImageLocation = (image_name: string) => getUrlBase(`/public/images/common/${image_name}`);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import { WS } from '@deriv/shared';
import { render, screen, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import AccountWizard from '../account-wizard';

jest.mock('Stores/connect', () => ({
Expand Down Expand Up @@ -29,7 +31,21 @@ jest.mock('../account-wizard-form', () => ({
]),
}));

const Test = () => <div>TestComponent</div>;
jest.mock('@deriv/shared', () => ({
...jest.requireActual('@deriv/shared'),
WS: {
send: jest.fn().mockResolvedValue({}),
},
}));

const mock_form_data = { name: 'Test', document_number: 'none', document_type: { id: 'none' } };

const Test = ({ onSubmit }) => (
<div>
TestComponent
<button onClick={() => onSubmit(0, mock_form_data)}>Submit</button>
</div>
);

jest.mock('../account-wizard-form', () => ({
getItems: jest.fn(() => [
Expand Down Expand Up @@ -66,13 +82,17 @@ describe('<AccountWizard />', () => {
has_residence: true,
is_virtual: true,
real_account_signup_target: 'svg',
realAccountSignup: jest.fn(),
onFinishSuccess: jest.fn(),
realAccountSignup: jest.fn().mockResolvedValue({ new_account_real: { currency: 'USD' } }),
setIsRiskWarningVisible: jest.fn(),
refreshNotifications: jest.fn(),
onError: jest.fn(),
residence: 'id',
setIsRealAccountSignupModalVisible: jest.fn(),
setIsTradingAssessmentForNewUserEnabled: jest.fn(),
setShouldShowAppropriatenessWarningModal: jest.fn(),
setShouldShowRiskWarningModal: jest.fn(),
setRealAccountFormData: jest.fn(),
upgrade_info: '',
setSubSectionIndex: jest.fn(),
sub_section_index: 0,
Expand Down Expand Up @@ -185,4 +205,13 @@ describe('<AccountWizard />', () => {
expect(mock_props.fetchStatesList).toBeCalledTimes(1);
expect(screen.getByText('TestComponent')).toBeInTheDocument();
});

it('should invoke Create account and IDV data submission APIs on click of Submit button', async () => {
render(<AccountWizard {...mock_props} />);
const ele_submit_btn = screen.getByRole('button', { name: 'Submit' });
await waitFor(() => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it expected to wrapp fireEvent with waitFor?
I think the expectation can be wrapped with waitFor.
Could you please try?
@likhith-deriv

Copy link
Contributor Author

@likhith-deriv likhith-deriv Aug 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assertion wrapped inside waitfor callback will pass for both +ve and -ve scenarios for the same assertion check

userEvent.click(ele_submit_btn);
});
expect(WS.send).toHaveBeenCalled();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,16 @@ const AccountWizard = props => {
props.onFinishSuccess(response.new_account_real.currency.toLowerCase());
}
const { document_type, document_number, document_additional } = { ...form_values() };
if (document_type && document_type.id !== IDV_NOT_APPLICABLE_OPTION.id && document_number) {
/**
* If user opted-out of IDV verification, we send the value "none" for document_number and document_type to the API.
*/
const idv_doc_number =
document_type.id === IDV_NOT_APPLICABLE_OPTION.id
? IDV_NOT_APPLICABLE_OPTION.value
: document_number;
if (document_type && idv_doc_number) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we do this formating in idv component itself and not in createRealAccount function?

Copy link
Contributor Author

@likhith-deriv likhith-deriv Aug 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice suggestion. Will check on it

const country_code = props.account_settings.citizen || props.residence;
submitIDVData(document_type, document_number, document_additional, country_code);
submitIDVData(document_type, idv_doc_number, document_additional, country_code);
}
})
.catch(error => {
Expand Down
5 changes: 4 additions & 1 deletion packages/shared/src/utils/constants/idv-options.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { localize } from '@deriv/translations';

export const IDV_NOT_APPLICABLE_OPTION = { id: '#NA', text: localize('I don’t have any of these') };
/**
* Configuration that allows user to opt-out of IDV
*/
export const IDV_NOT_APPLICABLE_OPTION = { id: 'none', text: localize('I want to do this later'), value: 'none' };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we've a separate card just for this option renaming, we shouldn't rename in this card's scope

Copy link
Contributor Author

@likhith-deriv likhith-deriv Aug 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will remove this change from the other card as both text and the DB logging need to be sent on priority