Files
agentic-dev/packages/auth/src/application/use-cases/sign-up.use-case.test.ts
Danijel Martinek a4c4ca6b6e refactor(features): split entities into models/ + errors/ subdirs
All 5 features (auth, blog, marketing-pages, navigation; media has no
entities yet) now follow Lazar's pattern:
- entities/<x>.ts → entities/models/<x>.ts
- entities/errors.ts → entities/errors/<domain>.ts + errors/common.ts

Updates all import paths across factories, contracts, tests, use cases,
controllers, repositories, integrations, and src/index.ts exports.

navigation divergence: had no errors.ts; errors/header.ts +
errors/common.ts added as new forward-looking stubs.

Refactor log: docs/superpowers/refactor-logs/2026-05-05-lazar-pattern-conformance.md
Spec: §5, §9.3

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-05 23:34:32 +02:00

48 lines
1.9 KiB
TypeScript

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 { AuthenticationError } from "@/entities/errors/auth";
import { signUpUseCase } from "./sign-up.use-case";
describe("signUpUseCase", () => {
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 and returns session + cookie + user", async () => {
const result = await signUpUseCase({
username: "carol",
password: "secret_password",
});
expect(result.user.username).toBe("carol");
expect(result.session.userId).toBe(result.user.id);
expect(result.cookie.name).toBe("session");
});
it("throws AuthenticationError when username taken", async () => {
await expect(
signUpUseCase({ username: "alice", password: "secret_password" }),
).rejects.toBeInstanceOf(AuthenticationError);
});
});