- 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>
42 lines
1.9 KiB
TypeScript
42 lines
1.9 KiB
TypeScript
// Feature-level test: sign-up, then sign-in with the new credentials, then sign-out.
|
|
// Constructs the full chain via direct injection (no container rebinding).
|
|
|
|
import { describe, it, expect } from "vitest";
|
|
import { MockUsersRepository } from "../src/infrastructure/repositories/users.repository.mock";
|
|
import { MockAuthenticationService } from "../src/infrastructure/services/authentication.service.mock";
|
|
import { signInUseCase } from "../src/application/use-cases/sign-in.use-case";
|
|
import { signUpUseCase } from "../src/application/use-cases/sign-up.use-case";
|
|
import { signOutUseCase } from "../src/application/use-cases/sign-out.use-case";
|
|
import { signInController } from "../src/interface-adapters/controllers/sign-in.controller";
|
|
import { signUpController } from "../src/interface-adapters/controllers/sign-up.controller";
|
|
import { signOutController } from "../src/interface-adapters/controllers/sign-out.controller";
|
|
|
|
describe("auth feature: sign-up → sign-in → sign-out", () => {
|
|
it("a new user can sign up, then sign in, then sign out", async () => {
|
|
// Construct the full chain via direct injection
|
|
const users = new MockUsersRepository([]);
|
|
const auth = new MockAuthenticationService(users);
|
|
|
|
const signIn = signInController(signInUseCase(users, auth));
|
|
const signUp = signUpController(signUpUseCase(users, auth));
|
|
const signOut = signOutController(signOutUseCase(auth));
|
|
|
|
const signUpResult = await signUp({
|
|
username: "newperson",
|
|
password: "verysecret",
|
|
confirmPassword: "verysecret",
|
|
});
|
|
expect(signUpResult.user.username).toBe("newperson");
|
|
const userId = signUpResult.user.id;
|
|
|
|
const signInCookie = await signIn({
|
|
username: "newperson",
|
|
password: "verysecret",
|
|
});
|
|
expect(signInCookie.value).toBe("session_" + userId);
|
|
|
|
const signOutResult = await signOut(signInCookie.value);
|
|
expect(signOutResult.value).toBe("");
|
|
});
|
|
});
|