""" tests/test_pdf_service.py — build_pdf() is pure and offline (no network, no mocking needed), so this exercises the real thing. """ from services.pdf_service import build_pdf def test_build_pdf_returns_valid_pdf_bytes(): result = build_pdf( { "title": "Your Results", "summary_text": "You could save 6 hours/week.", "results": [{"label": "Hours saved / week", "value": "6"}], "basis_footnote": "Estimates based on inputs provided.", } ) assert result[:5] == b"%PDF-" def test_build_pdf_handles_missing_optional_fields(): result = build_pdf({"title": "Your Results"}) assert result[:5] == b"%PDF-" def test_build_pdf_sanitizes_unicode_punctuation(): # A real "email me a copy" request crashed generation outright on an # em dash before _sanitize_text existed (see pdf_service.py's own # comment) — this is the regression test for that. result = build_pdf( { "title": "Your Results", "summary_text": "Savings — up to 20% — guaranteed.", "proactive_question": "What about edge cases?", "proactive_answer": "We've got you covered — see below.", } ) assert result[:5] == b"%PDF-"