File
Blob: tests/worker/protocol/caldav/calendar-discovery.workers.test.ts
| 1 | import { describe, expect, it } from "vitest"; |
| 2 | |
| 3 | import { createDavFixture, davRequest } from "@tests/worker/helpers/dav"; |
| 4 | import { fetchWorker } from "@tests/worker/helpers/http"; |
| 5 | import { propfindBody } from "./helpers"; |
| 6 | |
| 7 | describe("CalDAV discovery", () => { |
| 8 | it("advertises CalDAV support with OPTIONS", async () => { |
| 9 | const fixture = await createDavFixture(["caldav.full"]); |
| 10 | const response = await fetchWorker(davRequest(fixture, "/calendars/", { method: "OPTIONS" })); |
| 11 | |
| 12 | expect(response.status).toBe(204); |
| 13 | expect(response.headers.get("allow")).toContain("REPORT"); |
| 14 | expect(response.headers.get("allow")).toContain("MKCOL"); |
| 15 | expect(response.headers.get("dav")).toContain("calendar-access"); |
| 16 | }); |
| 17 | |
| 18 | it("discovers the default calendar", async () => { |
| 19 | const fixture = await createDavFixture(["caldav.full"]); |
| 20 | const response = await fetchWorker( |
| 21 | davRequest(fixture, "/calendars/", { |
| 22 | method: "PROPFIND", |
| 23 | headers: { depth: "1", "content-type": "application/xml" }, |
| 24 | body: propfindBody( |
| 25 | "<D:resourcetype/><C:supported-calendar-data/><C:supported-calendar-component-set/><D:supported-report-set/><CS:getctag/>", |
| 26 | ), |
| 27 | }), |
| 28 | ); |
| 29 | |
| 30 | expect(response.status).toBe(207); |
| 31 | const xml = await response.text(); |
| 32 | expect(xml).toContain("/calendars/default/"); |
| 33 | expect(xml).toContain("<C:calendar"); |
| 34 | expect(xml).toContain("supported-calendar-data"); |
| 35 | expect(xml).toContain("calendar-query"); |
| 36 | expect(xml).toContain("calendar-multiget"); |
| 37 | expect(xml).toContain("sync-collection"); |
| 38 | expect(xml).toContain("<D:supported-report-set><D:supported-report>"); |
| 39 | expect(xml).not.toContain("<D:supported-report-set><D:supported-report-set>"); |
| 40 | expect(xml).toMatch(/<CS:getctag[^>]*>sync:\d+<\/CS:getctag>/); |
| 41 | }); |
| 42 | }); |