Skip to content
File

Blob: tests/worker/protocol/carddav/addressbook-discovery.workers.test.ts

typescript48 lines
1import { describe, expect, it } from "vitest";
2 
3import { createDavFixture, davRequest } from "@tests/worker/helpers/dav";
4import { fetchWorker } from "@tests/worker/helpers/http";
5import { propfindBody } from "./helpers";
6 
7describe("CardDAV discovery", () => {
8 it("advertises CardDAV support with OPTIONS", async () => {
9 const fixture = await createDavFixture(["carddav.full"]);
10 const response = await fetchWorker(davRequest(fixture, "/addressbooks/", { method: "OPTIONS" }));
11 
12 expect(response.status).toBe(204);
13 expect(response.headers.get("allow")).toContain("REPORT");
14 expect(response.headers.get("dav")).toContain("addressbook");
15 });
16 
17 it("discovers the default address book", async () => {
18 const fixture = await createDavFixture(["carddav.full"]);
19 const response = await fetchWorker(
20 davRequest(fixture, "/addressbooks/", {
21 method: "PROPFIND",
22 headers: { depth: "1", "content-type": "application/xml" },
23 body: propfindBody("<D:resourcetype/><CARD:supported-address-data/><CS:getctag/>"),
24 }),
25 );
26 
27 expect(response.status).toBe(207);
28 const xml = await response.text();
29 expect(xml).toContain("/addressbooks/default/");
30 expect(xml).toContain("<CARD:addressbook");
31 expect(xml).toContain("supported-address-data");
32 expect(xml).toMatch(/<CS:getctag[^>]*>sync:\d+<\/CS:getctag>/);
33 });
34 
35 it("does not alias unknown address books to the default address book", async () => {
36 const fixture = await createDavFixture(["carddav.full"]);
37 const response = await fetchWorker(
38 davRequest(fixture, "/addressbooks/unknown/", {
39 method: "PROPFIND",
40 headers: { depth: "0", "content-type": "application/xml" },
41 body: propfindBody("<D:resourcetype/>"),
42 }),
43 );
44 
45 expect(response.status).toBe(404);
46 });
47});