108 lines
3.0 KiB
TypeScript
108 lines
3.0 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
|
|
import {
|
|
assertAdminCalendarScopes,
|
|
mergeBusyIntervalDelta,
|
|
projectGoogleBusyIntervals,
|
|
projectMicrosoftBusyIntervals,
|
|
} from "./admin-calendar-provider.js";
|
|
|
|
describe("admin calendar provider contract", () => {
|
|
it("requires the complete provider-specific delegated scope set", () => {
|
|
expect(() =>
|
|
assertAdminCalendarScopes("microsoft_calendar", [
|
|
"offline_access",
|
|
"Calendars.ReadWrite",
|
|
])
|
|
).toThrowError(
|
|
expect.objectContaining({
|
|
code: "missing_required_scopes",
|
|
})
|
|
);
|
|
});
|
|
|
|
it("projects Google events to anonymous, stable busy intervals", () => {
|
|
const result = projectGoogleBusyIntervals([
|
|
{
|
|
id: "private-event",
|
|
summary: "Vertraulicher Termin",
|
|
description: "darf nicht gespeichert werden",
|
|
start: { dateTime: "2026-07-28T10:00:00+02:00" },
|
|
end: { dateTime: "2026-07-28T11:00:00+02:00" },
|
|
etag: "v1",
|
|
},
|
|
{
|
|
id: "free-event",
|
|
transparency: "transparent",
|
|
start: { dateTime: "2026-07-28T12:00:00+02:00" },
|
|
end: { dateTime: "2026-07-28T13:00:00+02:00" },
|
|
},
|
|
]);
|
|
expect(result).toEqual([
|
|
{
|
|
externalEventId: "private-event",
|
|
startsAt: "2026-07-28T08:00:00.000Z",
|
|
endsAt: "2026-07-28T09:00:00.000Z",
|
|
opaqueVersion: "v1",
|
|
},
|
|
]);
|
|
expect(JSON.stringify(result)).not.toContain("Vertraulicher");
|
|
});
|
|
|
|
it("drops free, cancelled and removed Microsoft events", () => {
|
|
const result = projectMicrosoftBusyIntervals([
|
|
{
|
|
id: "busy",
|
|
start: { dateTime: "2026-07-28T08:00:00Z" },
|
|
end: { dateTime: "2026-07-28T09:00:00Z" },
|
|
showAs: "busy",
|
|
},
|
|
{
|
|
id: "free",
|
|
start: { dateTime: "2026-07-28T09:00:00Z" },
|
|
end: { dateTime: "2026-07-28T10:00:00Z" },
|
|
showAs: "free",
|
|
},
|
|
{
|
|
id: "removed",
|
|
"@removed": { reason: "deleted" },
|
|
},
|
|
]);
|
|
expect(result.map((entry) => entry.externalEventId)).toEqual(["busy"]);
|
|
});
|
|
|
|
it("replaces changed events and removes provider tombstones deterministically", () => {
|
|
expect(
|
|
mergeBusyIntervalDelta({
|
|
current: [
|
|
{
|
|
externalEventId: "changed",
|
|
startsAt: "2026-07-28T08:00:00Z",
|
|
endsAt: "2026-07-28T09:00:00Z",
|
|
},
|
|
{
|
|
externalEventId: "deleted",
|
|
startsAt: "2026-07-28T10:00:00Z",
|
|
endsAt: "2026-07-28T11:00:00Z",
|
|
},
|
|
],
|
|
upserts: [
|
|
{
|
|
externalEventId: "changed",
|
|
startsAt: "2026-07-28T09:00:00Z",
|
|
endsAt: "2026-07-28T10:00:00Z",
|
|
},
|
|
],
|
|
removedExternalEventIds: ["deleted"],
|
|
})
|
|
).toEqual([
|
|
{
|
|
externalEventId: "changed",
|
|
startsAt: "2026-07-28T09:00:00.000Z",
|
|
endsAt: "2026-07-28T10:00:00.000Z",
|
|
opaqueVersion: undefined,
|
|
},
|
|
]);
|
|
});
|
|
});
|