-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(pdf-service): append hinweisblatt to pkh pdf (#1518)
- Loading branch information
Showing
6 changed files
with
125 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
app/domains/prozesskostenhilfe/services/pdf/__test__/loadHinweisblatt.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import fs from "node:fs"; | ||
import path from "node:path"; | ||
import { describe, it, expect } from "vitest"; | ||
|
||
describe("loadHinweisblatt", () => { | ||
it("should fail when the location of the PDF file has changed", () => { | ||
const originalPath = path.resolve( | ||
path.join( | ||
process.cwd(), | ||
"data/pdf/", | ||
"prozesskostenhilfe", | ||
"Formular_Hinweisblatt_Prozess_Verfahrenskostenhilfe.pdf", | ||
), | ||
); | ||
|
||
const fileExists = fs.existsSync(originalPath); | ||
expect(fileExists).toBe(true); | ||
}); | ||
}); |
64 changes: 64 additions & 0 deletions
64
...omains/prozesskostenhilfe/services/pdf/__test__/prozesskostenhilfePdfFromUserdata.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { PDFDocument } from "pdf-lib"; | ||
import type { ProzesskostenhilfeFormularContext } from "~/domains/prozesskostenhilfe/formular"; | ||
import { addMetadataToPdf } from "~/services/pdf/addMetadataToPdf"; | ||
import { appendPagesToPdf } from "~/services/pdf/appendPagesToPdf"; | ||
import { pdfFillReducer } from "~/services/pdf/fillOutFunction"; | ||
import { fillPdf } from "~/services/pdf/fillPdf.server"; | ||
import { pdfFromUserData } from "~/services/pdf/pdfFromUserData"; | ||
import { prozesskostenhilfePdfFromUserdata } from ".."; | ||
import loadHinweisblatt from "../loadHinweisblatt"; | ||
|
||
vi.mock("~/services/pdf/fillOutFunction", () => ({ | ||
pdfFillReducer: vi.fn(), | ||
})); | ||
vi.mock("~/services/pdf/fillPdf.server", () => ({ | ||
fillPdf: vi.fn(), | ||
})); | ||
vi.mock("~/services/pdf/addMetadataToPdf", () => ({ | ||
addMetadataToPdf: vi.fn(), | ||
})); | ||
vi.mock("~/services/pdf/appendPagesToPdf", () => ({ | ||
appendPagesToPdf: vi.fn(), | ||
})); | ||
vi.mock("~/services/pdf/pdfFromUserData", () => ({ | ||
pdfFromUserData: vi.fn(), | ||
})); | ||
vi.mock("../loadHinweisblatt", () => ({ | ||
default: vi.fn(), | ||
})); | ||
|
||
const userData: ProzesskostenhilfeFormularContext = { | ||
vorname: "Angelika", | ||
nachname: "M", | ||
}; | ||
|
||
describe("prozesskostenhilfePdfFromUserdata", () => { | ||
beforeEach(() => { | ||
vi.resetAllMocks(); | ||
}); | ||
|
||
it("should call all expected functions", async () => { | ||
const mockPdfDocument = await PDFDocument.create(); | ||
const pdfBytes = await mockPdfDocument.save(); | ||
const mockPdfBuffer = Buffer.from(pdfBytes); | ||
const mockUint8Array = new Uint8Array(pdfBytes); | ||
|
||
vi.mocked(pdfFillReducer).mockReturnValue({ | ||
pdfValues: {}, | ||
attachment: [], | ||
}); | ||
vi.mocked(fillPdf).mockResolvedValue(mockPdfDocument); | ||
vi.mocked(addMetadataToPdf).mockReturnValue(mockPdfDocument); | ||
vi.mocked(pdfFromUserData).mockResolvedValue(mockPdfBuffer); | ||
vi.mocked(appendPagesToPdf).mockResolvedValue(mockUint8Array); | ||
vi.mocked(loadHinweisblatt).mockResolvedValue(mockPdfDocument); | ||
|
||
await prozesskostenhilfePdfFromUserdata(userData); | ||
|
||
expect(pdfFillReducer).toHaveBeenCalled(); | ||
expect(fillPdf).toHaveBeenCalled(); | ||
expect(addMetadataToPdf).toHaveBeenCalled(); | ||
expect(appendPagesToPdf).toHaveBeenCalled(); | ||
expect(loadHinweisblatt).toHaveBeenCalled(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
app/domains/prozesskostenhilfe/services/pdf/loadHinweisblatt.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import fs from "node:fs"; | ||
import path from "node:path"; | ||
import { PDFDocument } from "pdf-lib"; | ||
import { addDruckvermerk } from "~/services/pdf/druckvermerk"; | ||
|
||
export default async function loadHinweisblatt({ | ||
yPositionDruckvermerk, | ||
xPositionDruckvermerk, | ||
}: { | ||
yPositionDruckvermerk: number; | ||
xPositionDruckvermerk: number; | ||
}) { | ||
const filepath = path.resolve( | ||
path.join( | ||
process.cwd(), | ||
"data/pdf/", | ||
"prozesskostenhilfe", | ||
"Formular_Hinweisblatt_Prozess_Verfahrenskostenhilfe.pdf", | ||
), | ||
); | ||
|
||
const pdfDoc = await PDFDocument.load(fs.readFileSync(filepath)); | ||
|
||
addDruckvermerk(pdfDoc, yPositionDruckvermerk, xPositionDruckvermerk); | ||
|
||
return pdfDoc; | ||
} |
Binary file added
BIN
+187 KB
data/pdf/prozesskostenhilfe/Formular_Hinweisblatt_Prozess_Verfahrenskostenhilfe.pdf
Binary file not shown.