feat(auth): add signOutUseCase (test red until DI lands)
This commit is contained in:
@@ -0,0 +1,36 @@
|
|||||||
|
import { beforeEach, describe, expect, it } from "vitest";
|
||||||
|
import { authContainer } from "@/di/container";
|
||||||
|
import { AUTH_SYMBOLS } from "@/di/symbols";
|
||||||
|
import { MockUsersRepository } from "@/infrastructure/repositories/mock-users.repository";
|
||||||
|
import { MockAuthenticationService } from "@/infrastructure/services/mock-authentication.service";
|
||||||
|
import type { IUsersRepository } from "@/application/repositories/users-repository.interface";
|
||||||
|
import type { IAuthenticationService } from "@/application/services/authentication-service.interface";
|
||||||
|
import { signOutUseCase } from "./sign-out.use-case";
|
||||||
|
|
||||||
|
describe("signOutUseCase", () => {
|
||||||
|
let usersRepo: MockUsersRepository;
|
||||||
|
let authService: MockAuthenticationService;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
if (authContainer.isBound(AUTH_SYMBOLS.IUsersRepository)) {
|
||||||
|
authContainer.unbind(AUTH_SYMBOLS.IUsersRepository);
|
||||||
|
}
|
||||||
|
if (authContainer.isBound(AUTH_SYMBOLS.IAuthenticationService)) {
|
||||||
|
authContainer.unbind(AUTH_SYMBOLS.IAuthenticationService);
|
||||||
|
}
|
||||||
|
usersRepo = new MockUsersRepository();
|
||||||
|
authService = new MockAuthenticationService(usersRepo);
|
||||||
|
authContainer
|
||||||
|
.bind<IUsersRepository>(AUTH_SYMBOLS.IUsersRepository)
|
||||||
|
.toConstantValue(usersRepo);
|
||||||
|
authContainer
|
||||||
|
.bind<IAuthenticationService>(AUTH_SYMBOLS.IAuthenticationService)
|
||||||
|
.toConstantValue(authService);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("returns a blank cookie", async () => {
|
||||||
|
const result = await signOutUseCase("session_1");
|
||||||
|
expect(result.blankCookie.name).toBe("session");
|
||||||
|
expect(result.blankCookie.value).toBe("");
|
||||||
|
});
|
||||||
|
});
|
||||||
13
packages/auth/src/application/use-cases/sign-out.use-case.ts
Normal file
13
packages/auth/src/application/use-cases/sign-out.use-case.ts
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
import type { Cookie } from "../../entities/cookie";
|
||||||
|
import { authContainer } from "../../di/container";
|
||||||
|
import { AUTH_SYMBOLS } from "../../di/symbols";
|
||||||
|
import type { IAuthenticationService } from "../services/authentication-service.interface";
|
||||||
|
|
||||||
|
export async function signOutUseCase(
|
||||||
|
sessionId: string,
|
||||||
|
): Promise<{ blankCookie: Cookie }> {
|
||||||
|
const authService = authContainer.get<IAuthenticationService>(
|
||||||
|
AUTH_SYMBOLS.IAuthenticationService,
|
||||||
|
);
|
||||||
|
return await authService.invalidateSession(sessionId);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user