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:
2026-09-26 15:50:24 -04:00
co-authored by Claude Sonnet 5
parent fd055f0cf9
commit ccf4d01a34
2 changed files with 17 additions and 3 deletions
+11
View File
@@ -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()