feat(auth): add sign-in/sign-up/sign-out controllers with Zod validation

This commit is contained in:
2026-05-05 07:19:19 +02:00
parent 2ad6b21f17
commit 29dea75a62
6 changed files with 210 additions and 0 deletions

View File

@@ -0,0 +1,50 @@
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 { InputParseError } from "@/entities/errors";
import { signUpController } from "./sign-up.controller";
describe("signUpController", () => {
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("creates a new user when passwords match", async () => {
const result = await signUpController({
username: "carol",
password: "secret_password",
confirmPassword: "secret_password",
});
expect(result.user.username).toBe("carol");
});
it("throws InputParseError when passwords do not match", async () => {
await expect(
signUpController({
username: "dave",
password: "secret_password",
confirmPassword: "different_password",
}),
).rejects.toBeInstanceOf(InputParseError);
});
});