// 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(AUTH_SYMBOLS.IUsersRepository) .toConstantValue(usersRepo); authContainer .bind(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(""); }); });