41 lines
1.3 KiB
TypeScript
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: 1,
|
|
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(1)
|
|
})
|
|
|
|
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()
|
|
})
|
|
})
|