Convention now: <name>.repository.{ts,mock.ts,interface.ts}.
Renames .mock prefix to .mock suffix; drops .payload prefix from real
impls (canonical name = real impl); dot-separates the .repository
qualifier in interface filenames. Class names follow suit:
PayloadXRepository → XRepository; Mock* unchanged.
Refactor log: §1, §3
Spec: §9.1
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
53 lines
2.1 KiB
TypeScript
53 lines
2.1 KiB
TypeScript
// Feature-level test: sign-up, then sign-in with the new credentials, then sign-out.
|
|
|
|
import { beforeEach, describe, expect, it } from "vitest";
|
|
import { authContainer } from "../src/di/container";
|
|
import { AUTH_SYMBOLS } from "../src/di/symbols";
|
|
import { MockUsersRepository } from "../src/infrastructure/repositories/users.repository.mock";
|
|
import { MockAuthenticationService } from "../src/infrastructure/services/authentication.service.mock";
|
|
import type { IUsersRepository } from "../src/application/repositories/users.repository.interface";
|
|
import type { IAuthenticationService } from "../src/application/services/authentication.service.interface";
|
|
import { authRouter } from "../src/integrations/api/router";
|
|
|
|
describe("auth feature: sign-up → sign-in → sign-out", () => {
|
|
beforeEach(() => {
|
|
if (authContainer.isBound(AUTH_SYMBOLS.IUsersRepository)) {
|
|
authContainer.unbind(AUTH_SYMBOLS.IUsersRepository);
|
|
}
|
|
if (authContainer.isBound(AUTH_SYMBOLS.IAuthenticationService)) {
|
|
authContainer.unbind(AUTH_SYMBOLS.IAuthenticationService);
|
|
}
|
|
const usersRepo = new MockUsersRepository();
|
|
const authService = new MockAuthenticationService(usersRepo);
|
|
authContainer
|
|
.bind<IUsersRepository>(AUTH_SYMBOLS.IUsersRepository)
|
|
.toConstantValue(usersRepo);
|
|
authContainer
|
|
.bind<IAuthenticationService>(AUTH_SYMBOLS.IAuthenticationService)
|
|
.toConstantValue(authService);
|
|
});
|
|
|
|
it("a new user can sign up, then sign in, then sign out", async () => {
|
|
const caller = authRouter.createCaller({});
|
|
|
|
const signUpResult = await caller.signUp({
|
|
username: "newperson",
|
|
password: "verysecret",
|
|
confirmPassword: "verysecret",
|
|
});
|
|
expect(signUpResult.user.username).toBe("newperson");
|
|
const userId = signUpResult.user.id;
|
|
|
|
const signInCookie = await caller.signIn({
|
|
username: "newperson",
|
|
password: "verysecret",
|
|
});
|
|
expect(signInCookie.value).toBe("session_" + userId);
|
|
|
|
const signOutResult = await caller.signOut({
|
|
sessionId: signInCookie.value,
|
|
});
|
|
expect(signOutResult.value).toBe("");
|
|
});
|
|
});
|