refactor(yachts): rename schema + consolidate tests per project conventions
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { createClientSchema, updateClientSchema } from '@/lib/validators/clients';
|
||||
import { createInterestSchema, updateInterestSchema, changeStageSchema } from '@/lib/validators/interests';
|
||||
import { createInterestSchema, changeStageSchema } from '@/lib/validators/interests';
|
||||
import { updateBerthSchema, updateBerthStatusSchema } from '@/lib/validators/berths';
|
||||
import { createInvoiceSchema } from '@/lib/validators/invoices';
|
||||
import { createWebhookSchema, updateWebhookSchema } from '@/lib/validators/webhooks';
|
||||
import { createFieldSchema, updateFieldSchema } from '@/lib/validators/custom-fields';
|
||||
import { createYachtSchema, transferOwnershipSchema } from '@/lib/validators/yachts';
|
||||
|
||||
// ─── Client schemas ───────────────────────────────────────────────────────────
|
||||
|
||||
@@ -92,12 +93,24 @@ describe('createInterestSchema', () => {
|
||||
});
|
||||
|
||||
it('rejects invalid pipelineStage', () => {
|
||||
const result = createInterestSchema.safeParse({ clientId: 'c1', pipelineStage: 'unknown_stage' });
|
||||
const result = createInterestSchema.safeParse({
|
||||
clientId: 'c1',
|
||||
pipelineStage: 'unknown_stage',
|
||||
});
|
||||
expect(result.success).toBe(false);
|
||||
});
|
||||
|
||||
it('accepts all valid pipeline stages', () => {
|
||||
const stages = ['open', 'details_sent', 'in_communication', 'visited', 'signed_eoi_nda', 'deposit_10pct', 'contract', 'completed'];
|
||||
const stages = [
|
||||
'open',
|
||||
'details_sent',
|
||||
'in_communication',
|
||||
'visited',
|
||||
'signed_eoi_nda',
|
||||
'deposit_10pct',
|
||||
'contract',
|
||||
'completed',
|
||||
];
|
||||
for (const stage of stages) {
|
||||
const result = createInterestSchema.safeParse({ clientId: 'c1', pipelineStage: stage });
|
||||
expect(result.success, `stage "${stage}" should be valid`).toBe(true);
|
||||
@@ -138,11 +151,15 @@ describe('updateBerthSchema', () => {
|
||||
|
||||
describe('updateBerthStatusSchema', () => {
|
||||
it('accepts valid status with reason', () => {
|
||||
expect(updateBerthStatusSchema.safeParse({ status: 'available', reason: 'Freed up' }).success).toBe(true);
|
||||
expect(
|
||||
updateBerthStatusSchema.safeParse({ status: 'available', reason: 'Freed up' }).success,
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it('rejects invalid status', () => {
|
||||
expect(updateBerthStatusSchema.safeParse({ status: 'occupied', reason: 'reason' }).success).toBe(false);
|
||||
expect(
|
||||
updateBerthStatusSchema.safeParse({ status: 'occupied', reason: 'reason' }).success,
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it('rejects missing reason', () => {
|
||||
@@ -220,7 +237,10 @@ describe('createWebhookSchema', () => {
|
||||
});
|
||||
|
||||
it('rejects http URL (must be HTTPS)', () => {
|
||||
const result = createWebhookSchema.safeParse({ ...validWebhook, url: 'http://example.com/hook' });
|
||||
const result = createWebhookSchema.safeParse({
|
||||
...validWebhook,
|
||||
url: 'http://example.com/hook',
|
||||
});
|
||||
expect(result.success).toBe(false);
|
||||
if (!result.success) {
|
||||
const messages = result.error.issues.map((i) => i.message);
|
||||
@@ -288,7 +308,10 @@ describe('createFieldSchema', () => {
|
||||
});
|
||||
|
||||
it('rejects fieldName with spaces', () => {
|
||||
const result = createFieldSchema.safeParse({ ...validTextField, fieldName: 'preferred marina' });
|
||||
const result = createFieldSchema.safeParse({
|
||||
...validTextField,
|
||||
fieldName: 'preferred marina',
|
||||
});
|
||||
expect(result.success).toBe(false);
|
||||
});
|
||||
|
||||
@@ -343,3 +366,52 @@ describe('updateFieldSchema', () => {
|
||||
// it cannot be used to mutate fieldType.
|
||||
});
|
||||
});
|
||||
|
||||
// ─── Yacht schemas ────────────────────────────────────────────────────────────
|
||||
|
||||
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);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,49 +0,0 @@
|
||||
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