Scaffold the workspaces feature package via pnpm turbo gen feature (single Workspace entity, getWorkspace use case) and hand-wire the aggregators: bindAll dispatcher (web-next), core-api app router, and workspace deps. Release-please registration reverted per the root-only versioning policy (AGENTS.md, ADR-027 retrofit). Pinned @trpc/server to the repo-wide 11.16.0 resolution so instanceof TRPCError checks share one module instance. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016j8z4VHjedXDTjEDNg7qHK
94 lines
2.9 KiB
TypeScript
94 lines
2.9 KiB
TypeScript
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
|
import { TRPCError } from "@trpc/server";
|
|
import { injectable } from "inversify";
|
|
import { workspacesContainer } from "@/di/container";
|
|
import { WorkspacesModule } from "@/di/module";
|
|
import { WORKSPACES_SYMBOLS } from "@/di/symbols";
|
|
import { getWorkspaceUseCase } from "@/application/use-cases/get-workspace.use-case";
|
|
import { getWorkspaceController } from "@/interface-adapters/controllers/get-workspace.controller";
|
|
import { workspacesRouter } from "@/integrations/api/router";
|
|
|
|
describe("workspacesRouter", () => {
|
|
beforeEach(() => {
|
|
workspacesContainer.unbindAll();
|
|
workspacesContainer.load(WorkspacesModule);
|
|
});
|
|
|
|
afterEach(() => {
|
|
workspacesContainer.unbindAll();
|
|
});
|
|
|
|
it("exposes the getWorkspace procedure", () => {
|
|
const names = Object.keys(workspacesRouter._def.procedures);
|
|
expect(names).toContain("getWorkspace");
|
|
});
|
|
|
|
it("getWorkspace returns the seeded workspace", async () => {
|
|
const caller = workspacesRouter.createCaller({});
|
|
const result = await caller.getWorkspace({ id: "seed-1" });
|
|
expect(result.id).toBe("seed-1");
|
|
});
|
|
});
|
|
|
|
describe("workspacesRouter (error mapping)", () => {
|
|
beforeEach(() => {
|
|
workspacesContainer.unbindAll();
|
|
workspacesContainer.load(WorkspacesModule);
|
|
});
|
|
|
|
afterEach(() => {
|
|
workspacesContainer.unbindAll();
|
|
});
|
|
|
|
it("translates InputParseError → BAD_REQUEST when extra fields are passed", async () => {
|
|
const caller = workspacesRouter.createCaller({});
|
|
try {
|
|
await caller.getWorkspace({
|
|
id: "seed-1",
|
|
unexpected: "field",
|
|
} as unknown as { id: string });
|
|
throw new Error("expected throw");
|
|
} catch (e) {
|
|
expect(e).toBeInstanceOf(TRPCError);
|
|
expect((e as TRPCError).code).toBe("BAD_REQUEST");
|
|
}
|
|
});
|
|
|
|
it("translates WorkspaceNotFoundError → NOT_FOUND when repository returns null", async () => {
|
|
@injectable()
|
|
class NullWorkspaceRepository {
|
|
async getWorkspace() {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
workspacesContainer.unbindAll();
|
|
workspacesContainer
|
|
.bind(WORKSPACES_SYMBOLS.IWorkspaceRepository)
|
|
.to(NullWorkspaceRepository);
|
|
workspacesContainer
|
|
.bind(WORKSPACES_SYMBOLS.IGetWorkspaceUseCase)
|
|
.toDynamicValue((ctx) =>
|
|
getWorkspaceUseCase(
|
|
ctx.container.get(WORKSPACES_SYMBOLS.IWorkspaceRepository),
|
|
),
|
|
);
|
|
workspacesContainer
|
|
.bind(WORKSPACES_SYMBOLS.IGetWorkspaceController)
|
|
.toDynamicValue((ctx) =>
|
|
getWorkspaceController(
|
|
ctx.container.get(WORKSPACES_SYMBOLS.IGetWorkspaceUseCase),
|
|
),
|
|
);
|
|
|
|
const caller = workspacesRouter.createCaller({});
|
|
try {
|
|
await caller.getWorkspace({ id: "anything" });
|
|
throw new Error("expected throw");
|
|
} catch (e) {
|
|
expect(e).toBeInstanceOf(TRPCError);
|
|
expect((e as TRPCError).code).toBe("NOT_FOUND");
|
|
}
|
|
});
|
|
});
|