feat: add removable reference feature vertical slice
This commit is contained in:
@@ -6,49 +6,34 @@ import {
|
||||
validateOperationRequest,
|
||||
} from "../../src/adapters/http/schema-registry.js";
|
||||
|
||||
describe("HTTP runtime schema boundary", () => {
|
||||
describe("HTTP platform schema boundary", () => {
|
||||
it("rejects an invalid top-level envelope", () => {
|
||||
expect(validateEnvelope({ success: true }).success).toBe(false);
|
||||
});
|
||||
|
||||
it("rejects an invalid operation payload with safe issue metadata", () => {
|
||||
const result = validateOperationPayload("SampleResourceListPayload", [
|
||||
{ id: "resource-1", name: 42 },
|
||||
]);
|
||||
|
||||
expect(result).toMatchObject({
|
||||
success: false,
|
||||
issues: [{ path: "0.name" }],
|
||||
});
|
||||
expect(JSON.stringify(result)).not.toContain("resource-1");
|
||||
});
|
||||
|
||||
it("returns a deep-cloned additive-tolerant payload", () => {
|
||||
const source = [{ id: "resource-1", name: "Example", additive: "accepted" }];
|
||||
const result = validateOperationPayload("SampleResourceListPayload", source);
|
||||
|
||||
expect(result).toMatchObject({
|
||||
it("accepts and clones a generic valid response envelope", () => {
|
||||
const source = {
|
||||
success: true,
|
||||
data: [{ id: "resource-1", additive: "accepted" }],
|
||||
});
|
||||
if (!result.success) throw new Error("expected valid sample payload");
|
||||
data: [],
|
||||
meta: { requestId: "request-1", traceId: "trace-1" },
|
||||
};
|
||||
const result = validateEnvelope(source);
|
||||
expect(result).toMatchObject({ success: true, data: source });
|
||||
if (!result.success) throw new Error("expected valid envelope");
|
||||
expect(result.data).not.toBe(source);
|
||||
});
|
||||
|
||||
it("validates outbound commands before transport", () => {
|
||||
expect(
|
||||
validateOperationRequest("CreateSampleResourceCommand", { name: "" }).success,
|
||||
).toBe(false);
|
||||
expect(
|
||||
validateOperationRequest("CreateSampleResourceCommand", { name: "Example" })
|
||||
.success,
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it("fails closed for an unregistered schema", () => {
|
||||
expect(validateOperationPayload("UnknownPayload", {})).toMatchObject({
|
||||
success: false,
|
||||
issues: [{ code: "SCHEMA_NOT_REGISTERED" }],
|
||||
it("fails closed without leaking input when a feature schema is absent", () => {
|
||||
const result = validateOperationPayload("UnknownPayload", {
|
||||
secret: "not-projected",
|
||||
});
|
||||
expect(result).toMatchObject({
|
||||
success: false,
|
||||
issues: [{ path: "", code: "SCHEMA_NOT_REGISTERED" }],
|
||||
});
|
||||
expect(JSON.stringify(result)).not.toContain("not-projected");
|
||||
expect(
|
||||
validateOperationRequest("UnknownCommand", { name: "Example" }).success,
|
||||
).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user