53 lines
2.0 KiB
TypeScript
53 lines
2.0 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import type { NeutralEvent } from "./adapters/CalendarAdapter";
|
|
import { toExternalEventFields, type EventOwnerContext } from "./eventMapping";
|
|
|
|
const ctx: EventOwnerContext = { tenantId: "t1", userId: "u1", connectionId: "c1", provider: "google", externalCalendarId: "primary" };
|
|
const now = new Date("2026-07-01T12:00:00Z");
|
|
|
|
function event(overrides: Partial<NeutralEvent> = {}): NeutralEvent {
|
|
return {
|
|
externalId: "ext-1",
|
|
isActive: true,
|
|
title: "Kundentermin",
|
|
description: "Details",
|
|
location: "Berlin",
|
|
startsAt: new Date("2026-07-02T09:00:00Z"),
|
|
endsAt: new Date("2026-07-02T10:00:00Z"),
|
|
isAllDay: false,
|
|
timeZone: "Europe/Berlin",
|
|
recurrenceRule: null,
|
|
attendees: [{ email: "kunde@example.com", status: "accepted" }],
|
|
etag: "etag-1",
|
|
lastModifiedExternal: new Date("2026-07-01T11:00:00Z"),
|
|
isBusy: true,
|
|
...overrides,
|
|
};
|
|
}
|
|
|
|
describe("toExternalEventFields", () => {
|
|
it("maps an active event to an external-synced cache row", () => {
|
|
const fields = toExternalEventFields(event(), ctx, now);
|
|
expect(fields.source).toBe("external_synced");
|
|
expect(fields.provider).toBe("google");
|
|
expect(fields.externalEventId).toBe("ext-1");
|
|
expect(fields.externalCalendarId).toBe("primary");
|
|
expect(fields.isBusyForAvailability).toBe(true);
|
|
expect(fields.archivedAt).toBeNull();
|
|
expect(fields.tenantId).toBe("t1");
|
|
expect(fields.userId).toBe("u1");
|
|
});
|
|
|
|
it("soft-archives and de-busies a cancelled event", () => {
|
|
const fields = toExternalEventFields(event({ isActive: false }), ctx, now);
|
|
expect(fields.archivedAt).toEqual(now);
|
|
expect(fields.isBusyForAvailability).toBe(false);
|
|
});
|
|
|
|
it("carries the Free flag through (provider transparency)", () => {
|
|
const fields = toExternalEventFields(event({ isBusy: false }), ctx, now);
|
|
expect(fields.isBusyForAvailability).toBe(false);
|
|
expect(fields.archivedAt).toBeNull();
|
|
});
|
|
});
|