File
Blob: tests/worker/protocol/webdav/locks-helpers.ts
| 1 | import { expect } from "vitest"; |
| 2 | |
| 3 | import { createDavFixture, davRequest } from "@tests/worker/helpers/dav"; |
| 4 | import { fetchWorker } from "@tests/worker/helpers/http"; |
| 5 | |
| 6 | type DavFixture = Awaited<ReturnType<typeof createDavFixture>>; |
| 7 | |
| 8 | export function name(prefix: string): string { |
| 9 | return `${prefix}-${crypto.randomUUID()}`; |
| 10 | } |
| 11 | |
| 12 | export 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 | } |