Files
FEDEO/backend/tests/pdfCharacterError.test.ts
flfeders d3ad53bcf0
All checks were successful
Build and Push Docker Images / build-backend (push) Successful in 30s
Build and Push Docker Images / build-frontend (push) Successful in 1m12s
Build and Push Docker Images / build-website (push) Successful in 18s
Build and Push Docker Images / build-docs (push) Successful in 17s
Improve unsupported PDF character errors
2026-07-24 10:25:10 +02:00

28 lines
1.1 KiB
TypeScript

import assert from "node:assert/strict"
import test from "node:test"
import { getUnsupportedPdfCharacterMessage } from "../src/utils/pdfCharacterError"
test("reports unsupported characters with the document position and character offset", () => {
// pdf-lib displays supplementary Unicode characters as a private-use glyph,
// while the hexadecimal value still contains the original code point.
const error = new Error('WinAnsi cannot encode "" (0x1f600)')
const documentData = {
rows: [
{ pos: "1", text: "Montage" },
{ pos: "2.3", descriptionText: "Gerät 😀 montieren" },
],
}
assert.equal(
getUnsupportedPdfCharacterMessage(error, documentData),
"Das Zeichen „😀“ (Unicode U+1F600) wird in PDF-Dokumenten nicht unterstützt. Fundstelle: Position 2.3, Beschreibung, Zeichen 7. Bitte ersetze oder entferne das Zeichen."
)
})
test("returns null for unrelated PDF errors", () => {
assert.equal(
getUnsupportedPdfCharacterMessage(new Error("Background PDF is invalid"), {}),
null
)
})