Per Plan 9 (spec R1-R28): - Use cases: input + output schemas (getArticles, createArticle, getArticleBySlug). Output validated via outputSchema.parse before return. status field uses articleStatusSchema (was loose `string`). - Controllers: receive `unknown`; safeParse with use-case schema; identity presenter (R11) on every controller. - New integrations/api/procedures.ts with blogProcedure ([InputParseError → BAD_REQUEST], [ArticleNotFoundError → NOT_FOUND]). - Router uses blogProcedure + .input(xInputSchema) for all 3 procedures. - src/index.ts: remove articleBySlugQuery/listArticlesQuery re-exports; export schemas + types + IUseCase/IController aliases. - src/ui/index.ts (NEW): query builders moved here; package.json adds ./ui subpath. - New tests: R25 output-validation per use case; R26 router error- mapping (NOT_FOUND on missing slug, BAD_REQUEST on schema fail). Refactor log: §1, §2, §3.1, §3.2, §3.3, §5.1, §5.2, §6.1, §6.2 Spec: R1–R6, R8–R15, R18–R20, R22–R26 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
40 lines
1.6 KiB
TypeScript
40 lines
1.6 KiB
TypeScript
import { describe, it, expect } from "vitest";
|
|
import { getArticleBySlugController } from "@/interface-adapters/controllers/get-article-by-slug.controller";
|
|
import { MockArticlesRepository } from "@/infrastructure/repositories/articles.repository.mock";
|
|
import { getArticleBySlugUseCase } from "@/application/use-cases/get-article-by-slug.use-case";
|
|
import { InputParseError } from "@/entities/errors/common";
|
|
import { ArticleNotFoundError } from "@/entities/errors/article";
|
|
import { articleFactory } from "@/__factories__/article.factory";
|
|
|
|
describe("getArticleBySlugController", () => {
|
|
it("returns article when slug exists", async () => {
|
|
const repo = new MockArticlesRepository();
|
|
const seed = articleFactory.build({ slug: "test-slug" });
|
|
await repo.createArticle(seed);
|
|
|
|
const useCase = getArticleBySlugUseCase(repo);
|
|
const controller = getArticleBySlugController(useCase);
|
|
|
|
const result = await controller({ slug: "test-slug" });
|
|
expect(result.slug).toBe("test-slug");
|
|
});
|
|
|
|
it("throws ArticleNotFoundError for missing slug", async () => {
|
|
const repo = new MockArticlesRepository();
|
|
const useCase = getArticleBySlugUseCase(repo);
|
|
const controller = getArticleBySlugController(useCase);
|
|
|
|
await expect(controller({ slug: "nope" })).rejects.toBeInstanceOf(ArticleNotFoundError);
|
|
});
|
|
|
|
it("throws InputParseError on empty slug", async () => {
|
|
const repo = new MockArticlesRepository();
|
|
const useCase = getArticleBySlugUseCase(repo);
|
|
const controller = getArticleBySlugController(useCase);
|
|
|
|
await expect(
|
|
controller({}),
|
|
).rejects.toBeInstanceOf(InputParseError);
|
|
});
|
|
});
|