feat: add buildCsv for cashbox export
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { buildRows } from './cashbox-export.utils';
|
||||
import { buildCsv, buildRows } from './cashbox-export.utils';
|
||||
|
||||
describe('buildRows', () => {
|
||||
const team = (overrides: Partial<{ transactions: any[]; players: any[] }> = {}) => ({
|
||||
@@ -101,3 +101,36 @@ describe('buildRows', () => {
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('buildCsv', () => {
|
||||
it('renders the header and formatted rows with German decimals', () => {
|
||||
const csv = buildCsv([
|
||||
{ date: '2026-08-05T00:00:00.000Z', type: 'payment', who: 'Alex Muster', note: 'Bar bezahlt', amount: 10, runningTotal: 10 },
|
||||
{ date: '2026-08-10T00:00:00.000Z', type: 'expense', who: 'Teamkasse', note: 'Bälle', amount: -20.5, runningTotal: -10.5 },
|
||||
]);
|
||||
|
||||
expect(csv).toBe(
|
||||
'Datum;Typ;Wer;Notiz;Betrag;Periodensaldo\r\n' +
|
||||
'2026-08-05;Zahlung;Alex Muster;Bar bezahlt;10,00;10,00\r\n' +
|
||||
'2026-08-10;Ausgabe;Teamkasse;Bälle;-20,50;-10,50',
|
||||
);
|
||||
});
|
||||
|
||||
it('quotes notes containing a semicolon and escapes embedded quotes', () => {
|
||||
const csv = buildCsv([
|
||||
{ date: '2026-08-05T00:00:00.000Z', type: 'credit', who: 'Teamkasse', note: 'Spende; "danke"', amount: 5, runningTotal: 5 },
|
||||
]);
|
||||
|
||||
expect(csv).toBe(
|
||||
'Datum;Typ;Wer;Notiz;Betrag;Periodensaldo\r\n' +
|
||||
'2026-08-05;Guthaben;Teamkasse;"Spende; ""danke""";5,00;5,00',
|
||||
);
|
||||
});
|
||||
|
||||
it('shows a placeholder row when there are no bookings', () => {
|
||||
const csv = buildCsv([]);
|
||||
expect(csv).toBe(
|
||||
'Datum;Typ;Wer;Notiz;Betrag;Periodensaldo\r\nKeine Buchungen im gewählten Zeitraum',
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user