- 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>
39 lines
1.5 KiB
TypeScript
39 lines
1.5 KiB
TypeScript
import { describe, it, expect } from "vitest";
|
|
import { createArticleController } from "@/interface-adapters/controllers/create-article.controller";
|
|
import { MockArticlesRepository } from "@/infrastructure/repositories/articles.repository.mock";
|
|
import { createArticleUseCase } from "@/application/use-cases/create-article.use-case";
|
|
import { InputParseError } from "@/entities/errors/common";
|
|
|
|
describe("createArticleController", () => {
|
|
it("creates an article on valid input", async () => {
|
|
const repo = new MockArticlesRepository();
|
|
const useCase = createArticleUseCase(repo);
|
|
const controller = createArticleController(useCase);
|
|
|
|
const result = await controller({ title: "Hello", content: "body", authorId: "u1" });
|
|
expect(result.title).toBe("Hello");
|
|
expect(result.slug).toBe("hello");
|
|
expect(result.status).toBe("draft");
|
|
});
|
|
|
|
it("throws InputParseError on missing title", async () => {
|
|
const repo = new MockArticlesRepository();
|
|
const useCase = createArticleUseCase(repo);
|
|
const controller = createArticleController(useCase);
|
|
|
|
await expect(
|
|
controller({ content: "body", authorId: "u1" }),
|
|
).rejects.toBeInstanceOf(InputParseError);
|
|
});
|
|
|
|
it("throws InputParseError on missing authorId", async () => {
|
|
const repo = new MockArticlesRepository();
|
|
const useCase = createArticleUseCase(repo);
|
|
const controller = createArticleController(useCase);
|
|
|
|
await expect(
|
|
controller({ title: "T" }),
|
|
).rejects.toBeInstanceOf(InputParseError);
|
|
});
|
|
});
|