forked from deriv-com/p2p
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuseIsP2PBlocked.spec.ts
76 lines (60 loc) · 3.78 KB
/
useIsP2PBlocked.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import { useGetAccountStatus } from '@deriv-com/api-hooks';
import { renderHook } from '@testing-library/react';
import { api } from '../..';
import useIsP2PBlocked from '../useIsP2PBlocked';
jest.mock('@deriv-com/api-hooks', () => ({
useGetAccountStatus: jest.fn(() => ({ data: undefined })),
}));
jest.mock('../..', () => ({
api: {
account: {
useActiveAccount: jest.fn(() => ({ data: undefined })),
},
},
}));
const mockUseGetAccountStatus = useGetAccountStatus as jest.Mock;
const mockUseActiveAccount = api.account.useActiveAccount as jest.Mock;
describe('useIsP2PBlocked', () => {
it('should return isP2PBlocked as undefined and status as empty string when accountStatus is not defined', () => {
const { result } = renderHook(() => useIsP2PBlocked());
expect(result.current).toStrictEqual({ isP2PBlocked: false, status: 'p2pBlocked' });
});
it('should return isP2PBlocked as false and status as empty string if user can use p2p', () => {
mockUseGetAccountStatus.mockImplementation(() => ({ data: { p2p_status: 'none', status: [] } }));
mockUseActiveAccount.mockImplementation(() => ({ data: { currency: 'USD', is_virtual: 0 } }));
const { result } = renderHook(() => useIsP2PBlocked());
expect(result.current).toStrictEqual({ isP2PBlocked: false, status: 'p2pBlocked' });
});
it('should return isP2PBlocked as true and status as p2pBlocked if p2p_status is perm banned', () => {
mockUseGetAccountStatus.mockImplementation(() => ({ data: { p2p_status: 'perm_ban', status: [] } }));
mockUseActiveAccount.mockImplementation(() => ({ data: { currency: 'USD', is_virtual: 0 } }));
const { result } = renderHook(() => useIsP2PBlocked());
expect(result.current).toStrictEqual({ isP2PBlocked: true, status: 'p2pBlocked' });
});
it('should return isP2PBlocked as true and status as systemMaintenance if cashier_validation has system_maintenance', () => {
mockUseGetAccountStatus.mockImplementation(() => ({
data: { cashier_validation: ['system_maintenance'], p2p_status: 'none', status: [] },
}));
mockUseActiveAccount.mockImplementation(() => ({ data: { currency: 'USD', is_virtual: 0 } }));
const { result } = renderHook(() => useIsP2PBlocked());
expect(result.current).toStrictEqual({ isP2PBlocked: true, status: 'systemMaintenance' });
});
it('should return isP2PBlocked as true and status as crypto if currency_type is crypto', () => {
mockUseGetAccountStatus.mockImplementation(() => ({ data: { p2p_status: 'none', status: [] } }));
mockUseActiveAccount.mockImplementation(() => ({ data: { currency_type: 'crypto', is_virtual: 0 } }));
const { result } = renderHook(() => useIsP2PBlocked());
expect(result.current).toStrictEqual({ isP2PBlocked: true, status: 'crypto' });
});
it('should return isP2PBlocked as true and status as demo if account is virtual', () => {
mockUseGetAccountStatus.mockImplementation(() => ({ data: { p2p_status: 'none', status: [] } }));
mockUseActiveAccount.mockImplementation(() => ({ data: { currency: 'USD', is_virtual: 1 } }));
const { result } = renderHook(() => useIsP2PBlocked());
expect(result.current).toStrictEqual({ isP2PBlocked: true, status: 'demo' });
});
it('should return isP2PBlocked as true and status as nonUSD if currency is not USD', () => {
mockUseGetAccountStatus.mockImplementation(() => ({ data: { p2p_status: 'none', status: [] } }));
mockUseActiveAccount.mockImplementation(() => ({ data: { currency: 'EUR', is_virtual: 0 } }));
const { result } = renderHook(() => useIsP2PBlocked());
expect(result.current).toStrictEqual({ isP2PBlocked: true, status: 'nonUSD' });
});
});