feat: add buildPdf for cashbox export

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Bastian Wagner
2026-08-03 21:20:57 +02:00
parent 0b408f7d73
commit f8857f71e1
2 changed files with 58 additions and 1 deletions

View File

@@ -1,4 +1,4 @@
import { buildCsv, buildRows } from './cashbox-export.utils';
import { buildCsv, buildPdf, buildRows } from './cashbox-export.utils';
describe('buildRows', () => {
const team = (overrides: Partial<{ transactions: any[]; players: any[] }> = {}) => ({
@@ -167,3 +167,26 @@ describe('buildCsv', () => {
);
});
});
describe('buildPdf', () => {
it('produces a non-empty valid PDF buffer', async () => {
const buffer = await buildPdf(
{ name: 'Team A' } as any,
[
{ date: '2026-08-05T00:00:00.000Z', type: 'payment', who: 'Alex Muster', note: 'Bar bezahlt', amount: 10, runningTotal: 10 },
],
'2026-08-01',
'2026-08-31',
);
expect(Buffer.isBuffer(buffer)).toBe(true);
expect(buffer.length).toBeGreaterThan(100);
expect(buffer.subarray(0, 5).toString('utf-8')).toBe('%PDF-');
});
it('still produces a valid PDF when there are no rows', async () => {
const buffer = await buildPdf({ name: 'Team A' } as any, [], '2026-08-01', '2026-08-31');
expect(buffer.subarray(0, 5).toString('utf-8')).toBe('%PDF-');
});
});