refactor(navigation): factory-style use case + controller
- Use case (get-header) → factory function with IGetHeaderUseCase alias - Controller renamed header.controller.ts → get-header.controller.ts (verb-noun); converted to factory function with IGetHeaderController alias - DI module wires factories with .toDynamicValue() - tRPC router resolves controller via container - Use case + controller tests refactored to direct factory injection (no container rebinding) - container.test.ts verifies IGetHeaderUseCase + IGetHeaderController symbols Refactor log: §1, §4.1, §4.2, §5.1 Spec: §6.4 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,20 +1,7 @@
|
||||
import { beforeEach, describe, expect, it } from "vitest";
|
||||
import { navigationContainer } from "@/di/container";
|
||||
import { NAVIGATION_SYMBOLS } from "@/di/symbols";
|
||||
import { MockHeaderRepository } from "@/infrastructure/repositories/header.repository.mock";
|
||||
import type { IHeaderRepository } from "@/application/repositories/header.repository.interface";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { navigationRouter } from "./router";
|
||||
|
||||
describe("navigationRouter", () => {
|
||||
beforeEach(() => {
|
||||
if (navigationContainer.isBound(NAVIGATION_SYMBOLS.IHeaderRepository)) {
|
||||
navigationContainer.unbind(NAVIGATION_SYMBOLS.IHeaderRepository);
|
||||
}
|
||||
navigationContainer
|
||||
.bind<IHeaderRepository>(NAVIGATION_SYMBOLS.IHeaderRepository)
|
||||
.toConstantValue(new MockHeaderRepository());
|
||||
});
|
||||
|
||||
it("exposes header procedure", () => {
|
||||
const names = Object.keys(navigationRouter._def.procedures);
|
||||
expect(names).toContain("header");
|
||||
|
||||
@@ -1,8 +1,15 @@
|
||||
import { router, publicProcedure } from "@repo/core-shared/trpc/init";
|
||||
import { getHeaderController } from "../../interface-adapters/controllers/header.controller";
|
||||
import { navigationContainer } from "../../di/container";
|
||||
import { NAVIGATION_SYMBOLS } from "../../di/symbols";
|
||||
import type { IGetHeaderController } from "../../interface-adapters/controllers/get-header.controller";
|
||||
|
||||
export const navigationRouter = router({
|
||||
header: publicProcedure.query(() => getHeaderController()),
|
||||
header: publicProcedure.query(() => {
|
||||
const ctrl = navigationContainer.get<IGetHeaderController>(
|
||||
NAVIGATION_SYMBOLS.IGetHeaderController,
|
||||
);
|
||||
return ctrl();
|
||||
}),
|
||||
});
|
||||
|
||||
export type NavigationRouter = typeof navigationRouter;
|
||||
|
||||
Reference in New Issue
Block a user