Skip to content

Commit

Permalink
[WALL] aum / WALL - [4916 / 4925] / implement-default-jurisdiction-fl…
Browse files Browse the repository at this point in the history
…ows (deriv-com#17336)

* feat: added created modal and added DocumentTile component

* feat: added DocumentsList component

* refactor: useSortedMT5Accounts to get default jurisdiction accounts

* feat: created MT5LicenceNumber component

* refactor: MT5 password related components to include info for the MT5LicenceMessage

* feat: added getClientVerification util

* fix: some UI issues

* chore: bump deriv-com/ui from 1.35.0 to 1.35.2

* feat: added ClientVerificationStatusBadge component

* feat: updated usage of badge in DocumentList component

* fix: temporary hardcoding of compnay number for non-regulated in MT5LicenceMessage

* refactor: converted getTileProps function to tileProps map in DocumentsList component

* fix: refer to correct key for poa and translation for DocumentTile in DocumentsList component

* fix: logic for getClientVerification util

* refactor: DocumentList to use getClientVerification

* chore: added unit tests for MT5LicenceMessage and DocumentList component

* refactor: renamed and moved CFDPasswordModalTnc to screens/components/MT5PasswordModalTnc

* fix: unit tests for MT5PasswordModalTnc

* fix: added temporary types for default service

* fix: unit tests for AvailableMT5AccountsList

* chore: added unit tests for EnterPassword component

* fix: sonarcloud issue

* fix: the build CI

* fix: unit test for DocumentsList

* fix: added missing localize for getMarketTypeDetails

* refactor: MT5 account filtering and sorting for displaying on traders hub

* chore: applied suggestions

* fix: warning for dependency array in MT5AccountAdded

* fix: applied comments

* feat: created AddedMT5AccountStatusBadge

* refactor: AddedMt5AccountsList for default jurisdiction changes

* fix: remove unwanted status checks for added MT5 accounts

* fix: description width in desktop for ClientVerificationModal

* fix: correct check for showing the ClientVerificationModal for pre-account creation flow

* fix: MT5 account added success screen not showing for first time account creation

* fix: add end margin to status badge for AddedMT5AccountsList

* perf: added unit test for useSortedMT5Accounts hook

* refactor: unit tests for AddedMT5AccountsList

* perf: added unit tests for useAddedMT5Accounts

* fix: ci error for ordering constants

* feat: show the ClientVerificationModal only on the click of the badge for added accounts

* fix: updated mt5 accounts sorting order with stp to show multiple accounts in post account creation

* fix: showing of multiple existing MT5 accounts for a single product type

* feat: reimplement disabled MT5 accounts flow

* fix: disable eslint check for the ObjectWithKeyInUnion utility type

* fix: added disabled flag for added account card component

Co-authored-by: George Usynin <[email protected]>

* feat: added poa_required and poa_pending statuses for showing badge on TH

* feat(wallets): ✨ add Financial STP account

* Update useSortedMT5Accounts.spec.ts

* Update useSortedMT5Accounts.spec.ts

* chore: add icon

* chore: restore package-lock

* Update EnterPassword.scss

* fix: labuan poa

* fix: add required tin check

---------

Co-authored-by: George Usynin <[email protected]>
Co-authored-by: heorhi-deriv <[email protected]>
  • Loading branch information
3 people authored Nov 4, 2024
1 parent d5b0736 commit f99a984
Show file tree
Hide file tree
Showing 61 changed files with 1,687 additions and 607 deletions.
302 changes: 302 additions & 0 deletions packages/api-v2/src/hooks/__tests__/useSortedMT5Accounts.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,302 @@
import { renderHook } from '@testing-library/react-hooks';
import useActiveAccount from '../useActiveAccount';
import useAvailableMT5Accounts from '../useAvailableMT5Accounts';
import useIsEuRegion from '../useIsEuRegion';
import useMT5AccountsList from '../useMT5AccountsList';
import useSortedMT5Accounts from '../useSortedMT5Accounts';
import { cleanup } from '@testing-library/react';

jest.mock('../useActiveAccount', () => jest.fn());
jest.mock('../useAvailableMT5Accounts', () => jest.fn());
jest.mock('../useIsEuRegion', () => jest.fn());
jest.mock('../useMT5AccountsList', () => jest.fn());

const mockMT5NonEUAvailableAccounts = [
{
is_default_jurisdiction: 'false',
product: 'standard',
shortcode: 'svg',
},
{
is_default_jurisdiction: 'false',
product: 'financial',
shortcode: 'svg',
},
{
is_default_jurisdiction: 'true',
product: 'financial',
shortcode: 'vanuatu',
},
{
is_default_jurisdiction: 'true',
product: 'stp',
shortcode: 'vanuatu',
},
{
is_default_jurisdiction: 'true',
product: 'standard',
shortcode: 'vanuatu',
},
{
is_default_jurisdiction: 'true',
product: 'zero_spread',
shortcode: 'bvi',
},
{
is_default_jurisdiction: 'true',
product: 'swap_free',
shortcode: 'svg',
},
];

const mockMT5NonEUAddedAccounts = [
{
is_virtual: false,
landing_company_short: 'vanuatu',
product: 'standard',
},
{
is_virtual: false,
landing_company_short: 'vanuatu',
product: 'financial',
},
{
is_virtual: false,
landing_company_short: 'bvi',
product: 'zero_spread',
},
];

const mockMT5EUAvailableAccounts = [
{
is_default_jurisdiction: 'true',
product: 'financial',
shortcode: 'maltainvest',
},
];

const mockMT5EUAddedAccounts = [
{
is_virtual: false,
landing_company_short: 'maltainvest',
product: 'financial',
},
];

describe('useSortedMT5Accounts', () => {
beforeEach(() => {
(useActiveAccount as jest.Mock).mockReturnValue({
data: { is_virtual: false },
});
(useIsEuRegion as jest.Mock).mockReturnValue({
isEUCountry: false,
});
});
afterEach(cleanup);

it('returns non-eu available accounts with default jurisdiction', () => {
(useAvailableMT5Accounts as jest.Mock).mockReturnValue({
data: mockMT5NonEUAvailableAccounts,
});
(useMT5AccountsList as jest.Mock).mockReturnValue({
data: [],
});

const { result } = renderHook(() => useSortedMT5Accounts());

expect(result.current.data).toEqual([
{
is_added: false,
is_default_jurisdiction: 'true',
product: 'standard',
shortcode: 'vanuatu',
},
{
is_added: false,
is_default_jurisdiction: 'true',
product: 'financial',
shortcode: 'vanuatu',
},
{
is_added: false,
is_default_jurisdiction: 'true',
product: 'stp',
shortcode: 'vanuatu',
},
{
is_added: false,
is_default_jurisdiction: 'true',
product: 'swap_free',
shortcode: 'svg',
},
{
is_added: false,
is_default_jurisdiction: 'true',
product: 'zero_spread',
shortcode: 'bvi',
},
]);
});

it('returns eu available accounts with default jurisdiction', () => {
(useAvailableMT5Accounts as jest.Mock).mockReturnValue({
data: mockMT5EUAvailableAccounts,
});
(useMT5AccountsList as jest.Mock).mockReturnValue({
data: [],
});

const { result } = renderHook(() => useSortedMT5Accounts());

expect(result.current.data).toEqual([
{
is_added: false,
is_default_jurisdiction: 'true',
product: 'financial',
shortcode: 'maltainvest',
},
]);
});

it('returns list of non-eu added and available accounts after some accounts are created', () => {
(useAvailableMT5Accounts as jest.Mock).mockReturnValue({
data: mockMT5NonEUAvailableAccounts,
});
(useMT5AccountsList as jest.Mock).mockReturnValue({
data: mockMT5NonEUAddedAccounts,
});

const { result } = renderHook(() => useSortedMT5Accounts());

expect(result.current.data).toEqual([
{
is_added: true,
is_virtual: false,
landing_company_short: 'vanuatu',
product: 'standard',
},
{
is_added: true,
is_virtual: false,
landing_company_short: 'vanuatu',
product: 'financial',
},
{
is_added: false,
is_default_jurisdiction: 'true',
product: 'stp',
shortcode: 'vanuatu',
},
{
is_added: false,
is_default_jurisdiction: 'true',
product: 'swap_free',
shortcode: 'svg',
},
{
is_added: true,
is_virtual: false,
landing_company_short: 'bvi',
product: 'zero_spread',
},
]);
});

it('returns list of eu added and available accounts after some accounts are created', () => {
(useAvailableMT5Accounts as jest.Mock).mockReturnValue({
data: mockMT5EUAvailableAccounts,
});
(useMT5AccountsList as jest.Mock).mockReturnValue({
data: mockMT5EUAddedAccounts,
});
(useIsEuRegion as jest.Mock).mockReturnValue({
isEUCountry: true,
});

const { result } = renderHook(() => useSortedMT5Accounts());

expect(result.current.data).toEqual([
{
is_added: true,
is_virtual: false,
landing_company_short: 'maltainvest',
product: 'financial',
},
]);
});

it('returns sorted non-eu accounts list in the correct order', () => {
(useAvailableMT5Accounts as jest.Mock).mockReturnValue({
data: mockMT5NonEUAvailableAccounts,
});
(useMT5AccountsList as jest.Mock).mockReturnValue({
data: [],
});

const { result } = renderHook(() => useSortedMT5Accounts());

expect(result.current.data?.map(account => account.product)).toStrictEqual([
'standard',
'financial',
'stp',
'swap_free',
'zero_spread',
]);
});

it('all available MT5 accounts are created', () => {
(useAvailableMT5Accounts as jest.Mock).mockReturnValue({
data: mockMT5NonEUAvailableAccounts,
});
(useMT5AccountsList as jest.Mock).mockReturnValue({
data: [
...mockMT5NonEUAddedAccounts,
{
is_virtual: false,
landing_company_short: 'svg',
product: 'swap_free',
},
{
is_virtual: false,
landing_company_short: 'vanuatu',
product: 'stp',
},
],
});

const { result } = renderHook(() => useSortedMT5Accounts());

expect(result.current.data).toEqual([
{
is_added: true,
is_virtual: false,
landing_company_short: 'vanuatu',
product: 'standard',
},
{
is_added: true,
is_virtual: false,
landing_company_short: 'vanuatu',
product: 'financial',
},
{
is_added: true,
is_virtual: false,
landing_company_short: 'vanuatu',
product: 'stp',
},
{
is_added: true,
is_virtual: false,
landing_company_short: 'svg',
product: 'swap_free',
},
{
is_added: true,
is_virtual: false,
landing_company_short: 'bvi',
product: 'zero_spread',
},
]);
});
});
Loading

0 comments on commit f99a984

Please sign in to comment.