forked from binary-com/deriv-app
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Shayan/feq116/add test for exchange rates hooks (binary-com#8491)
* feat: adding new tests [WIP] * fix: updated exchange_store provider for test files[co-authored by farzin-deriv] * feat: new tests added [WIP] * feat: useTotalCurrency's test added * feat: test for useGetCfdAccounts added * fix: adding remaining tests [WIP] * feat: new tests added * feat: new test added * fix: fixing failed tests [WIP] * feat: all tsts added * Update packages/hooks/src/__tests__/usePlatformDemoAccount.spec.tsx Co-authored-by: Farzin Mirzaie <72082844+farzin-deriv@users.noreply.github.com> * Update packages/hooks/src/__tests__/usePlatformAccounts.spec.tsx Co-authored-by: Farzin Mirzaie <72082844+farzin-deriv@users.noreply.github.com> * Update packages/hooks/src/__tests__/usePlatformAccounts.spec.tsx Co-authored-by: Farzin Mirzaie <72082844+farzin-deriv@users.noreply.github.com> * Update packages/hooks/src/__tests__/useTotalAssetCurrency.spec.tsx Co-authored-by: Farzin Mirzaie <72082844+farzin-deriv@users.noreply.github.com> * Update packages/hooks/src/__tests__/useCFDAccounts.spec.tsx Co-authored-by: Farzin Mirzaie <72082844+farzin-deriv@users.noreply.github.com> * Update packages/hooks/src/__tests__/useCFDAccounts.spec.tsx Co-authored-by: Farzin Mirzaie <72082844+farzin-deriv@users.noreply.github.com> * Update packages/hooks/src/__tests__/useCFDAccounts.spec.tsx Co-authored-by: Farzin Mirzaie <72082844+farzin-deriv@users.noreply.github.com> * Update packages/hooks/src/__tests__/useCFDAccounts.spec.tsx Co-authored-by: Farzin Mirzaie <72082844+farzin-deriv@users.noreply.github.com> * fix: resolved pr comments * Update packages/hooks/src/__tests__/useTotalAssetCurrency.spec.tsx Co-authored-by: Farzin Mirzaie <72082844+farzin-deriv@users.noreply.github.com> * Update packages/hooks/src/__tests__/useTotalAssetCurrency.spec.tsx Co-authored-by: Farzin Mirzaie <72082844+farzin-deriv@users.noreply.github.com> * Update packages/hooks/src/__tests__/useTotalAssetCurrency.spec.tsx Co-authored-by: Farzin Mirzaie <72082844+farzin-deriv@users.noreply.github.com> * Update packages/hooks/src/__tests__/useTotalAssetCurrency.spec.tsx Co-authored-by: Farzin Mirzaie <72082844+farzin-deriv@users.noreply.github.com> * Update packages/hooks/src/__tests__/useTotalAssetCurrency.spec.tsx Co-authored-by: Farzin Mirzaie <72082844+farzin-deriv@users.noreply.github.com> * Update packages/hooks/src/__tests__/useTotalAssetCurrency.spec.tsx Co-authored-by: Farzin Mirzaie <72082844+farzin-deriv@users.noreply.github.com> * Update packages/hooks/src/__tests__/useTotalAssetCurrency.spec.tsx Co-authored-by: Farzin Mirzaie <72082844+farzin-deriv@users.noreply.github.com> * Update packages/hooks/src/__tests__/useTotalAssetCurrency.spec.tsx Co-authored-by: Farzin Mirzaie <72082844+farzin-deriv@users.noreply.github.com> * Update packages/hooks/src/__tests__/useCFDRealAccounts.spec.tsx Co-authored-by: Farzin Mirzaie <72082844+farzin-deriv@users.noreply.github.com> * Update packages/hooks/src/__tests__/useTotalAccountBalance.spec.tsx Co-authored-by: Farzin Mirzaie <72082844+farzin-deriv@users.noreply.github.com> * Update packages/hooks/src/__tests__/useCFDAllAccounts.spec.tsx Co-authored-by: Farzin Mirzaie <72082844+farzin-deriv@users.noreply.github.com> * Update packages/hooks/src/__tests__/useCFDAllAccounts.spec.tsx Co-authored-by: Farzin Mirzaie <72082844+farzin-deriv@users.noreply.github.com> * Update packages/hooks/src/__tests__/useCFDAllAccounts.spec.tsx Co-authored-by: Farzin Mirzaie <72082844+farzin-deriv@users.noreply.github.com> * Update packages/hooks/src/__tests__/useCFDDemoAccounts.spec.tsx Co-authored-by: Farzin Mirzaie <72082844+farzin-deriv@users.noreply.github.com> * Update packages/hooks/src/__tests__/useCFDDemoAccounts.spec.tsx Co-authored-by: Farzin Mirzaie <72082844+farzin-deriv@users.noreply.github.com> * Update packages/hooks/src/__tests__/useCFDDemoAccounts.spec.tsx Co-authored-by: Farzin Mirzaie <72082844+farzin-deriv@users.noreply.github.com> * Update packages/hooks/src/__tests__/useCFDRealAccounts.spec.tsx Co-authored-by: Farzin Mirzaie <72082844+farzin-deriv@users.noreply.github.com> * Update packages/hooks/src/__tests__/useCFDRealAccounts.spec.tsx Co-authored-by: Farzin Mirzaie <72082844+farzin-deriv@users.noreply.github.com> * fix: fixed ts error in useTotalAccountBalance hook * fix: resolved pr comment * chore: renamed hook --------- Co-authored-by: Farzin Mirzaie <72082844+farzin-deriv@users.noreply.github.com>
- Loading branch information
1 parent
dd81757
commit 7d9921d
Showing
17 changed files
with
949 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import * as React from 'react'; | ||
import { mockStore, StoreProvider } from '@deriv/stores'; | ||
import { renderHook } from '@testing-library/react-hooks'; | ||
import useCFDAccounts from '../useCFDAccounts'; | ||
|
||
describe('useCFDAccounts', () => { | ||
test('should return empty array when client has no CFD accounts', async () => { | ||
const mock = mockStore({}); | ||
|
||
const wrapper = ({ children }: { children: JSX.Element }) => ( | ||
<StoreProvider store={mock}>{children}</StoreProvider> | ||
); | ||
const { result } = renderHook(() => useCFDAccounts(), { 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 () => { | ||
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(() => useCFDAccounts(), { 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 () => { | ||
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(() => useCFDAccounts(), { 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 () => { | ||
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(() => useCFDAccounts(), { wrapper }); | ||
|
||
expect(result.current.all.length).toBe(2); | ||
expect(result.current.demo.length).toBe(1); | ||
expect(result.current.real.length).toBe(1); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
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({}); | ||
|
||
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 () => { | ||
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 () => { | ||
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); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 () => { | ||
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 () => { | ||
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 () => { | ||
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); | ||
}); | ||
}); |
Oops, something went wrong.