|
| 1 | +import { Coins, CryptoId, Platforms } from 'invity-api'; |
| 2 | + |
| 3 | +import coins from '../../__fixtures__/coins.json'; |
| 4 | +import platforms from '../../__fixtures__/platforms.json'; |
| 5 | +import { initialState } from '../../reducers/tradingReducer'; |
| 6 | +import { TradingPaymentMethodListProps } from '../../types'; |
| 7 | +import { |
| 8 | + TradingRootState, |
| 9 | + selectCoinInfoByCryptoId, |
| 10 | + selectCoinSymbolByCryptoId, |
| 11 | + selectNativeCoinSymbolByCryptoId, |
| 12 | + selectPlatformByCryptoId, |
| 13 | + selectSymbolAndContractAddressByCryptoId, |
| 14 | + selectTradingBuyQuotesRequest, |
| 15 | + selectTradingBuySelectedQuote, |
| 16 | +} from '../tradingSelectors'; |
| 17 | + |
| 18 | +describe('tradingSelectors', () => { |
| 19 | + const state = { |
| 20 | + wallet: { |
| 21 | + tradingNew: { |
| 22 | + ...initialState, |
| 23 | + buy: { |
| 24 | + ...initialState.buy, |
| 25 | + quotesRequest: { |
| 26 | + wantCrypto: true, |
| 27 | + fiatCurrency: 'fiatCurrency', |
| 28 | + paymentMethod: 'eps', |
| 29 | + receiveCurrency: 'bitcoin', |
| 30 | + }, |
| 31 | + selectedQuote: { |
| 32 | + paymentMethod: 'eps', |
| 33 | + }, |
| 34 | + }, |
| 35 | + info: { |
| 36 | + paymentMethods: [] as TradingPaymentMethodListProps[], |
| 37 | + coins: coins as Coins, |
| 38 | + platforms: platforms as Platforms, |
| 39 | + }, |
| 40 | + }, |
| 41 | + }, |
| 42 | + } as TradingRootState; |
| 43 | + |
| 44 | + it('selectTradingBuyQuotesRequest should return correct data', () => { |
| 45 | + expect(selectTradingBuyQuotesRequest(state)).toBe( |
| 46 | + state.wallet.tradingNew.buy.quotesRequest, |
| 47 | + ); |
| 48 | + }); |
| 49 | + |
| 50 | + it('selectTradingBuySelectedQuote should return correct data', () => { |
| 51 | + expect(selectTradingBuySelectedQuote(state)).toBe( |
| 52 | + state.wallet.tradingNew.buy.selectedQuote, |
| 53 | + ); |
| 54 | + }); |
| 55 | + |
| 56 | + it('selectCoinInfoByCryptoId should return coin data', () => { |
| 57 | + expect(selectCoinInfoByCryptoId(state, 'bitcoin' as CryptoId)).toEqual({ |
| 58 | + symbol: 'btc', |
| 59 | + name: 'Bitcoin', |
| 60 | + coingeckoId: 'bitcoin', |
| 61 | + services: { |
| 62 | + buy: true, |
| 63 | + sell: true, |
| 64 | + exchange: true, |
| 65 | + }, |
| 66 | + }); |
| 67 | + }); |
| 68 | + |
| 69 | + it('selectCoinSymbolByCryptoId should return coin symbol', () => { |
| 70 | + expect(selectCoinSymbolByCryptoId(state, 'bitcoin' as CryptoId)).toBe('BTC'); |
| 71 | + }); |
| 72 | + |
| 73 | + it('selectPlatformByCryptoId should return platform data', () => { |
| 74 | + expect(selectPlatformByCryptoId(state, 'ethereum' as CryptoId)).toEqual({ |
| 75 | + id: 'ethereum', |
| 76 | + name: 'Ethereum', |
| 77 | + nativeCoinSymbol: 'eth', |
| 78 | + }); |
| 79 | + }); |
| 80 | + |
| 81 | + it.each([ |
| 82 | + ['bitcoin', 'btc'], |
| 83 | + ['ethereum', 'eth'], |
| 84 | + ['ethereum--0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48', 'eth'], |
| 85 | + ] as [CryptoId, string][])( |
| 86 | + 'selectNativeCoinSymbolByCryptoId should return native coin symbol for cryptoId [%s]', |
| 87 | + (cryptoId, expected) => { |
| 88 | + expect(selectNativeCoinSymbolByCryptoId(state, cryptoId)).toBe(expected); |
| 89 | + }, |
| 90 | + ); |
| 91 | + |
| 92 | + describe('selectSymbolAndContractAddressByCryptoId', () => { |
| 93 | + it.each([ |
| 94 | + ['bitcoin', { coinSymbol: 'btc', contractAddress: undefined }], |
| 95 | + [ |
| 96 | + 'ethereum--0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48', |
| 97 | + { |
| 98 | + coinSymbol: 'usdc', |
| 99 | + contractAddress: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48', |
| 100 | + }, |
| 101 | + ], |
| 102 | + ] as [CryptoId, { coinSymbol: string; contractAddress: string }][])( |
| 103 | + 'should return correct data for cryptoId [%s]', |
| 104 | + (cryptoId, expectedResult) => { |
| 105 | + expect(selectSymbolAndContractAddressByCryptoId(state, cryptoId)).toEqual( |
| 106 | + expectedResult, |
| 107 | + ); |
| 108 | + }, |
| 109 | + ); |
| 110 | + |
| 111 | + it('should be stable', () => { |
| 112 | + expect(selectSymbolAndContractAddressByCryptoId(state, 'bitcoin' as CryptoId)).toBe( |
| 113 | + selectSymbolAndContractAddressByCryptoId(state, 'bitcoin' as CryptoId), |
| 114 | + ); |
| 115 | + }); |
| 116 | + }); |
| 117 | +}); |
0 commit comments