import assert from "node:assert/strict"; import { test } from "vitest"; import { TECH_LOG_PUBLIC_CONTRIBUTION } from "../../../src/features/tech-log/contracts/tech-log-public-contract-contribution.ts"; /** * 종류마다 읽는 주소가 다르다. 이 대응이 어긋나면 화면이 다른 종류의 API 를 부른다. * *

실제로 그렇게 났다: 게이트웨이가 종류를 삼항으로 이어 붙여 마지막 else 가 남은 것을 다 * 받아 갔고, `/concepts/{slug}` 화면이 `/api/v1/public/questions/{slug}` 를 불러 404 를 받았다. * 계약 타입에는 `getPublicConcept` 이 있었지만 기여 목록에 등록되지 않아 부를 수도 없었다. * 삭제 경로에서 겪은 것과 같은 모양이다. */ const EXPECTED = { CASE: { operationId: "getPublicCase", path: "/api/v1/public/cases/{slug}" }, REFERENCE: { operationId: "getPublicReference", path: "/api/v1/public/references/{slug}" }, QUESTION: { operationId: "getPublicQuestion", path: "/api/v1/public/questions/{slug}" }, CONCEPT: { operationId: "getPublicConcept", path: "/api/v1/public/concepts/{slug}" }, } as const; test("문서 종류마다 자기 조회 주소가 있고 서로 겹치지 않는다", () => { const byId = new Map( TECH_LOG_PUBLIC_CONTRIBUTION.http.map((entry) => [entry.contract.operationId, entry]), ); const paths = new Set(); for (const [kind, expected] of Object.entries(EXPECTED)) { const installed = byId.get(expected.operationId); assert.ok(installed, `${kind} 를 읽는 ${expected.operationId} 가 기여 목록에 있어야 한다`); assert.equal(installed.contract.method, "GET"); assert.equal( installed.contract.pathTemplate, expected.path, `${kind} 는 자기 주소로 나가야 한다`, ); assert.ok(!paths.has(expected.path), `${kind} 가 다른 종류와 같은 주소를 쓴다`); paths.add(expected.path); } });