import { describe, expect, it } from "vitest"; import { projectApiOperationRows } from "../../src/contracts/api-operations.ts"; import { composeContractContributions } from "../../src/contracts/external-contract-runtime.ts"; import { API_OPERATIONS, COMPOSED_CONTRACT_CONTRIBUTIONS, } from "../../src/features/loaded-feature-runtimes.ts"; import { TEST_CONTRACT_CONTRIBUTION, TEST_LIST_HTTP_CONTRACT, } from "../helpers/external-contract-fixture.ts"; /** * FE-REG-API rows are projected from the installed HTTP descriptors, so an * operation is written once and the governed row cannot disagree with what * executes. */ describe("FE-REG-API rows projected from HTTP descriptors", () => { it("projects each descriptor with its feature, wire and schema identities", () => { const rows = projectApiOperationRows( composeContractContributions([TEST_CONTRACT_CONTRIBUTION]).contributions, ); expect(Object.keys(rows)).toEqual([ "TEST_LIST_ENTITIES", "TEST_GET_ENTITY", "TEST_CREATE_ENTITY", ]); expect(rows.TEST_LIST_ENTITIES).toEqual({ operationId: "TEST_LIST_ENTITIES", featureId: "test-feature", method: "GET", path: "/api/test-entities", authProfileId: "ANONYMOUS", retrySemantics: "SAFE", requestBody: "NONE", responseBody: "REQUIRED_JSON", responseEnvelope: "NONE", requestSchema: "TestEntityListQuery", responseSchema: "TestEntityListPayload", problemSchema: "TestProblem", }); expect(rows.TEST_CREATE_ENTITY).toMatchObject({ method: "POST", retrySemantics: "KEYED", requestBody: "JSON", }); }); it("carries an Envelope declaration", () => { const rows = projectApiOperationRows( composeContractContributions([ { ...TEST_CONTRACT_CONTRIBUTION, http: [ { ...TEST_LIST_HTTP_CONTRACT, contract: { ...TEST_LIST_HTTP_CONTRACT.contract, responseEnvelope: "ENVELOPE_V1" as const, }, }, ] as never, }, ]).contributions, ); expect(rows.TEST_LIST_ENTITIES?.responseEnvelope).toBe("ENVELOPE_V1"); }); it("is what the registry governance reads for the installed features", () => { expect(API_OPERATIONS).toEqual( projectApiOperationRows(COMPOSED_CONTRACT_CONTRIBUTIONS.contributions), ); expect(Object.keys(API_OPERATIONS).sort()).toEqual( [...COMPOSED_CONTRACT_CONTRIBUTIONS.httpByOperationId.keys()].sort(), ); }); });