33 lines
1.1 KiB
TypeScript
33 lines
1.1 KiB
TypeScript
import { describe, it, expect, vi } from 'vitest'
|
|
import { exportReportToPdf } from '@/pdf/export'
|
|
import { importReportFromPdf, ImportError } from '@/pdf/import'
|
|
import type { Report } from '@/domain/schema/report'
|
|
|
|
vi.mock('@/pdf/render/svgToPng', () => ({ rasterizeSvg: async () => new Uint8Array([137, 80, 78, 71]) }))
|
|
|
|
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: 'ok',
|
|
recommendations: '',
|
|
}
|
|
|
|
describe('PDF roundtrip', () => {
|
|
it('rejects unrelated PDF bytes with ImportError', async () => {
|
|
const fake = new Uint8Array([37, 80, 68, 70, 45, 49, 46, 52, 10, 37, 226, 227, 207, 211, 10])
|
|
await expect(importReportFromPdf(fake)).rejects.toThrow(ImportError)
|
|
})
|
|
|
|
it('roundtrips a minimal report (no observations)', async () => {
|
|
const bytes = await exportReportToPdf(report)
|
|
const imported = await importReportFromPdf(bytes)
|
|
expect(imported.animal.name).toBe('Mistral')
|
|
})
|
|
})
|