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() }) })