100 lines
2.9 KiB
TypeScript
100 lines
2.9 KiB
TypeScript
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
import {
|
|
syncGoogleCalendarBusySnapshot,
|
|
syncMicrosoftCalendarBusySnapshot,
|
|
} from "./admin-calendar-sync-worker.server.js";
|
|
|
|
const originalFetch = globalThis.fetch;
|
|
|
|
afterEach(() => {
|
|
globalThis.fetch = originalFetch;
|
|
vi.restoreAllMocks();
|
|
});
|
|
|
|
describe("admin calendar busy snapshot sync", () => {
|
|
it("applies Google deltas without retaining private event content", async () => {
|
|
globalThis.fetch = vi.fn(async () =>
|
|
Response.json({
|
|
items: [
|
|
{
|
|
id: "busy-1",
|
|
summary: "Private title",
|
|
description: "Private details",
|
|
start: { dateTime: "2026-07-26T08:00:00.000Z" },
|
|
end: { dateTime: "2026-07-26T09:00:00.000Z" },
|
|
etag: "v1",
|
|
},
|
|
{ id: "old", status: "cancelled" },
|
|
],
|
|
nextSyncToken: "cursor-2",
|
|
})
|
|
);
|
|
const result = await syncGoogleCalendarBusySnapshot({
|
|
provider: "google_calendar",
|
|
accessToken: "token",
|
|
externalCalendarId: "primary",
|
|
cursorToken: "cursor-1",
|
|
deltaLink: null,
|
|
busyIntervals: [
|
|
{
|
|
externalEventId: "old",
|
|
startsAt: "2026-07-25T08:00:00.000Z",
|
|
endsAt: "2026-07-25T09:00:00.000Z",
|
|
},
|
|
],
|
|
now: new Date("2026-07-25T10:00:00.000Z"),
|
|
});
|
|
expect(result).toEqual({
|
|
busyIntervals: [
|
|
{
|
|
externalEventId: "busy-1",
|
|
startsAt: "2026-07-26T08:00:00.000Z",
|
|
endsAt: "2026-07-26T09:00:00.000Z",
|
|
opaqueVersion: "v1",
|
|
},
|
|
],
|
|
cursorToken: "cursor-2",
|
|
deltaLink: null,
|
|
});
|
|
expect(JSON.stringify(result)).not.toContain("Private");
|
|
});
|
|
|
|
it("applies Microsoft delta links and removes free events", async () => {
|
|
globalThis.fetch = vi.fn(async () =>
|
|
Response.json({
|
|
value: [
|
|
{
|
|
id: "busy-2",
|
|
start: { dateTime: "2026-07-27T08:00:00.000Z" },
|
|
end: { dateTime: "2026-07-27T09:00:00.000Z" },
|
|
showAs: "busy",
|
|
changeKey: "v2",
|
|
},
|
|
{ id: "old", showAs: "free" },
|
|
],
|
|
"@odata.deltaLink":
|
|
"https://graph.microsoft.com/v1.0/me/calendars/c/delta?$deltatoken=2",
|
|
})
|
|
);
|
|
const result = await syncMicrosoftCalendarBusySnapshot({
|
|
provider: "microsoft_calendar",
|
|
accessToken: "token",
|
|
externalCalendarId: "calendar",
|
|
cursorToken: null,
|
|
deltaLink:
|
|
"https://graph.microsoft.com/v1.0/me/calendars/c/delta?$deltatoken=1",
|
|
busyIntervals: [
|
|
{
|
|
externalEventId: "old",
|
|
startsAt: "2026-07-25T08:00:00.000Z",
|
|
endsAt: "2026-07-25T09:00:00.000Z",
|
|
},
|
|
],
|
|
now: new Date("2026-07-25T10:00:00.000Z"),
|
|
});
|
|
expect(result.busyIntervals).toHaveLength(1);
|
|
expect(result.busyIntervals[0]?.externalEventId).toBe("busy-2");
|
|
expect(result.deltaLink).toContain("$deltatoken=2");
|
|
});
|
|
});
|