feat: 기능 추가 과정중
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import {
|
||||
validateEnvelope,
|
||||
validateOperationPayload,
|
||||
validateOperationRequest,
|
||||
} from "../../src/adapters/http/schema-registry.ts";
|
||||
import {
|
||||
composeRuntimeSchemaCodecs,
|
||||
validateWithRuntimeSchemaRegistry,
|
||||
} from "../../src/contracts/schema-registry.ts";
|
||||
|
||||
describe("HTTP platform schema boundary", () => {
|
||||
it("rejects an invalid top-level envelope", () => {
|
||||
expect(validateEnvelope({ success: true }).success).toBe(false);
|
||||
});
|
||||
|
||||
it("accepts and clones a generic valid response envelope", () => {
|
||||
const source = {
|
||||
success: true,
|
||||
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("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);
|
||||
});
|
||||
});
|
||||
|
||||
describe("runtime schema codec contribution", () => {
|
||||
const codec = {
|
||||
schemaId: "Example",
|
||||
parse: (value: unknown) => ({ success: true as const, data: value }),
|
||||
};
|
||||
|
||||
it("resolves installed codecs and fails missing IDs closed", () => {
|
||||
const registry = composeRuntimeSchemaCodecs([{ Example: codec }]);
|
||||
expect(validateWithRuntimeSchemaRegistry("Example", 42, registry)).toEqual({
|
||||
success: true,
|
||||
data: 42,
|
||||
});
|
||||
expect(
|
||||
validateWithRuntimeSchemaRegistry("Missing", 42, registry),
|
||||
).toMatchObject({
|
||||
success: false,
|
||||
issues: [{ code: "SCHEMA_NOT_REGISTERED" }],
|
||||
});
|
||||
});
|
||||
|
||||
it("rejects duplicate codec contributions", () => {
|
||||
expect(() =>
|
||||
composeRuntimeSchemaCodecs([{ Example: codec }, { Example: codec }]),
|
||||
).toThrow("duplicate runtime schema codec");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user