diff --git a/src/contracts/api-operations.ts b/src/contracts/api-operations.ts index ae9bc4c3..ca1eb2d1 100644 --- a/src/contracts/api-operations.ts +++ b/src/contracts/api-operations.ts @@ -131,14 +131,13 @@ function commandEffectRow( effect: CommandEffectDescriptor | null, ): ApiCommandEffectRow | null { if (effect === null) return null; - // Read structurally: a descriptor that does not name refused codes has no - // such list, and the row then has no such field. - const refused: unknown = (effect as Readonly<{ refusedBeforeWrite?: unknown }>) - .refusedBeforeWrite; + // A descriptor that does not name refused codes has no such list, and the + // row then has no such field. + const refused = effect.refusedBeforeWrite; return Object.freeze({ classifiesStatus: typeof effect.classifyStatus === "function", - ...(Array.isArray(refused) - ? { refusedBeforeWrite: Object.freeze(refused.map(String)) } - : {}), + ...(refused === undefined + ? {} + : { refusedBeforeWrite: Object.freeze([...refused]) }), }); } diff --git a/tests/unit/api-operation-rows.test.ts b/tests/unit/api-operation-rows.test.ts index fc597cd5..29c72e8c 100644 --- a/tests/unit/api-operation-rows.test.ts +++ b/tests/unit/api-operation-rows.test.ts @@ -105,9 +105,11 @@ describe("FE-REG-API rows projected from HTTP descriptors", () => { contract: { ...TEST_CLASSIFIED_CREATE_HTTP_CONTRACT.contract, // A descriptor that names the codes refused before any write. + // Only an Envelope operation may name them. + responseEnvelope: "ENVELOPE_V1" as const, commandEffect: { ...TEST_CLASSIFIED_CREATE_HTTP_CONTRACT.contract.commandEffect, - refusedBeforeWrite: ["VALIDATION_FAILED", "CONFLICT"], + refusedBeforeWrite: ["TEST_ENTITY_INVALID", "TEST_ENTITY_ALREADY_EXISTS"], }, }, }, @@ -122,7 +124,7 @@ describe("FE-REG-API rows projected from HTTP descriptors", () => { }); expect(rows.TEST_CREATE_ENTITY?.commandEffect).toEqual({ classifiesStatus: true, - refusedBeforeWrite: ["VALIDATION_FAILED", "CONFLICT"], + refusedBeforeWrite: ["TEST_ENTITY_INVALID", "TEST_ENTITY_ALREADY_EXISTS"], }); });