- 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>
40 lines
1.4 KiB
TypeScript
40 lines
1.4 KiB
TypeScript
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
|
import { blogContainer } from "./container";
|
|
import { BLOG_SYMBOLS } from "./symbols";
|
|
import { BlogModule } from "./module";
|
|
import { MockArticlesRepository } from "../infrastructure/repositories/articles.repository.mock";
|
|
import type { IArticlesRepository } from "../application/repositories/articles.repository.interface";
|
|
|
|
describe("blogContainer", () => {
|
|
beforeEach(() => {
|
|
blogContainer.unbindAll();
|
|
blogContainer.load(BlogModule);
|
|
});
|
|
|
|
afterEach(() => {
|
|
blogContainer.unbindAll();
|
|
});
|
|
|
|
it("resolves IArticlesRepository to MockArticlesRepository by default binding", () => {
|
|
const repo = blogContainer.get<IArticlesRepository>(
|
|
BLOG_SYMBOLS.IArticlesRepository,
|
|
);
|
|
expect(repo).toBeInstanceOf(MockArticlesRepository);
|
|
});
|
|
|
|
it("resolves IGetArticlesController from the container", () => {
|
|
const ctrl = blogContainer.get(BLOG_SYMBOLS.IGetArticlesController);
|
|
expect(typeof ctrl).toBe("function");
|
|
});
|
|
|
|
it("resolves ICreateArticleController from the container", () => {
|
|
const ctrl = blogContainer.get(BLOG_SYMBOLS.ICreateArticleController);
|
|
expect(typeof ctrl).toBe("function");
|
|
});
|
|
|
|
it("resolves IGetArticleBySlugController from the container", () => {
|
|
const ctrl = blogContainer.get(BLOG_SYMBOLS.IGetArticleBySlugController);
|
|
expect(typeof ctrl).toBe("function");
|
|
});
|
|
});
|