From 839ddd05ff4562c8502b8242133496870fd03dfc Mon Sep 17 00:00:00 2001 From: Bastien Chanot Date: Mon, 18 May 2026 21:00:01 +0200 Subject: [PATCH] test(schema): cover ReportSchema discriminated union + version --- tests/unit/schema.report.test.ts | 49 ++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 tests/unit/schema.report.test.ts diff --git a/tests/unit/schema.report.test.ts b/tests/unit/schema.report.test.ts new file mode 100644 index 00000000..97493d14 --- /dev/null +++ b/tests/unit/schema.report.test.ts @@ -0,0 +1,49 @@ +import { describe, it, expect } from 'vitest' +import { ReportSchema } from '@/domain/schema/report' + +const minimal = { + version: 1 as const, + 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: '', + recommendations: '', +} + +describe('ReportSchema', () => { + it('accepts a minimal valid report', () => { + expect(() => ReportSchema.parse(minimal)).not.toThrow() + }) + + it('accepts nextAppointment kind=date', () => { + expect(() => + ReportSchema.parse({ + ...minimal, + nextAppointment: { kind: 'date', date: '2026-06-08' }, + }), + ).not.toThrow() + }) + + it('accepts nextAppointment kind=period', () => { + expect(() => + ReportSchema.parse({ + ...minimal, + nextAppointment: { kind: 'period', text: 'dans 3 semaines' }, + }), + ).not.toThrow() + }) + + it('rejects version !== 1', () => { + expect(() => ReportSchema.parse({ ...minimal, version: 2 })).toThrow() + }) + + it('rejects empty practitioner.name', () => { + expect(() => + ReportSchema.parse({ ...minimal, practitioner: { name: '' } }), + ).toThrow() + }) +})