Skip to content
File

Blob: tests/worker/protocol/webdav/locks-helpers.ts

typescript25 lines
1import { expect } from "vitest";
2 
3import { createDavFixture, davRequest } from "@tests/worker/helpers/dav";
4import { fetchWorker } from "@tests/worker/helpers/http";
5 
6type DavFixture = Awaited<ReturnType<typeof createDavFixture>>;
7 
8export function name(prefix: string): string {
9 return `${prefix}-${crypto.randomUUID()}`;
10}
11 
12export async function lock(fixture: DavFixture, path: string, depth = "0"): Promise<string> {
13 const response = await fetchWorker(
14 davRequest(fixture, path, {
15 method: "LOCK",
16 headers: { depth, timeout: "Second-600", "content-type": "application/xml" },
17 body: `<?xml version="1.0"?><D:lockinfo xmlns:D="DAV:"><D:lockscope><D:exclusive/></D:lockscope><D:locktype><D:write/></D:locktype><D:owner><D:href>mailto:test@example.test</D:href></D:owner></D:lockinfo>`,
18 }),
19 );
20 expect(response.status).toBe(200);
21 const token = response.headers.get("lock-token");
22 expect(token).toMatch(/^<opaquelocktoken:[^>]+>$/);
23 return token!;
24}