import { mapBrokerageOperation, operationCategory, } from './brokerage-operation.mapper'; describe('mapBrokerageOperation', () => { it.each([ ['OPERATION_TYPE_COUPON', 'income'], ['OPERATION_TYPE_DIVIDEND', 'income'], ['OPERATION_TYPE_TAX', 'tax'], ['OPERATION_TYPE_BROKER_FEE', 'fee'], ['NEW_TYPE', 'other'], ])('maps %s to %s', (type, category) => { expect(operationCategory(type)).toBe(category); }); it('keeps a trade and its commission in one exact-money entry', () => { expect( mapBrokerageOperation({ id: 'trade', date: { seconds: '1' }, type: 'OPERATION_TYPE_BUY', payment: { currency: 'rub', units: '-1', nano: '-500000000' }, commission: { currency: 'RUB', nano: '-5000000' }, }), ).toMatchObject({ id: 'trade', category: 'trade', payment: { currency: 'RUB', value: '-1.5' }, commission: { currency: 'RUB', value: '-0.005' }, }); }); it('does not invent payment for an instrument-only movement', () => { expect( mapBrokerageOperation({ id: 'transfer', date: { seconds: '1' }, type: 'OPERATION_TYPE_INPUT_SECURITIES', quantity: '3', }), ).toMatchObject({ category: 'transfer', quantity: '3', payment: null, }); }); });