From ccf4d01a34215fc32e7a1545afcf265e665c5ef8 Mon Sep 17 00:00:00 2001 From: Andrew Bryant Date: Sat, 26 Sep 2026 15:50:24 -0400 Subject: [PATCH] tests: add end-to-end PDF generation check Exercises the chromium/snappdf pipeline via POST /api/v1/preview with no entity, which falls back to PdfMock's self-contained mock PDF - verified this needs no client/invoice test data, since a fresh account has neither. Asserts the response starts with the %PDF magic bytes. This was previously the biggest untested path in the module: an actual binary runtime dependency (chromium) rather than just config, and the kind of thing that silently breaks in a minimal NixOS closure. Co-Authored-By: Claude Sonnet 5 --- CLAUDE.md | 9 ++++++--- tests/nixos-test.nix | 11 +++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index 3f52f58..bf20884 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -48,9 +48,12 @@ This project uses `just` (see `justfile`) and Nix directly. against each node: waits for mysql/redis/phpfpm/queue-worker/proxy to be active, checks the `invoiceninja-data-setup` marker files (`.initial-migration`, `.db-seeded`, `.admin-created`) to confirm the one-time setup actually completed (not just that the oneshot unit exited), curls `/` for the app shell, exercises - the `invoiceninja-manage` wrapper, and logs in via `/api/v1/login` using the test admin credentials as an - end-to-end check that migrations/seeding/account creation all worked. This is the only automated test in the - repo — there is no separate unit-test suite. + the `invoiceninja-manage` wrapper, logs in via `/api/v1/login` using the test admin credentials as an + end-to-end check that migrations/seeding/account creation all worked, checks the full language list is + available (see the `cache:forget languages` note above), and exercises PDF generation end-to-end (POSTs to + `/api/v1/preview` with no entity, which falls back to a self-contained mock PDF built via the same + chromium/snappdf pipeline real invoices use, and checks for the `%PDF` magic bytes — no client/invoice setup + needed). This is the only automated test in the repo — there is no separate unit-test suite. ## Architecture diff --git a/tests/nixos-test.nix b/tests/nixos-test.nix index bcb81e5..2beec25 100644 --- a/tests/nixos-test.nix +++ b/tests/nixos-test.nix @@ -80,6 +80,17 @@ pkgs.testers.nixosTest { language_count = len(json.loads(statics)["languages"]) assert language_count > 40, f"expected ~45 languages, got {language_count}" + with subtest("PDF generation works (chromium/snappdf)"): + # /api/v1/preview with no entity falls back to a self-contained mock PDF (no invoice/client + # setup needed), exercising the same chromium/snappdf pipeline real invoice PDFs use. + machine.succeed( + "curl -sf -X POST http://localhost/api/v1/preview " + + f"-H 'X-API-TOKEN: {token}' -H 'Content-Type: application/json' " + + "-d '{}' -o /tmp/preview.pdf" + ) + magic_bytes = machine.succeed("head -c 4 /tmp/preview.pdf") + assert magic_bytes == "%PDF", f"expected a PDF, got: {magic_bytes!r}" + nginx.start() caddy.start()