refactor(blog): factory-style use cases + per-use-case controllers + getArticleBySlug

- Use cases (create-article, get-articles, get-article-by-slug NEW) → factory functions
- Controllers split: articles.controller.ts → 3 single-responsibility files
- DI module wires factories with .toDynamicValue()
- tRPC router resolves controllers via container

Refactor log: §2, §3, §4.1, §4.2, §5.1
Spec: §6.2

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-06 00:08:15 +02:00
parent 780d5cb83b
commit 700d311052
21 changed files with 488 additions and 302 deletions

View File

@@ -0,0 +1,41 @@
import { describe, it, expect } from "vitest";
import { getArticlesController } from "@/interface-adapters/controllers/get-articles.controller";
import { MockArticlesRepository } from "@/infrastructure/repositories/articles.repository.mock";
import { getArticlesUseCase } from "@/application/use-cases/get-articles.use-case";
import { InputParseError } from "@/entities/errors/common";
import { articleFactory } from "@/__factories__/article.factory";
describe("getArticlesController", () => {
it("returns array on valid input", async () => {
const repo = new MockArticlesRepository();
const useCase = getArticlesUseCase(repo);
const controller = getArticlesController(useCase);
const result = await controller({});
expect(result).toEqual([]);
});
it("filters by status", async () => {
const repo = new MockArticlesRepository();
articleFactory.reset();
await repo.createArticle(articleFactory.build({ id: "1", slug: "a", status: "draft" }));
await repo.createArticle(articleFactory.build({ id: "2", slug: "b", status: "published" }));
const useCase = getArticlesUseCase(repo);
const controller = getArticlesController(useCase);
const result = await controller({ status: "published" });
expect(result).toHaveLength(1);
expect(result[0]?.id).toBe("2");
});
it("throws InputParseError on invalid input shape", async () => {
const repo = new MockArticlesRepository();
const useCase = getArticlesUseCase(repo);
const controller = getArticlesController(useCase);
await expect(
controller({ limit: "not a number" } as unknown as Record<string, unknown>),
).rejects.toBeInstanceOf(InputParseError);
});
});