- Use cases (sign-in, sign-up, sign-out) → factory functions with I*UseCase aliases - Controllers → factory functions with I*Controller aliases - DI symbols + module updated with .toDynamicValue() bindings for factories - New: real UsersRepository (Payload-backed, SanitizedConfig, contract-tested) - New: real AuthenticationService (node:crypto hashing/UUIDs; createSession/ validateSession/invalidateSession deferred — see refactor log §7) - bindProductionAuth swaps both mocks for real impls (was a no-op before) - Tests refactored to construct mocks and inject directly (no container rebinding) - Feature test constructs full chain via direct factory injection Refactor log: §2, §4.1, §4.2, §5.1, §5.2, §6.1, §7 Spec: §6.1, §7 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
48 lines
1.8 KiB
TypeScript
48 lines
1.8 KiB
TypeScript
import { describe, it, expect } from "vitest";
|
|
import { signInController } from "@/interface-adapters/controllers/sign-in.controller";
|
|
import { MockUsersRepository } from "@/infrastructure/repositories/users.repository.mock";
|
|
import { MockAuthenticationService } from "@/infrastructure/services/authentication.service.mock";
|
|
import { signInUseCase } from "@/application/use-cases/sign-in.use-case";
|
|
import { InputParseError } from "@/entities/errors/common";
|
|
import { userFactory } from "@/__factories__/user.factory";
|
|
|
|
describe("signInController", () => {
|
|
it("returns a cookie on valid credentials", async () => {
|
|
const users = new MockUsersRepository([]);
|
|
const auth = new MockAuthenticationService(users);
|
|
const seedUser = userFactory.build({
|
|
username: "alice",
|
|
passwordHash: "hashed_testpassword",
|
|
});
|
|
await users.createUser(seedUser);
|
|
|
|
const useCase = signInUseCase(users, auth);
|
|
const controller = signInController(useCase);
|
|
|
|
const cookie = await controller({ username: "alice", password: "testpassword" });
|
|
expect(cookie.name).toBe("session");
|
|
});
|
|
|
|
it("throws InputParseError on missing username", async () => {
|
|
const users = new MockUsersRepository([]);
|
|
const auth = new MockAuthenticationService(users);
|
|
const useCase = signInUseCase(users, auth);
|
|
const controller = signInController(useCase);
|
|
|
|
await expect(
|
|
controller({ password: "anything" }),
|
|
).rejects.toBeInstanceOf(InputParseError);
|
|
});
|
|
|
|
it("throws InputParseError on too-short password", async () => {
|
|
const users = new MockUsersRepository([]);
|
|
const auth = new MockAuthenticationService(users);
|
|
const useCase = signInUseCase(users, auth);
|
|
const controller = signInController(useCase);
|
|
|
|
await expect(
|
|
controller({ username: "alice", password: "abc" }),
|
|
).rejects.toBeInstanceOf(InputParseError);
|
|
});
|
|
});
|