feat(companies): service + validators + unit tests

This commit is contained in:
Matt Ciaccio
2026-04-24 12:02:08 +02:00
parent 7c408cf975
commit 037f2544e8
5 changed files with 628 additions and 0 deletions

View File

@@ -6,6 +6,7 @@ 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';
import { createCompanySchema } from '@/lib/validators/companies';
// ─── Client schemas ───────────────────────────────────────────────────────────
@@ -415,3 +416,41 @@ describe('transferOwnershipSchema', () => {
expect(result.success).toBe(true);
});
});
// ─── Company schemas ──────────────────────────────────────────────────────────
describe('createCompanySchema', () => {
it('rejects empty name', () => {
const result = createCompanySchema.safeParse({ name: '' });
expect(result.success).toBe(false);
});
it('rejects invalid billingEmail', () => {
const result = createCompanySchema.safeParse({
name: 'Aegean Holdings',
billingEmail: 'not-an-email',
});
expect(result.success).toBe(false);
});
it('accepts minimal valid input', () => {
const result = createCompanySchema.safeParse({ name: 'Aegean Holdings' });
expect(result.success).toBe(true);
});
it('accepts full valid input', () => {
const result = createCompanySchema.safeParse({
name: 'Aegean Holdings',
legalName: 'Aegean Holdings Ltd.',
taxId: 'GR123456789',
registrationNumber: 'REG-001',
incorporationCountry: 'GR',
incorporationDate: '2010-04-15',
status: 'active',
billingEmail: 'billing@aegean.example',
notes: 'Longtime customer',
tagIds: ['tag-1', 'tag-2'],
});
expect(result.success).toBe(true);
});
});