feat(yachts): add zod validators + tests
This commit is contained in:
49
tests/unit/validators/yachts.test.ts
Normal file
49
tests/unit/validators/yachts.test.ts
Normal 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);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user