30 lines
1.0 KiB
TypeScript
30 lines
1.0 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { problemInstance, problemResponse } from "./problem-response";
|
|
|
|
describe("problemResponse", () => {
|
|
it("uses the request path and query as the problem instance", () => {
|
|
expect(problemInstance(new Request("https://example.com/api/items?cursor=next")))
|
|
.toBe("/api/items?cursor=next");
|
|
});
|
|
|
|
it("returns RFC 9457 JSON with the required media type", async () => {
|
|
const response = problemResponse({
|
|
type: "urn:error:unauthorized",
|
|
title: "Unauthorized",
|
|
status: 401,
|
|
detail: "A valid Velocity server credential is required.",
|
|
instance: "/api/velocity/access",
|
|
});
|
|
|
|
expect(response.status).toBe(401);
|
|
expect(response.headers.get("content-type")).toBe("application/problem+json");
|
|
expect(await response.json()).toEqual({
|
|
type: "urn:error:unauthorized",
|
|
title: "Unauthorized",
|
|
status: 401,
|
|
detail: "A valid Velocity server credential is required.",
|
|
instance: "/api/velocity/access",
|
|
});
|
|
});
|
|
});
|