59 lines
1.6 KiB
TypeScript
59 lines
1.6 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
|
|
import {
|
|
composeApiOperations,
|
|
defineRestOperation,
|
|
} from "../../src/contracts/api-operations.ts";
|
|
|
|
function operation(operationId = "GET_RESOURCE") {
|
|
return defineRestOperation({
|
|
contractVersion: 2,
|
|
protocol: "REST",
|
|
semantics: "QUERY",
|
|
method: "GET",
|
|
path: "/resources/{resourceId}",
|
|
operationId,
|
|
auth: "external-session",
|
|
timeoutMs: 5_000,
|
|
idempotency: "safe",
|
|
retry: "runtime",
|
|
replayPolicy: "SAFE",
|
|
idempotencyKeyPolicy: "NONE",
|
|
requestSource: "none",
|
|
requestSchema: "NoRequest",
|
|
responseSchema: "ResourcePayload",
|
|
mapperId: "ResourceMapper",
|
|
successStatuses: [200],
|
|
responseMediaTypes: ["application/json"],
|
|
maxResponseBytes: 32_768,
|
|
providerId: "PRIMARY_API",
|
|
authProfileId: "REFERENCE_EXTERNAL_BEARER",
|
|
csrfProfileId: "NO_CSRF_BEARER",
|
|
pathSchema: "ResourceParams",
|
|
pathParameterNames: ["resourceId"],
|
|
maxEncodedSearchBytes: 0,
|
|
owner: "test",
|
|
});
|
|
}
|
|
|
|
describe("REST operation v2 registry", () => {
|
|
it("rejects duplicate contributions before an object spread can overwrite them", () => {
|
|
const selected = operation();
|
|
expect(() =>
|
|
composeApiOperations([
|
|
{ GET_RESOURCE: selected },
|
|
{ GET_RESOURCE: selected },
|
|
]),
|
|
).toThrow("Duplicate API operation");
|
|
});
|
|
|
|
it("rejects an unsafe query/replay policy combination", () => {
|
|
expect(() =>
|
|
defineRestOperation({
|
|
...operation(),
|
|
method: "POST",
|
|
}),
|
|
).toThrow("Incoherent REST replay contract");
|
|
});
|
|
});
|