84 lines
2.1 KiB
TypeScript
84 lines
2.1 KiB
TypeScript
import { presentCashFlow } from './transaction-amount';
|
||
|
||
describe('presentCashFlow', () => {
|
||
it.each([
|
||
{
|
||
amount: 12,
|
||
type: 0,
|
||
context: 'player' as const,
|
||
expected: { direction: 'inflow', amount: 12, sign: '+' },
|
||
},
|
||
{
|
||
amount: -12,
|
||
type: 'payment',
|
||
context: 'player' as const,
|
||
expected: { direction: 'outflow', amount: 12, sign: '−' },
|
||
},
|
||
{
|
||
amount: 8.5,
|
||
type: { id: 1, name: 'credit' },
|
||
context: 'team' as const,
|
||
expected: { direction: 'inflow', amount: 8.5, sign: '+' },
|
||
},
|
||
{
|
||
amount: 8.5,
|
||
type: { id: 14, name: 'expense' },
|
||
context: 'team' as const,
|
||
expected: { direction: 'outflow', amount: 8.5, sign: '−' },
|
||
},
|
||
{
|
||
amount: 7,
|
||
type: 'fine',
|
||
context: 'player' as const,
|
||
expected: { direction: 'neutral', amount: 7, sign: '' },
|
||
},
|
||
{
|
||
amount: 6,
|
||
type: 'credit',
|
||
context: 'player' as const,
|
||
expected: { direction: 'neutral', amount: 6, sign: '' },
|
||
},
|
||
{
|
||
amount: 5,
|
||
type: 'levy',
|
||
context: 'player' as const,
|
||
expected: { direction: 'neutral', amount: 5, sign: '' },
|
||
},
|
||
{
|
||
amount: 4,
|
||
type: 'fee',
|
||
context: 'player' as const,
|
||
expected: { direction: 'neutral', amount: 4, sign: '' },
|
||
},
|
||
{
|
||
amount: 3,
|
||
type: 'payment',
|
||
context: 'team' as const,
|
||
expected: { direction: 'neutral', amount: 3, sign: '' },
|
||
},
|
||
{
|
||
amount: 2,
|
||
type: 'expense',
|
||
context: 'player' as const,
|
||
expected: { direction: 'neutral', amount: 2, sign: '' },
|
||
},
|
||
{
|
||
amount: -7,
|
||
type: 'unknown',
|
||
context: 'player' as const,
|
||
expected: { direction: 'neutral', amount: 7, sign: '' },
|
||
},
|
||
{
|
||
amount: -9,
|
||
type: 'unknown',
|
||
context: 'team' as const,
|
||
expected: { direction: 'neutral', amount: 9, sign: '' },
|
||
},
|
||
])(
|
||
'presents $context $type transactions with their cash-flow direction',
|
||
({ amount, type, context, expected }) => {
|
||
expect(presentCashFlow(amount, type, context)).toEqual(expected);
|
||
},
|
||
);
|
||
});
|