import { categorizeOperationType, mapOperation, mapOperationsPage } from './operation.mapper'; describe('operation.mapper', () => { it.each([ ['OPERATION_TYPE_BUY', 'trade'], ['OPERATION_TYPE_SELL', 'trade'], ['OPERATION_TYPE_DIVIDEND', 'income'], ['OPERATION_TYPE_COUPON', 'income'], ['OPERATION_TYPE_TAX', 'tax'], ['OPERATION_TYPE_DIVIDEND_TAX', 'tax'], ['OPERATION_TYPE_BROKER_FEE', 'fee'], ['OPERATION_TYPE_SERVICE_FEE', 'fee'], ['OPERATION_TYPE_INPUT', 'transfer'], ['OPERATION_TYPE_OUTPUT', 'transfer'], ['OPERATION_TYPE_UNRECOGNIZED_NEW_VALUE', 'other'], ])('maps %s to %s', (type, category) => { expect(categorizeOperationType(type)).toBe(category); }); it('maps operation item with money and quantities', () => { const result = mapOperation( { cursor: 'cursor-1', brokerAccountId: 'acc-1', id: 'op-1', date: { seconds: '1781577000' }, type: 'OPERATION_TYPE_COUPON', description: 'Coupon', state: 'OPERATION_STATE_EXECUTED', ticker: 'SU26238RMFS5', classCode: 'TQOB', payment: { currency: 'rub', units: '100', nano: 0 }, commission: { currency: 'rub', units: '0', nano: 0 }, quantity: '5', quantityDone: '5', }, 'acc-1', ); expect(result).toMatchObject({ cursor: 'cursor-1', accountId: 'acc-1', id: 'op-1', category: 'income', ticker: 'SU26238RMFS5', quantity: 5, quantityDone: 5, payment: { currency: 'RUB', value: 100 }, }); }); it('maps operations page cursor metadata', () => { const page = mapOperationsPage('acc-1', { hasNext: true, nextCursor: 'next', items: [{ cursor: 'cursor-1', type: 'OPERATION_TYPE_BUY' }], }); expect(page.accountId).toBe('acc-1'); expect(page.hasNext).toBe(true); expect(page.nextCursor).toBe('next'); expect(page.items).toHaveLength(1); }); });