feat: validate HTTP envelopes and payload schemas

This commit is contained in:
donghyeon-ka
2026-07-25 20:51:27 +09:00
parent 0934de44c7
commit bf813f09ab
4 changed files with 232 additions and 17 deletions
+31
View File
@@ -68,4 +68,35 @@ describe("shared HTTP client", () => {
});
expect(JSON.stringify(result)).not.toContain("raw body");
});
it("classifies malformed JSON and invalid payloads at the boundary", async () => {
server.use(
http.get(
"https://api.test/api/sample/resources",
() =>
new HttpResponse("{", {
headers: { "Content-Type": "application/json" },
}),
),
);
const client = createHttpClient({ baseUrl: "https://api.test", clock });
await expect(client.execute("LIST_SAMPLE_RESOURCES")).resolves.toMatchObject({
ok: false,
error: { kind: "MALFORMED_JSON" },
});
server.use(
http.get("https://api.test/api/sample/resources", () =>
HttpResponse.json({
success: true,
data: [{ id: "resource-1", name: 42 }],
meta: { requestId: "request-1", traceId: "trace-1" },
}),
),
);
await expect(client.execute("LIST_SAMPLE_RESOURCES")).resolves.toMatchObject({
ok: false,
error: { kind: "SCHEMA_MISMATCH" },
});
});
});