Files
HiveGrid-Wireframes/03 Quellen und Referenzen/hivegrid-cloud/apps/web/app/modules/booking/services/bookingAutomationEvents.server.test.ts
T

79 lines
2.8 KiB
TypeScript

import { describe, expect, test } from "vitest";
import { buildBookingBookedWorkflowEvents, buildBookingCancelledWorkflowEvent, buildCalendarCreatedWorkflowEvent } from "./bookingAutomationEvents.server";
const START = new Date("2026-08-03T08:00:00.000Z");
const END = new Date("2026-08-03T09:00:00.000Z");
describe("booking automation workflow events", () => {
test("builds one booked and one calendar-created event from the committed booking", () => {
const events = buildBookingBookedWorkflowEvents({
tenantId: "tenant-1",
appointmentId: "appointment-1",
bookingPageId: "page-1",
bookingPageSlug: "beratung",
providerUserId: "user-1",
calendarEventId: "calendar-1",
startAt: START,
endAt: END,
kontaktId: "kontakt-1",
});
expect(events).toEqual([
expect.objectContaining({
type: "workflow.trigger.event",
dispatchKey: "workflow-trigger:booking:appointment-1:booked",
payload: expect.objectContaining({
event: "booking.appointment_booked",
data: expect.objectContaining({ appointmentId: "appointment-1", appointmentType: "beratung", providerUserId: "user-1" }),
}),
}),
expect.objectContaining({
dispatchKey: "workflow-trigger:calendar:calendar-1:created",
payload: expect.objectContaining({
event: "calendar.event_created",
data: expect.objectContaining({ calendarKey: "hauptkalender", eventKind: "termin" }),
}),
}),
]);
});
test("keeps cancellation actor and timestamp in the idempotent event", () => {
const cancelledAt = new Date("2026-08-03T07:30:00.000Z");
expect(
buildBookingCancelledWorkflowEvent({
tenantId: "tenant-1",
appointmentId: "appointment-1",
bookingPageId: "page-1",
bookingPageSlug: "wartung",
providerUserId: "user-1",
cancelledByKind: "customer",
cancellationReason: "Keine Zeit",
cancelledAt,
actorUserId: null,
})
).toMatchObject({
dispatchKey: `workflow-trigger:booking:appointment-1:cancelled:${cancelledAt.getTime()}`,
payload: { event: "booking.appointment_cancelled", data: { cancelledByKind: "customer", appointmentType: "wartung" }, userId: null },
});
});
test("builds reusable calendar-created events for non-booking sources", () => {
expect(
buildCalendarCreatedWorkflowEvent({
tenantId: "tenant-1",
calendarEventId: "calendar-2",
userId: "user-2",
calendarKey: "urlaubskalender",
eventKind: "termin",
source: "leave",
sourceEntityId: "leave-1",
startsAt: START,
endsAt: END,
})
).toMatchObject({
payload: { event: "calendar.event_created", data: { calendarKey: "urlaubskalender", source: "leave" }, userId: "user-2" },
});
});
});