Skip to content

Commit

Permalink
test(pdf-service): add pdfDownloadLoader tests (#1547)
Browse files Browse the repository at this point in the history
  • Loading branch information
rbrtrfl authored Dec 12, 2024
1 parent 9a05747 commit 8222791
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions app/routes/shared/__test__/pdfDownloadLoader.test.ts
Original file line number Diff line number Diff line change
@@ -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");
});
});

0 comments on commit 8222791

Please sign in to comment.