fix: make cash flow amounts fully accessible

This commit is contained in:
Bastian Wagner
2026-08-02 09:22:39 +02:00
parent f2e6704943
commit 367533f1f5
6 changed files with 73 additions and 35 deletions

View File

@@ -1,4 +1,4 @@
import { presentCashFlow, signedTransactionAmount } from './transaction-amount';
import { presentCashFlow } from './transaction-amount';
describe('presentCashFlow', () => {
it.each([
@@ -32,12 +32,48 @@ describe('presentCashFlow', () => {
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 }) => {
@@ -45,15 +81,3 @@ describe('presentCashFlow', () => {
},
);
});
describe('signedTransactionAmount', () => {
it('shows debit transaction types as negative amounts', () => {
expect(signedTransactionAmount(12, 'fine')).toBe(-12);
expect(signedTransactionAmount(12, { id: 14, name: 'expense' })).toBe(-12);
});
it('keeps credits and negative reversal amounts unchanged', () => {
expect(signedTransactionAmount(12, 'credit')).toBe(12);
expect(signedTransactionAmount(-12, { id: 1, name: 'credit' })).toBe(-12);
});
});