test(auth): add feature test for sign-up → sign-in → sign-out flow
This commit is contained in:
52
packages/auth/tests/sign-in-flow.feature.test.ts
Normal file
52
packages/auth/tests/sign-in-flow.feature.test.ts
Normal file
@@ -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<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("");
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user