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

Shayan/feq116/add test for exchange rates hooks #8491

Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
6b0bfd1
feat: adding new tests [WIP]
Apr 28, 2023
a5d5cee
fix: updated exchange_store provider for test files[co-authored by fa…
Apr 28, 2023
5be1c6f
Merge branch 'shayan/feq116/add_test_for_exchange_rates_hooks' of git…
Apr 28, 2023
a76a9d4
feat: new tests added [WIP]
Apr 30, 2023
bcebab8
feat: useTotalCurrency's test added
May 1, 2023
a23fe81
feat: test for useGetCfdAccounts added
May 1, 2023
4a10f43
fix: adding remaining tests [WIP]
May 1, 2023
1d1e3ae
Merge branch 'master' of github.com:binary-com/deriv-app into shayan/…
May 2, 2023
310fcbc
Merge branch 'master' of github.com:binary-com/deriv-app into shayan/…
May 7, 2023
a03c915
feat: new tests added
May 7, 2023
83f2e71
feat: new test added
May 7, 2023
cc55e68
fix: fixing failed tests [WIP]
May 7, 2023
0655e75
feat: all tsts added
May 7, 2023
58b8a65
Update packages/hooks/src/__tests__/usePlatformDemoAccount.spec.tsx
shayan-deriv May 8, 2023
b21bb6a
Update packages/hooks/src/__tests__/usePlatformAccounts.spec.tsx
shayan-deriv May 8, 2023
f3fb37e
Update packages/hooks/src/__tests__/usePlatformAccounts.spec.tsx
shayan-deriv May 8, 2023
804a20b
Update packages/hooks/src/__tests__/useTotalAssetCurrency.spec.tsx
shayan-deriv May 8, 2023
19c30ed
Update packages/hooks/src/__tests__/useCFDAccounts.spec.tsx
shayan-deriv May 8, 2023
07fdd7a
Update packages/hooks/src/__tests__/useCFDAccounts.spec.tsx
shayan-deriv May 8, 2023
2837561
Update packages/hooks/src/__tests__/useCFDAccounts.spec.tsx
shayan-deriv May 8, 2023
9c094a5
Update packages/hooks/src/__tests__/useCFDAccounts.spec.tsx
shayan-deriv May 8, 2023
e6dea3f
fix: resolved pr comments
May 8, 2023
fc485b7
Merge branch 'master' of github.com:binary-com/deriv-app into shayan/…
May 8, 2023
834cbd2
Update packages/hooks/src/__tests__/useTotalAssetCurrency.spec.tsx
shayan-deriv May 8, 2023
4dd73d5
Update packages/hooks/src/__tests__/useTotalAssetCurrency.spec.tsx
shayan-deriv May 8, 2023
5416f1f
Update packages/hooks/src/__tests__/useTotalAssetCurrency.spec.tsx
shayan-deriv May 8, 2023
fe51f34
Update packages/hooks/src/__tests__/useTotalAssetCurrency.spec.tsx
shayan-deriv May 8, 2023
c5bdd0c
Update packages/hooks/src/__tests__/useTotalAssetCurrency.spec.tsx
shayan-deriv May 8, 2023
0030a63
Update packages/hooks/src/__tests__/useTotalAssetCurrency.spec.tsx
shayan-deriv May 8, 2023
4e421d2
Update packages/hooks/src/__tests__/useTotalAssetCurrency.spec.tsx
shayan-deriv May 8, 2023
52aeae5
Update packages/hooks/src/__tests__/useTotalAssetCurrency.spec.tsx
shayan-deriv May 8, 2023
5cf0016
Update packages/hooks/src/__tests__/useCFDRealAccounts.spec.tsx
shayan-deriv May 8, 2023
b99b328
Update packages/hooks/src/__tests__/useTotalAccountBalance.spec.tsx
shayan-deriv May 8, 2023
0a1eaae
Update packages/hooks/src/__tests__/useCFDAllAccounts.spec.tsx
shayan-deriv May 8, 2023
8fe111e
Update packages/hooks/src/__tests__/useCFDAllAccounts.spec.tsx
shayan-deriv May 8, 2023
eb1b1f6
Update packages/hooks/src/__tests__/useCFDAllAccounts.spec.tsx
shayan-deriv May 8, 2023
1df7e8a
Update packages/hooks/src/__tests__/useCFDDemoAccounts.spec.tsx
shayan-deriv May 8, 2023
e230aa0
Update packages/hooks/src/__tests__/useCFDDemoAccounts.spec.tsx
shayan-deriv May 8, 2023
65250c0
Update packages/hooks/src/__tests__/useCFDDemoAccounts.spec.tsx
shayan-deriv May 8, 2023
93c7e44
Update packages/hooks/src/__tests__/useCFDRealAccounts.spec.tsx
shayan-deriv May 8, 2023
f2d01ce
Update packages/hooks/src/__tests__/useCFDRealAccounts.spec.tsx
shayan-deriv May 8, 2023
ab6b61a
Merge branch 'master' into shayan/feq116/add_test_for_exchange_rates_…
shayan-deriv May 8, 2023
7721872
fix: fixed ts error in useTotalAccountBalance hook
May 8, 2023
64c13c1
fix: resolved pr comment
May 8, 2023
fb52581
chore: renamed hook
May 8, 2023
1254f64
Merge branch 'master' into shayan/feq116/add_test_for_exchange_rates_…
shayan-deriv May 10, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 97 additions & 0 deletions packages/hooks/src/__tests__/useCFDAccounts.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import * as React from 'react';
import { mockStore, StoreProvider } from '@deriv/stores';
import { renderHook } from '@testing-library/react-hooks';
import useGetCfdAccounts from '../useCfdAccounts';

describe('useGetCfdAccounts', () => {
test('should return empty array when client has no cfd accounts', async () => {
const mock = mockStore({
client: {},
});
shayan-deriv marked this conversation as resolved.
Show resolved Hide resolved

const wrapper = ({ children }: { children: JSX.Element }) => (
<StoreProvider store={mock}>{children}</StoreProvider>
);
const { result } = renderHook(() => useGetCfdAccounts(), { wrapper });

expect(result.current.all.length).toBe(0);
expect(result.current.demo.length).toBe(0);
expect(result.current.real.length).toBe(0);
});

test('should return proper data when client only has cfd demo accounts', async () => {
shayan-deriv marked this conversation as resolved.
Show resolved Hide resolved
const mock = mockStore({
client: {
mt5_login_list: [
{
account_type: 'demo',
balance: 1000,
currency: 'USD',
},
],
},
});

const wrapper = ({ children }: { children: JSX.Element }) => (
<StoreProvider store={mock}>{children}</StoreProvider>
);
const { result } = renderHook(() => useGetCfdAccounts(), { wrapper });

expect(result.current.all.length).toBe(1);
expect(result.current.demo.length).toBe(1);
expect(result.current.real.length).toBe(0);
});

test('should return proper data when client only has cfd real accounts', async () => {
shayan-deriv marked this conversation as resolved.
Show resolved Hide resolved
const mock = mockStore({
client: {
mt5_login_list: [
{
account_type: 'real',
balance: 1000,
currency: 'USD',
},
],
},
});

const wrapper = ({ children }: { children: JSX.Element }) => (
<StoreProvider store={mock}>{children}</StoreProvider>
);
const { result } = renderHook(() => useGetCfdAccounts(), { wrapper });

expect(result.current.all.length).toBe(1);
expect(result.current.demo.length).toBe(0);
expect(result.current.real.length).toBe(1);
});

test('should return proper data when client only has both cfd real and demo accounts', async () => {
shayan-deriv marked this conversation as resolved.
Show resolved Hide resolved
const mock = mockStore({
client: {
mt5_login_list: [
{
account_type: 'real',
balance: 1000,
currency: 'USD',
},
],
dxtrade_accounts_list: [
{
account_type: 'demo',
balance: 1000,
currency: 'USD',
},
],
},
});

const wrapper = ({ children }: { children: JSX.Element }) => (
<StoreProvider store={mock}>{children}</StoreProvider>
);
const { result } = renderHook(() => useGetCfdAccounts(), { wrapper });

expect(result.current.all.length).toBe(2);
expect(result.current.demo.length).toBe(1);
expect(result.current.real.length).toBe(1);
});
});
89 changes: 89 additions & 0 deletions packages/hooks/src/__tests__/useCFDAllAccounts.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import * as React from 'react';
import { mockStore, StoreProvider } from '@deriv/stores';
import { renderHook } from '@testing-library/react-hooks';
import useCFDAllAccounts from '../useCFDAllAccounts';

describe('useCFDAllAccounts', () => {
test('should return empty array when client has no cfd accounts', async () => {
const mock = mockStore({
client: {},
});
shayan-deriv marked this conversation as resolved.
Show resolved Hide resolved

const wrapper = ({ children }: { children: JSX.Element }) => (
<StoreProvider store={mock}>{children}</StoreProvider>
);
const { result } = renderHook(() => useCFDAllAccounts(), { wrapper });

expect(result.current.length).toBe(0);
});

test('should return proper data when client has mt5 accounts', async () => {
shayan-deriv marked this conversation as resolved.
Show resolved Hide resolved
const mock = mockStore({
client: {
mt5_login_list: [
{
account_type: 'real',
balance: 1000,
currency: 'USD',
},
],
},
});

const wrapper = ({ children }: { children: JSX.Element }) => (
<StoreProvider store={mock}>{children}</StoreProvider>
);
const { result } = renderHook(() => useCFDAllAccounts(), { wrapper });

expect(result.current.length).toBe(1);
});

test('should return proper data when client has dxtrade accounts', async () => {
const mock = mockStore({
client: {
dxtrade_accounts_list: [
{
account_type: 'real',
balance: 1000,
currency: 'USD',
},
],
},
});

const wrapper = ({ children }: { children: JSX.Element }) => (
<StoreProvider store={mock}>{children}</StoreProvider>
);
const { result } = renderHook(() => useCFDAllAccounts(), { wrapper });

expect(result.current.length).toBe(1);
});

test('should return proper data when client has both mt5 and dxtrade accounts', async () => {
shayan-deriv marked this conversation as resolved.
Show resolved Hide resolved
const mock = mockStore({
client: {
mt5_login_list: [
{
account_type: 'real',
balance: 1000,
currency: 'USD',
},
],
dxtrade_accounts_list: [
{
account_type: 'real',
balance: 1000,
currency: 'USD',
},
],
},
});

const wrapper = ({ children }: { children: JSX.Element }) => (
<StoreProvider store={mock}>{children}</StoreProvider>
);
const { result } = renderHook(() => useCFDAllAccounts(), { wrapper });

expect(result.current.length).toBe(2);
});
});
68 changes: 68 additions & 0 deletions packages/hooks/src/__tests__/useCFDDemoAccounts.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import * as React from 'react';
import { mockStore, StoreProvider } from '@deriv/stores';
import { renderHook } from '@testing-library/react-hooks';
import useCFDDemoAccounts from '../useCFDDemoAccounts';

describe('useCFDDemoAccounts', () => {
test('should return empty array when user has no cfd accounts', async () => {
shayan-deriv marked this conversation as resolved.
Show resolved Hide resolved
const mock = mockStore({});

const wrapper = ({ children }: { children: JSX.Element }) => (
<StoreProvider store={mock}>{children}</StoreProvider>
);
const { result } = renderHook(() => useCFDDemoAccounts(), { wrapper });

expect(result.current?.length).toBe(0);
});

test('should return empty array when user has no cfd demo accounts', async () => {
shayan-deriv marked this conversation as resolved.
Show resolved Hide resolved
const mock = mockStore({
client: {
mt5_login_list: [
{
account_type: 'real',
},
],
dxtrade_accounts_list: [
{
account_type: 'real',
},
],
},
});

const wrapper = ({ children }: { children: JSX.Element }) => (
<StoreProvider store={mock}>{children}</StoreProvider>
);
const { result } = renderHook(() => useCFDDemoAccounts(), { wrapper });

expect(result.current?.length).toBe(0);
});

test('should return proper data when user has cfd demo accounts', async () => {
shayan-deriv marked this conversation as resolved.
Show resolved Hide resolved
const mock = mockStore({
client: {
mt5_login_list: [
{
account_type: 'demo',
},
],
dxtrade_accounts_list: [
{
account_type: 'real',
},
{
account_type: 'demo',
},
],
},
});

const wrapper = ({ children }: { children: JSX.Element }) => (
<StoreProvider store={mock}>{children}</StoreProvider>
);
const { result } = renderHook(() => useCFDDemoAccounts(), { wrapper });

expect(result.current?.length).toBe(2);
});
});
68 changes: 68 additions & 0 deletions packages/hooks/src/__tests__/useCFDRealAccounts.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import * as React from 'react';
import { mockStore, StoreProvider } from '@deriv/stores';
import { renderHook } from '@testing-library/react-hooks';
import useCFDRealAccounts from '../useCFDRealAccounts';

describe('useCFDRealAccounts', () => {
test('should return empty array when user has no cfd accounts', async () => {
shayan-deriv marked this conversation as resolved.
Show resolved Hide resolved
const mock = mockStore({});

const wrapper = ({ children }: { children: JSX.Element }) => (
<StoreProvider store={mock}>{children}</StoreProvider>
);
const { result } = renderHook(() => useCFDRealAccounts(), { wrapper });

expect(result.current?.length).toBe(0);
});

test('should return empty array when user has no cfd real accounts', async () => {
shayan-deriv marked this conversation as resolved.
Show resolved Hide resolved
const mock = mockStore({
client: {
mt5_login_list: [
{
account_type: 'demo',
},
],
dxtrade_accounts_list: [
{
account_type: 'demo',
},
],
},
});

const wrapper = ({ children }: { children: JSX.Element }) => (
<StoreProvider store={mock}>{children}</StoreProvider>
);
const { result } = renderHook(() => useCFDRealAccounts(), { wrapper });

expect(result.current?.length).toBe(0);
});

test('should return proper data when user has cfd real accounts', async () => {
shayan-deriv marked this conversation as resolved.
Show resolved Hide resolved
const mock = mockStore({
client: {
mt5_login_list: [
{
account_type: 'real',
},
],
dxtrade_accounts_list: [
{
account_type: 'real',
},
{
account_type: 'demo',
},
],
},
});

const wrapper = ({ children }: { children: JSX.Element }) => (
<StoreProvider store={mock}>{children}</StoreProvider>
);
const { result } = renderHook(() => useCFDRealAccounts(), { wrapper });

expect(result.current?.length).toBe(2);
});
});
48 changes: 48 additions & 0 deletions packages/hooks/src/__tests__/useExchangeRate.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import * as React from 'react';
import { mockStore, StoreProvider } from '@deriv/stores';
import { renderHook } from '@testing-library/react-hooks';
import useExchangeRate from '../useExchangeRate';

describe('useExchangeRate', () => {
test('should return 1 if currency is not found', async () => {
const mock = mockStore({
exchange_rates: {
data: {
base_currency: 'USD',
rates: {
EUR: 1.3,
GBP: 1.4,
ETH: 0.0001,
},
},
},
});

const wrapper = ({ children }: { children: JSX.Element }) => (
<StoreProvider store={mock}>{children}</StoreProvider>
);
const { result } = renderHook(() => useExchangeRate(), { wrapper });
const rate = result.current.getRate('JPY');
expect(rate).toBe(1);
});

test('should return correct rate for the given currency other than USD', async () => {
const mock = mockStore({
exchange_rates: {
data: {
rates: {
EUR: 1.3,
GBP: 1.5,
},
},
},
});

const wrapper = ({ children }: { children: JSX.Element }) => (
<StoreProvider store={mock}>{children}</StoreProvider>
);
const { result } = renderHook(() => useExchangeRate(), { wrapper });
const rate = result.current.getRate('EUR');
expect(rate).toBe(1.3);
});
});
Loading