import { describe, expect, it } from "vitest"; import { commandMutationIdentity } from "../../src/contracts/server-state.ts"; import { TEST_CREATE_HTTP_CONTRACT, TEST_LIST_HTTP_CONTRACT, } from "../helpers/external-contract-fixture.ts"; /** * 1103/16-05, 1101/03-03. A mutation policy used to restate its command's * operation id and key requirement as free values. A misspelt id passed the * type check and the registries, and the executor refused every save before * sending, as a missing idempotency key. The policy now takes both from the * HTTP descriptor. */ describe("commandMutationIdentity", () => { it("takes the operation id and the key requirement from a KEYED descriptor", () => { expect(commandMutationIdentity(TEST_CREATE_HTTP_CONTRACT)).toEqual({ operationId: "TEST_CREATE_ENTITY", requiresIdempotencyKey: true, }); }); it.each(["NEVER", "IDEMPOTENT"] as const)( "sends no key for a %s command", (retrySemantics) => { expect( commandMutationIdentity({ contract: { ...TEST_CREATE_HTTP_CONTRACT.contract, retrySemantics }, }), ).toEqual({ operationId: "TEST_CREATE_ENTITY", requiresIdempotencyKey: false }); }, ); it("refuses a read descriptor", () => { expect(() => commandMutationIdentity(TEST_LIST_HTTP_CONTRACT)).toThrow( "commandMutationIdentity: TEST_LIST_ENTITIES is a GET; a mutation binds a write operation", ); }); });