Files
pn-new-crm/tests/unit/validators/yachts.test.ts

50 lines
1.4 KiB
TypeScript
Raw Normal View History

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