Files
pn-new-crm/tests/unit/webhook-event-map.test.ts
Matt 67d7e6e3d5
Some checks failed
Build & Push Docker Images / build-and-push (push) Has been cancelled
Build & Push Docker Images / deploy (push) Has been cancelled
Build & Push Docker Images / lint (push) Has been cancelled
Initial commit: Port Nimara CRM (Layers 0-4)
Full CRM rebuild with Next.js 15, TypeScript, Tailwind, Drizzle ORM,
PostgreSQL, Redis, BullMQ, MinIO, and Socket.io. Includes 461 source
files covering clients, berths, interests/pipeline, documents/EOI,
expenses/invoices, email, notifications, dashboard, admin, and
client portal. CI/CD via Gitea Actions with Docker builds.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 11:52:51 +01:00

74 lines
2.7 KiB
TypeScript

import { describe, it, expect } from 'vitest';
import { INTERNAL_TO_WEBHOOK_MAP, WEBHOOK_EVENTS } from '@/lib/services/webhook-event-map';
describe('INTERNAL_TO_WEBHOOK_MAP', () => {
it('every internal event key maps to a value present in WEBHOOK_EVENTS', () => {
const validEvents = new Set<string>(WEBHOOK_EVENTS);
for (const [internalKey, webhookEvent] of Object.entries(INTERNAL_TO_WEBHOOK_MAP)) {
expect(validEvents.has(webhookEvent), `"${internalKey}" maps to unknown event "${webhookEvent}"`).toBe(true);
}
});
it('all webhook event values use dot-style notation (contain a dot, no colons)', () => {
for (const webhookEvent of Object.values(INTERNAL_TO_WEBHOOK_MAP)) {
expect(webhookEvent, `"${webhookEvent}" does not contain a dot`).toMatch(/\./);
expect(webhookEvent, `"${webhookEvent}" contains a colon`).not.toMatch(/:/);
}
});
it('"interest:stageChanged" maps to "interest.stage_changed"', () => {
expect(INTERNAL_TO_WEBHOOK_MAP['interest:stageChanged']).toBe('interest.stage_changed');
});
it('"client:created" maps to "client.created"', () => {
expect(INTERNAL_TO_WEBHOOK_MAP['client:created']).toBe('client.created');
});
it('"document:signed" maps to "document.signed"', () => {
expect(INTERNAL_TO_WEBHOOK_MAP['document:signed']).toBe('document.signed');
});
it('"registration:new" maps to "registration.new"', () => {
expect(INTERNAL_TO_WEBHOOK_MAP['registration:new']).toBe('registration.new');
});
it('has no duplicate values in the map', () => {
const values = Object.values(INTERNAL_TO_WEBHOOK_MAP);
const unique = new Set(values);
expect(unique.size).toBe(values.length);
});
});
describe('WEBHOOK_EVENTS', () => {
it('contains all values present in INTERNAL_TO_WEBHOOK_MAP', () => {
const eventsSet = new Set<string>(WEBHOOK_EVENTS);
for (const webhookEvent of Object.values(INTERNAL_TO_WEBHOOK_MAP)) {
expect(eventsSet.has(webhookEvent), `"${webhookEvent}" missing from WEBHOOK_EVENTS`).toBe(true);
}
});
it('all entries use dot-style notation', () => {
for (const event of WEBHOOK_EVENTS) {
expect(event).toMatch(/\./);
expect(event).not.toMatch(/:/);
}
});
it('contains "interest.stage_changed"', () => {
expect(WEBHOOK_EVENTS).toContain('interest.stage_changed');
});
it('contains "client.created"', () => {
expect(WEBHOOK_EVENTS).toContain('client.created');
});
it('contains "registration.new"', () => {
expect(WEBHOOK_EVENTS).toContain('registration.new');
});
it('has no duplicate entries', () => {
const unique = new Set(WEBHOOK_EVENTS);
expect(unique.size).toBe(WEBHOOK_EVENTS.length);
});
});