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 <noreply@anthropic.com>
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user