|
| 1 | +import PortfolioStore from '../portfolio-store.js'; |
| 2 | +import { configure } from 'mobx'; |
| 3 | + |
| 4 | +configure({ safeDescriptors: false }); |
| 5 | + |
| 6 | +let mockedPortfolioStore: PortfolioStore; |
| 7 | + |
| 8 | +const symbol = '1HZ100V'; |
| 9 | +const contracts = [ |
| 10 | + { |
| 11 | + app_id: 24075, |
| 12 | + buy_price: 10, |
| 13 | + contract_id: 229749680508, |
| 14 | + contract_type: 'MULTUP', |
| 15 | + currency: 'USD', |
| 16 | + date_start: 1705570990, |
| 17 | + expiry_time: 4859222399, |
| 18 | + longcode: |
| 19 | + "If you select 'Up', your total profit/loss will be the percentage increase in Volatility 100 (1s) Index, multiplied by 100, minus commissions.", |
| 20 | + payout: 0, |
| 21 | + purchase_time: 1705570990, |
| 22 | + shortcode: 'MULTUP_1HZ100V_10.00_10_1705570990_4859222399_0_0.00', |
| 23 | + symbol, |
| 24 | + transaction_id: 458367398868, |
| 25 | + }, |
| 26 | + { |
| 27 | + app_id: 16929, |
| 28 | + buy_price: 10, |
| 29 | + contract_id: 230152813328, |
| 30 | + contract_type: 'MULTDOWN', |
| 31 | + currency: 'USD', |
| 32 | + date_start: 1705921444, |
| 33 | + expiry_time: 4859567999, |
| 34 | + longcode: |
| 35 | + "If you select 'Down', your total profit/loss will be the percentage decrease in AUD/JPY, multiplied by 300, minus commissions.", |
| 36 | + payout: 0, |
| 37 | + purchase_time: 1705921444, |
| 38 | + shortcode: 'MULTDOWN_FRXAUDJPY_10.00_30_1705921444_4859567999_0_0.00', |
| 39 | + symbol, |
| 40 | + transaction_id: 459167693628, |
| 41 | + }, |
| 42 | +]; |
| 43 | + |
| 44 | +beforeEach(() => { |
| 45 | + mockedPortfolioStore = new PortfolioStore({ |
| 46 | + active_symbols: { |
| 47 | + active_symbols: [ |
| 48 | + { |
| 49 | + allow_forward_starting: 1, |
| 50 | + display_name: 'Volatility 100 (1s) Index', |
| 51 | + display_order: 3, |
| 52 | + exchange_is_open: 1, |
| 53 | + is_trading_suspended: 0, |
| 54 | + market: 'synthetic_index', |
| 55 | + market_display_name: 'Derived', |
| 56 | + pip: 0.01, |
| 57 | + subgroup: 'synthetics', |
| 58 | + subgroup_display_name: 'Synthetics', |
| 59 | + submarket: 'random_index', |
| 60 | + submarket_display_name: 'Continuous Indices', |
| 61 | + symbol, |
| 62 | + symbol_type: 'stockindex', |
| 63 | + }, |
| 64 | + ], |
| 65 | + }, |
| 66 | + }); |
| 67 | + mockedPortfolioStore.portfolioHandler({ |
| 68 | + echo_req: { |
| 69 | + portfolio: 1, |
| 70 | + req_id: 8, |
| 71 | + }, |
| 72 | + msg_type: 'portfolio', |
| 73 | + portfolio: { |
| 74 | + contracts, |
| 75 | + }, |
| 76 | + req_id: 8, |
| 77 | + }); |
| 78 | +}); |
| 79 | + |
| 80 | +describe('PortfolioStore', () => { |
| 81 | + it('getPositionById() should return a position by its id, or undefined when id is incorrect or not provided', () => { |
| 82 | + expect(mockedPortfolioStore.getPositionById(230152813328)).toMatchObject({ |
| 83 | + contract_info: contracts[1], |
| 84 | + contract_update: undefined, |
| 85 | + details: contracts[1].longcode, |
| 86 | + display_name: '', |
| 87 | + id: contracts[1].contract_id, |
| 88 | + indicative: 0, |
| 89 | + is_unsupported: false, |
| 90 | + payout: contracts[1].payout, |
| 91 | + purchase: contracts[1].buy_price, |
| 92 | + reference: contracts[1].transaction_id, |
| 93 | + type: contracts[1].contract_type, |
| 94 | + }); |
| 95 | + expect(mockedPortfolioStore.getPositionById('incorrect-id')).toEqual(undefined); |
| 96 | + expect(mockedPortfolioStore.getPositionById(null)).toEqual(undefined); |
| 97 | + expect(mockedPortfolioStore.getPositionById(undefined)).toEqual(undefined); |
| 98 | + }); |
| 99 | +}); |
0 commit comments