feat: contain DTO mapping at the HTTP boundary

This commit is contained in:
donghyeon-ka
2026-07-25 21:02:06 +09:00
parent 3e126c0ddd
commit a9a7db0231
6 changed files with 178 additions and 8 deletions
+27 -1
View File
@@ -46,7 +46,7 @@ describe("shared HTTP client", () => {
client.execute("LIST_SAMPLE_RESOURCES", { routeId: "SAMPLE_RESOURCE_LIST" }),
).resolves.toMatchObject({
ok: true,
value: [{ id: "resource-1" }],
value: [{ id: "resource-1", displayName: "Example" }],
meta: { requestId: "request-1" },
});
expect(attempts).toBe(3);
@@ -99,4 +99,30 @@ describe("shared HTTP client", () => {
error: { kind: "SCHEMA_MISMATCH" },
});
});
it("guards mapper exceptions as UNKNOWN_FAILURE", async () => {
server.use(
http.get("https://api.test/api/sample/resources", () =>
HttpResponse.json({
success: true,
data: [{ id: "resource-1", name: "Example" }],
meta: { requestId: "request-1", traceId: "trace-1" },
}),
),
);
const client = createHttpClient({
baseUrl: "https://api.test",
clock,
mapPayload: () => {
throw new Error("raw mapper detail");
},
});
const result = await client.execute("LIST_SAMPLE_RESOURCES");
expect(result).toMatchObject({
ok: false,
error: { kind: "UNKNOWN_FAILURE" },
});
expect(JSON.stringify(result)).not.toContain("raw mapper detail");
});
});