Files
HiveGrid-Wireframes/03 Quellen und Referenzen/hivegrid-cloud/apps/web/app/modules/booking/services/ics.test.ts
T
2026-07-08 16:15:37 +02:00

50 lines
1.9 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { buildIcs, icsToBase64 } from "./ics";
const base = {
uid: "appt-123@hivegrid",
start: new Date("2026-07-01T09:00:00Z"),
end: new Date("2026-07-01T10:00:00Z"),
dtstamp: new Date("2026-06-30T12:00:00Z"),
summary: "Wartungstermin",
};
describe("buildIcs (RFC 5545 minimal)", () => {
it("emits a single VEVENT with UTC timestamps + CRLF endings", () => {
const ics = buildIcs(base);
expect(ics).toContain("BEGIN:VCALENDAR");
expect(ics).toContain("BEGIN:VEVENT");
expect(ics).toContain("UID:appt-123@hivegrid");
expect(ics).toContain("DTSTART:20260701T090000Z");
expect(ics).toContain("DTEND:20260701T100000Z");
expect(ics).toContain("DTSTAMP:20260630T120000Z");
expect(ics).toContain("SUMMARY:Wartungstermin");
expect(ics).toContain("END:VCALENDAR");
expect(ics).toContain("\r\n");
});
it("escapes TEXT special chars (comma, semicolon, newline, backslash)", () => {
const ics = buildIcs({ ...base, summary: "A, B; C\\D", description: "line1\nline2" });
expect(ics).toContain("SUMMARY:A\\, B\\; C\\\\D");
expect(ics).toContain("DESCRIPTION:line1\\nline2");
});
it("includes organizer + attendee when provided", () => {
const ics = buildIcs({ ...base, organizerEmail: "host@acme.de", organizerName: "Acme GmbH", attendeeEmail: "kunde@example.com" });
expect(ics).toContain("ORGANIZER;CN=Acme GmbH:mailto:host@acme.de");
expect(ics).toContain("ATTENDEE;ROLE=REQ-PARTICIPANT:mailto:kunde@example.com");
});
it("omits optional fields when absent", () => {
const ics = buildIcs(base);
expect(ics).not.toContain("DESCRIPTION:");
expect(ics).not.toContain("LOCATION:");
expect(ics).not.toContain("ORGANIZER");
});
it("base64-encodes round-trippable content", () => {
const ics = buildIcs(base);
expect(Buffer.from(icsToBase64(ics), "base64").toString("utf8")).toEqual(ics);
});
});