Files
frontend/apps/dc/app/api/general-search/current-original/route.test.ts
T

23 lines
1.0 KiB
TypeScript

import { NextRequest } from "next/server";
import { describe, expect, it } from "vitest";
import { GET } from "./route";
const qr = "https://frontend.invalid/api/general-search/current-original?";
const query = new URLSearchParams({ fileSn: "file-1", revisionId: "rev-2" }).toString();
describe("previously issued revision QR links", () => {
it("sends the scanning browser to the public DC download with the exact file and revision", () => {
const response = GET(new NextRequest(qr + query));
expect(response.status).toBe(307);
expect(response.headers.get("Location")).toBe("/dc-service/api/v1/fileDownload?" + query);
expect(response.headers.get("Cache-Control")).toBe("no-store");
});
it.each([query + "&filePath=unexpected", query + "&revisionId=other", "revisionId=r2", "filePath=doc.pdf"])(
"rejects incomplete or ambiguous QR arguments (%s)", search => {
const response = GET(new NextRequest(qr + search));
expect(response.status).toBe(400);
expect(response.headers.has("Location")).toBe(false);
});
});