feat(yachts): add zod validators + tests

This commit is contained in:
Matt Ciaccio
2026-04-23 23:31:29 +02:00
parent 7a6e95c87a
commit 899e588a0c
2 changed files with 101 additions and 0 deletions

View File

@@ -0,0 +1,49 @@
import { describe, it, expect } from 'vitest';
import { createYachtSchema, transferOwnershipSchema } from '@/lib/validators/yachts';
describe('createYachtSchema', () => {
it('rejects empty name', () => {
const result = createYachtSchema.safeParse({
name: '',
owner: { type: 'client', id: 'c1' },
});
expect(result.success).toBe(false);
});
it('requires owner', () => {
const result = createYachtSchema.safeParse({ name: 'Sea Breeze' });
expect(result.success).toBe(false);
});
it('rejects invalid yearBuilt', () => {
const result = createYachtSchema.safeParse({
name: 'Sea Breeze',
owner: { type: 'client', id: 'c1' },
yearBuilt: 1700,
});
expect(result.success).toBe(false);
});
it('accepts minimal valid input', () => {
const result = createYachtSchema.safeParse({
name: 'Sea Breeze',
owner: { type: 'client', id: 'c1' },
});
expect(result.success).toBe(true);
});
});
describe('transferOwnershipSchema', () => {
it('requires newOwner + effectiveDate', () => {
expect(transferOwnershipSchema.safeParse({}).success).toBe(false);
});
it('accepts valid input', () => {
const result = transferOwnershipSchema.safeParse({
newOwner: { type: 'company', id: 'co1' },
effectiveDate: new Date(),
transferReason: 'sale',
});
expect(result.success).toBe(true);
});
});