From 822279157fc8ed0f0bca6010ec62c5ee6c34faf7 Mon Sep 17 00:00:00 2001 From: Rafael Falk Date: Thu, 12 Dec 2024 15:19:04 +0100 Subject: [PATCH] test(pdf-service): add pdfDownloadLoader tests (#1547) --- .../shared/__test__/pdfDownloadLoader.test.ts | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 app/routes/shared/__test__/pdfDownloadLoader.test.ts diff --git a/app/routes/shared/__test__/pdfDownloadLoader.test.ts b/app/routes/shared/__test__/pdfDownloadLoader.test.ts new file mode 100644 index 000000000..760b770f9 --- /dev/null +++ b/app/routes/shared/__test__/pdfDownloadLoader.test.ts @@ -0,0 +1,55 @@ +// @vitest-environment node +import { PDFDocument } from "pdf-lib"; +import { pdfDownloadLoader } from "../pdfDownloadLoader"; + +vi.mock("~/services/flow/pruner", () => ({ + pruneIrrelevantData: vi + .fn() + .mockResolvedValue({ vorname: "Zoe", nachname: "Müller" }), +})); + +vi.mock("~/services/cms/index.server.ts", () => ({ + fetchTranslations: vi.fn().mockResolvedValue({}), +})); + +describe("pdfDownloadLoader", () => { + it("generates correct PDF for Beratungshilfe", async () => { + const response = await pdfDownloadLoader({ + request: new Request( + "https://mock-url.de/beratungshilfe/antrag/download/pdf", + ), + params: {}, + context: {}, + }); + + const pdfDoc = await PDFDocument.load(await response.arrayBuffer()); + const nameField = pdfDoc + .getForm() + .getTextField("Antragsteller (Name, Vorname ggf Geburtsname)"); + + expect(response.status).toBe(200); + expect(response.headers.get("Content-Type")).toBe("application/pdf"); + expect(pdfDoc.getPageCount()).toBe(4); + expect(nameField.getText()).toBe("Müller, Zoe"); + }); + + it("generates correct PDF for Prozesskostenhilfe", async () => { + const response = await pdfDownloadLoader({ + request: new Request( + "https://mock-url.de/prozesskostenhilfe/formular/download/pdf", + ), + params: {}, + context: {}, + }); + + const pdfDoc = await PDFDocument.load(await response.arrayBuffer()); + const nameField = pdfDoc + .getForm() + .getTextField("Name Vorname ggf Geburtsname"); + + expect(response.status).toBe(200); + expect(response.headers.get("Content-Type")).toBe("application/pdf"); + expect(pdfDoc.getPageCount()).toBe(9); + expect(nameField.getText()).toBe("Müller, Zoe"); + }); +});