Files
faunosteo/apps/app/tests/unit/pdf.attachment.test.ts
T
bchanot 8673475293 chore(workspace): move the app to apps/app under a pnpm workspace (step 2)
144 files moved with git mv (pure renames). Root package.json delegates
dev/typecheck/test:run/lint/build to the packages; Node 24 LTS and
pnpm 10.13.1 pinned (.nvmrc, .node-version, engines, packageManager,
root devDependency, engine-strict). Dockerfile builds @faunosteo/app on
node:24-alpine and copies apps/app/dist; nginx and runtime config
unchanged. CI workflow for Gitea Actions. packages/ reserved (README only).
Docs synced: WORKSPACE.md, CLAUDE.md, README, DEPLOY, CHANGELOG, plan.
271/271 tests, typecheck, lint, build green from the root.
2026-10-08 21:51:13 +02:00

41 lines
1.3 KiB
TypeScript

import { describe, it, expect } from 'vitest'
import { PDFDocument } from 'pdf-lib'
import { attachReportJson, extractReportJson } from '@/pdf/attachment'
import type { Report } from '@/domain/schema/report'
const report: Report = {
version: 2,
id: 'r1',
createdAt: '2026-05-18T10:00:00Z',
date: '2026-05-18',
practitioner: { name: 'Dr. Dupont' },
animal: { speciesId: 'equine', name: 'Mistral' },
owner: { name: 'Jean Martin' },
observations: [],
conclusion: 'tout va bien',
recommendations: 'continuer',
}
describe('PDF attachment roundtrip', () => {
it('attaches and extracts the report JSON', async () => {
const doc = await PDFDocument.create()
doc.addPage()
await attachReportJson(doc, report)
const bytes = await doc.save()
const reopened = await PDFDocument.load(bytes)
const out = await extractReportJson(reopened)
expect(out.conclusion).toBe('tout va bien')
expect(out.animal.name).toBe('Mistral')
expect(out.version).toBe(2)
})
it('throws on PDFs without the attachment', async () => {
const doc = await PDFDocument.create()
doc.addPage()
const bytes = await doc.save()
const reopened = await PDFDocument.load(bytes)
await expect(extractReportJson(reopened)).rejects.toThrow()
})
})