feat(events): register yacht, company, membership, reservation webhook events

This commit is contained in:
Matt Ciaccio
2026-04-24 12:56:47 +02:00
parent a78f653f5a
commit 94f8b76a03
2 changed files with 86 additions and 2 deletions

View File

@@ -24,6 +24,20 @@ export const WEBHOOK_EVENTS = [
'invoice.paid', 'invoice.paid',
'invoice.overdue', 'invoice.overdue',
'registration.new', 'registration.new',
'yacht.created',
'yacht.updated',
'yacht.ownership_transferred',
'yacht.archived',
'company.created',
'company.updated',
'company.archived',
'company_membership.added',
'company_membership.updated',
'company_membership.ended',
'berth_reservation.created',
'berth_reservation.activated',
'berth_reservation.ended',
'berth_reservation.cancelled',
] as const; ] as const;
export type WebhookEvent = (typeof WEBHOOK_EVENTS)[number]; export type WebhookEvent = (typeof WEBHOOK_EVENTS)[number];
@@ -50,4 +64,18 @@ export const INTERNAL_TO_WEBHOOK_MAP: Record<string, WebhookEvent> = {
'invoice:paid': 'invoice.paid', 'invoice:paid': 'invoice.paid',
'invoice:overdue': 'invoice.overdue', 'invoice:overdue': 'invoice.overdue',
'registration:new': 'registration.new', 'registration:new': 'registration.new',
'yacht:created': 'yacht.created',
'yacht:updated': 'yacht.updated',
'yacht:ownership_transferred': 'yacht.ownership_transferred',
'yacht:archived': 'yacht.archived',
'company:created': 'company.created',
'company:updated': 'company.updated',
'company:archived': 'company.archived',
'company_membership:added': 'company_membership.added',
'company_membership:updated': 'company_membership.updated',
'company_membership:ended': 'company_membership.ended',
'berth_reservation:created': 'berth_reservation.created',
'berth_reservation:activated': 'berth_reservation.activated',
'berth_reservation:ended': 'berth_reservation.ended',
'berth_reservation:cancelled': 'berth_reservation.cancelled',
}; };

View File

@@ -5,7 +5,10 @@ describe('INTERNAL_TO_WEBHOOK_MAP', () => {
it('every internal event key maps to a value present in WEBHOOK_EVENTS', () => { it('every internal event key maps to a value present in WEBHOOK_EVENTS', () => {
const validEvents = new Set<string>(WEBHOOK_EVENTS); const validEvents = new Set<string>(WEBHOOK_EVENTS);
for (const [internalKey, webhookEvent] of Object.entries(INTERNAL_TO_WEBHOOK_MAP)) { for (const [internalKey, webhookEvent] of Object.entries(INTERNAL_TO_WEBHOOK_MAP)) {
expect(validEvents.has(webhookEvent), `"${internalKey}" maps to unknown event "${webhookEvent}"`).toBe(true); expect(
validEvents.has(webhookEvent),
`"${internalKey}" maps to unknown event "${webhookEvent}"`,
).toBe(true);
} }
}); });
@@ -43,7 +46,9 @@ describe('WEBHOOK_EVENTS', () => {
it('contains all values present in INTERNAL_TO_WEBHOOK_MAP', () => { it('contains all values present in INTERNAL_TO_WEBHOOK_MAP', () => {
const eventsSet = new Set<string>(WEBHOOK_EVENTS); const eventsSet = new Set<string>(WEBHOOK_EVENTS);
for (const webhookEvent of Object.values(INTERNAL_TO_WEBHOOK_MAP)) { for (const webhookEvent of Object.values(INTERNAL_TO_WEBHOOK_MAP)) {
expect(eventsSet.has(webhookEvent), `"${webhookEvent}" missing from WEBHOOK_EVENTS`).toBe(true); expect(eventsSet.has(webhookEvent), `"${webhookEvent}" missing from WEBHOOK_EVENTS`).toBe(
true,
);
} }
}); });
@@ -71,3 +76,54 @@ describe('WEBHOOK_EVENTS', () => {
expect(unique.size).toBe(WEBHOOK_EVENTS.length); expect(unique.size).toBe(WEBHOOK_EVENTS.length);
}); });
}); });
describe('new resource events (yachts, companies, memberships, reservations)', () => {
it('includes all yacht events in the catalog', () => {
const events = new Set<string>(WEBHOOK_EVENTS);
['yacht.created', 'yacht.updated', 'yacht.ownership_transferred', 'yacht.archived'].forEach(
(e) => {
expect(events.has(e), `missing ${e}`).toBe(true);
},
);
});
it('includes all company events', () => {
const events = new Set<string>(WEBHOOK_EVENTS);
['company.created', 'company.updated', 'company.archived'].forEach((e) => {
expect(events.has(e)).toBe(true);
});
});
it('includes all membership events', () => {
const events = new Set<string>(WEBHOOK_EVENTS);
['company_membership.added', 'company_membership.updated', 'company_membership.ended'].forEach(
(e) => {
expect(events.has(e)).toBe(true);
},
);
});
it('includes all berth reservation lifecycle events', () => {
const events = new Set<string>(WEBHOOK_EVENTS);
[
'berth_reservation.created',
'berth_reservation.activated',
'berth_reservation.ended',
'berth_reservation.cancelled',
].forEach((e) => {
expect(events.has(e)).toBe(true);
});
});
it('yacht:ownership_transferred maps to yacht.ownership_transferred', () => {
expect(INTERNAL_TO_WEBHOOK_MAP['yacht:ownership_transferred']).toBe(
'yacht.ownership_transferred',
);
});
it('berth_reservation:activated maps to berth_reservation.activated', () => {
expect(INTERNAL_TO_WEBHOOK_MAP['berth_reservation:activated']).toBe(
'berth_reservation.activated',
);
});
});