119 lines
3.9 KiB
TypeScript
119 lines
3.9 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import { test } from "vitest";
|
|
|
|
import { TECH_LOG_MANAGEMENT_CONTRIBUTION } from "../../../src/features/tech-log/contracts/tech-log-management-contract-contribution.ts";
|
|
|
|
/**
|
|
* 축(variant) CRUD 네 연산이 실제로 나가는 주소와 메서드.
|
|
*
|
|
* <p>계약에만 있고 기여 목록에 없으면 타입에는 멀쩡히 보이는데 부를 수가 없다. 축을 더할 때
|
|
* 정확히 그 상태였다 — 계약에 넷이 다 있는데 화면에서 하나도 부를 수 없었다.
|
|
*/
|
|
const EXPECTED = [
|
|
{ operationId: "listTopicVariants", method: "GET", path: "/api/v1/studio/topics/{id}/variants" },
|
|
{
|
|
operationId: "createTopicVariant",
|
|
method: "POST",
|
|
path: "/api/v1/studio/topics/{id}/variants",
|
|
},
|
|
{
|
|
operationId: "updateTopicVariant",
|
|
method: "PUT",
|
|
path: "/api/v1/studio/topics/{id}/variants/{variantId}",
|
|
},
|
|
{
|
|
operationId: "deleteTopicVariant",
|
|
method: "DELETE",
|
|
path: "/api/v1/studio/topics/{id}/variants/{variantId}",
|
|
},
|
|
] as const;
|
|
|
|
test("축 CRUD 네 연산이 자기 주소와 메서드로 등록되어 있다", () => {
|
|
const byId = new Map(
|
|
TECH_LOG_MANAGEMENT_CONTRIBUTION.http.map((entry) => [entry.contract.operationId, entry]),
|
|
);
|
|
|
|
for (const expected of EXPECTED) {
|
|
const installed = byId.get(expected.operationId);
|
|
assert.ok(installed, `${expected.operationId} 가 기여 목록에 있어야 한다`);
|
|
assert.equal(installed.contract.method, expected.method);
|
|
assert.equal(installed.contract.pathTemplate, expected.path);
|
|
}
|
|
});
|
|
|
|
/**
|
|
* 주소가 있는 것과 게이트웨이가 그것을 부르는 것은 다르다 — 삭제 경로에서 겪은 그대로다.
|
|
* 그래서 게이트웨이를 실제로 불러 어떤 연산이 어떤 인자로 나가는지 본다.
|
|
*/
|
|
test("게이트웨이가 축 연산을 주제 id 와 함께 부른다", async () => {
|
|
const { createHttpManagementGateway } = await import(
|
|
"../../../src/features/tech-log/adapters/http/http-management-gateway.ts"
|
|
);
|
|
|
|
const called: Array<{
|
|
operationId: string;
|
|
input: unknown;
|
|
idempotencyKey: string | undefined;
|
|
}> = [];
|
|
const gateway = createHttpManagementGateway({
|
|
http: {
|
|
execute: (
|
|
operationId: string,
|
|
input: unknown,
|
|
context: Readonly<{
|
|
intent?: Readonly<{ idempotencyKey?: string }>;
|
|
}>,
|
|
) => {
|
|
called.push({
|
|
operationId,
|
|
input,
|
|
idempotencyKey: context.intent?.idempotencyKey,
|
|
});
|
|
return Promise.resolve({ ok: true as const, value: [] });
|
|
},
|
|
},
|
|
} as never);
|
|
|
|
const topicId = "11111111-1111-4111-8111-111111111111";
|
|
const variantId = "22222222-2222-4222-8222-222222222222";
|
|
await gateway.listTopicVariants(topicId);
|
|
await gateway.createTopicVariant(
|
|
topicId,
|
|
{ slug: "bff", title: "BFF" },
|
|
{ idempotencyKey: "variant-create-test" },
|
|
);
|
|
await gateway.updateTopicVariant(
|
|
topicId,
|
|
variantId,
|
|
{ slug: "bff", title: "BFF" },
|
|
{ idempotencyKey: "variant-update-test" },
|
|
);
|
|
await gateway.deleteTopicVariant(
|
|
topicId,
|
|
variantId,
|
|
3,
|
|
{ idempotencyKey: "variant-delete-test" },
|
|
);
|
|
|
|
assert.deepEqual(
|
|
called.map((entry) => entry.operationId),
|
|
["listTopicVariants", "createTopicVariant", "updateTopicVariant", "deleteTopicVariant"],
|
|
);
|
|
// 경로가 주제를 요구한다. 주제 id 를 빠뜨리면 서버는 다른 주제의 축을 보게 된다.
|
|
for (const entry of called) {
|
|
assert.equal((entry.input as { id?: string }).id, topicId, entry.operationId);
|
|
}
|
|
for (const entry of called.slice(2)) {
|
|
assert.equal((entry.input as { variantId?: string }).variantId, variantId, entry.operationId);
|
|
}
|
|
assert.deepEqual(
|
|
called.map((entry) => entry.idempotencyKey),
|
|
[
|
|
undefined,
|
|
"variant-create-test",
|
|
"variant-update-test",
|
|
"variant-delete-test",
|
|
],
|
|
);
|
|
});
|