114 lines
2.8 KiB
TypeScript
114 lines
2.8 KiB
TypeScript
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
|
|
const google = vi.hoisted(() => ({
|
|
insertEvent: vi.fn(),
|
|
patchEvent: vi.fn(),
|
|
deleteEvent: vi.fn(),
|
|
}));
|
|
const microsoft = vi.hoisted(() => ({
|
|
createGraphCalendarEvent: vi.fn(),
|
|
patchGraphCalendarEvent: vi.fn(),
|
|
deleteGraphCalendarEvent: vi.fn(),
|
|
}));
|
|
|
|
vi.mock("./google/googleCalendarApi.js", () => google);
|
|
vi.mock("./microsoft/graphCalendarApi.js", () => microsoft);
|
|
|
|
import {
|
|
googleAdminBookingProvider,
|
|
microsoftAdminBookingProvider,
|
|
} from "./admin-booking-provider.server.js";
|
|
|
|
const event = {
|
|
calendarId: "primary",
|
|
subject: "HiveGrid Demo",
|
|
bodyText: "Termin aus HiveGrid",
|
|
startsAt: new Date("2026-08-03T08:00:00.000Z"),
|
|
endsAt: new Date("2026-08-03T08:45:00.000Z"),
|
|
timeZone: "Europe/Berlin",
|
|
attendee: { email: "ada@example.com", name: "Ada Lovelace" },
|
|
};
|
|
|
|
describe("admin booking provider adapters", () => {
|
|
beforeEach(() => vi.clearAllMocks());
|
|
|
|
it("maps booking data to Google and preserves the opaque etag", async () => {
|
|
google.insertEvent.mockResolvedValue({ id: "g-1", etag: "v1" });
|
|
|
|
await expect(
|
|
googleAdminBookingProvider.createEvent("access", event)
|
|
).resolves.toEqual({
|
|
externalEventId: "g-1",
|
|
opaqueVersion: "v1",
|
|
});
|
|
expect(google.insertEvent).toHaveBeenCalledWith(
|
|
"access",
|
|
"primary",
|
|
expect.objectContaining({
|
|
summary: "HiveGrid Demo",
|
|
attendees: [{ email: "ada@example.com" }],
|
|
})
|
|
);
|
|
});
|
|
|
|
it("maps booking data to Microsoft and passes optimistic versions", async () => {
|
|
microsoft.patchGraphCalendarEvent.mockResolvedValue({
|
|
id: "m-1",
|
|
changeKey: "v2",
|
|
});
|
|
|
|
await expect(
|
|
microsoftAdminBookingProvider.updateEvent(
|
|
"access",
|
|
"m-1",
|
|
event,
|
|
"v1"
|
|
)
|
|
).resolves.toEqual({
|
|
externalEventId: "m-1",
|
|
opaqueVersion: "v2",
|
|
});
|
|
expect(microsoft.patchGraphCalendarEvent).toHaveBeenCalledWith(
|
|
"access",
|
|
"primary",
|
|
"m-1",
|
|
expect.objectContaining({
|
|
attendees: [
|
|
{
|
|
emailAddress: {
|
|
address: "ada@example.com",
|
|
name: "Ada Lovelace",
|
|
},
|
|
type: "required",
|
|
},
|
|
],
|
|
}),
|
|
"v1"
|
|
);
|
|
});
|
|
|
|
it("uses provider delete operations as the idempotent cancellation edge", async () => {
|
|
await googleAdminBookingProvider.deleteEvent(
|
|
"access",
|
|
"primary",
|
|
"g-1"
|
|
);
|
|
await microsoftAdminBookingProvider.deleteEvent(
|
|
"access",
|
|
"primary",
|
|
"m-1"
|
|
);
|
|
|
|
expect(google.deleteEvent).toHaveBeenCalledWith(
|
|
"access",
|
|
"primary",
|
|
"g-1"
|
|
);
|
|
expect(microsoft.deleteGraphCalendarEvent).toHaveBeenCalledWith(
|
|
"access",
|
|
"primary",
|
|
"m-1"
|
|
);
|
|
});
|
|
});
|