Per Plan 9 (spec R1-R28): - Use cases: input + output schemas (signIn, signUp); input-only for signOut (void output). Use case body validates output via outputSchema.parse before returning. - Controllers: receive `unknown`; safeParse with the use-case schema; presenter (returning cookie) for signIn/signUp; void return for signOut. - New integrations/api/procedures.ts with authProcedure built via defineErrorMiddleware([[InputParseError,"BAD_REQUEST"], [AuthenticationError,"UNAUTHORIZED"], [UnauthenticatedError, "UNAUTHORIZED"], [UnauthorizedError,"FORBIDDEN"]]). - Router uses authProcedure + .input(xInputSchema) for every procedure. - src/index.ts exports schemas + types + IUseCase/IController aliases. - package.json gains ./ui subpath; src/ui/index.ts placeholder (auth has no query builders today). - New tests: R25 output-validation per use case (signIn, signUp); R26 router error-mapping (UNAUTHORIZED on missing user, BAD_REQUEST on schema fail). Refactor log: §1, §2, §3.1, §3.2, §3.3, §5.1, §5.2, §6.1, §6.2 Spec: R1–R6, R8–R15, R18, R19, R22–R26
45 lines
2.0 KiB
TypeScript
45 lines
2.0 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));
|
|
|
|
// signUp returns a cookie (presenter shape)
|
|
const signUpCookie = await signUp({
|
|
username: "newperson",
|
|
password: "verysecret",
|
|
confirmPassword: "verysecret",
|
|
});
|
|
expect(signUpCookie.name).toBe("session");
|
|
expect(signUpCookie.value).toBeTruthy();
|
|
|
|
const signInCookie = await signIn({
|
|
username: "newperson",
|
|
password: "verysecret",
|
|
});
|
|
expect(signInCookie.name).toBe("session");
|
|
expect(signInCookie.value).toBeTruthy();
|
|
|
|
// signOut takes { sessionId } and returns void
|
|
const signOutResult = await signOut({ sessionId: signInCookie.value });
|
|
expect(signOutResult).toBeUndefined();
|
|
});
|
|
});
|