import { expect, it } from "bun:test"; import { checkProjectCapabilities, requiredProjectCapabilities } from "../src/lib/project-capabilities"; const url = "https://velum.invalid/api/project-capabilities"; const reply = (value: unknown) => async () => Response.json(value); it("reproduziert die alte Meldung: Textprojekt benötigt keine Office-Fähigkeiten", async () => { const olderBackend = { request_force_masks: true, document_hit_review: true, document_restoration: true }; await checkProjectCapabilities(url, false, reply(olderBackend)); await expect(checkProjectCapabilities(url, true, reply(olderBackend))).rejects.toThrow("document_review_mapping"); }); it("prüft jede Office-Schutzfunktion strikt, einschließlich Bilder und Autoren", async () => { const complete = Object.fromEntries(requiredProjectCapabilities(true).map((key) => [key, true])); await checkProjectCapabilities(url, true, reply(complete)); for (const key of Object.keys(complete)) { const missing = { ...complete }; delete missing[key]; await expect(checkProjectCapabilities(url, true, reply(missing))).rejects.toThrow(key); await expect(checkProjectCapabilities(url, true, reply({ ...complete, [key]: "true" }))).rejects.toThrow(key); } }); it("unterscheidet fehlende Endpunkte, Anmeldung, Größenlimits und Gateway-Fehler", async () => { for (const status of [401, 403, 404, 405, 413, 502, 504]) { await expect(checkProjectCapabilities(url, false, async () => new Response("", { status }))) .rejects.toThrow(`HTTP ${status}`); } await expect(checkProjectCapabilities(url, false, async () => new Response("Login", { headers: { "content-type": "text/html" }, }))).rejects.toThrow("Keine JSON-Antwort"); }); it("meldet URL, fehlende Fähigkeit, ungültige Antwort und Zeitlimit", async () => { await expect(checkProjectCapabilities(url, false, reply({}))).rejects.toThrow("request_force_masks"); for (const value of [null, [], true]) await expect(checkProjectCapabilities(url, false, reply(value))) .rejects.toThrow("Ungültige Projektfähigkeiten"); await expect(checkProjectCapabilities(url, false, async (_url, init) => { expect(init.signal).toBeDefined(); throw new DOMException("Deadline", "TimeoutError"); })).rejects.toThrow("Zeitlimit"); }); it("reproduziert die Live-API vom 8. November ohne document_image_policy", async () => { const live = { request_force_masks: true, document_hit_review: true, document_review_mapping: true, document_restoration: true, comment_author_review: true, revision_author_review: true }; await checkProjectCapabilities(url, false, reply(live)); await expect(checkProjectCapabilities(url, true, reply(live))).rejects.toThrow("document_image_policy"); });