import { describe, expect, it } from "vitest"; import { createDavFixture, davRequest } from "@tests/worker/helpers/dav"; import { fetchWorker } from "@tests/worker/helpers/http"; import { propfindBody } from "./helpers"; describe("CardDAV discovery", () => { it("advertises CardDAV support with OPTIONS", async () => { const fixture = await createDavFixture(["carddav.full"]); const response = await fetchWorker(davRequest(fixture, "/addressbooks/", { method: "OPTIONS" })); expect(response.status).toBe(204); expect(response.headers.get("allow")).toContain("REPORT"); expect(response.headers.get("dav")).toContain("addressbook"); }); it("discovers the default address book", async () => { const fixture = await createDavFixture(["carddav.full"]); const response = await fetchWorker( davRequest(fixture, "/addressbooks/", { method: "PROPFIND", headers: { depth: "1", "content-type": "application/xml" }, body: propfindBody(""), }), ); expect(response.status).toBe(207); const xml = await response.text(); expect(xml).toContain("/addressbooks/default/"); expect(xml).toContain("]*>sync:\d+<\/CS:getctag>/); }); it("does not alias unknown address books to the default address book", async () => { const fixture = await createDavFixture(["carddav.full"]); const response = await fetchWorker( davRequest(fixture, "/addressbooks/unknown/", { method: "PROPFIND", headers: { depth: "0", "content-type": "application/xml" }, body: propfindBody(""), }), ); expect(response.status).toBe(404); }); });