From 3770764ac5a229e378a5d94eacdc7d285620dc9d Mon Sep 17 00:00:00 2001 From: Danijel Martinek Date: Tue, 5 May 2026 07:58:53 +0200 Subject: [PATCH] =?UTF-8?q?test(auth):=20add=20feature=20test=20for=20sign?= =?UTF-8?q?-up=20=E2=86=92=20sign-in=20=E2=86=92=20sign-out=20flow?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/tests/sign-in-flow.feature.test.ts | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 packages/auth/tests/sign-in-flow.feature.test.ts diff --git a/packages/auth/tests/sign-in-flow.feature.test.ts b/packages/auth/tests/sign-in-flow.feature.test.ts new file mode 100644 index 0000000..b9d8998 --- /dev/null +++ b/packages/auth/tests/sign-in-flow.feature.test.ts @@ -0,0 +1,52 @@ +// 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/mock-users.repository"; +import { MockAuthenticationService } from "../src/infrastructure/services/mock-authentication.service"; +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(""); + }); +});