This commit is contained in:
2025-12-21 19:53:22 +01:00
parent f2d8a23583
commit 3c64f328e2
105 changed files with 3191 additions and 1706 deletions

View File

@@ -5,21 +5,21 @@ import { SignupParams, LoginParams, AuthSessionDTO } from './dtos/AuthDto';
describe('AuthController', () => {
let controller: AuthController;
let service: ReturnType<typeof vi.mocked<AuthService>>;
let service: AuthService;
beforeEach(() => {
service = vi.mocked<AuthService>({
service = {
signupWithEmail: vi.fn(),
loginWithEmail: vi.fn(),
getCurrentSession: vi.fn(),
logout: vi.fn(),
});
} as unknown as AuthService;
controller = new AuthController(service);
});
describe('signup', () => {
it('should call service.signupWithEmail and return session', async () => {
it('should call service.signupWithEmail and return session DTO', async () => {
const params: SignupParams = {
email: 'test@example.com',
password: 'password123',
@@ -36,7 +36,7 @@ describe('AuthController', () => {
displayName: 'Test User',
},
};
service.signupWithEmail.mockResolvedValue(session);
(service.signupWithEmail as jest.Mock).mockResolvedValue(session);
const result = await controller.signup(params);
@@ -46,7 +46,7 @@ describe('AuthController', () => {
});
describe('login', () => {
it('should call service.loginWithEmail and return session', async () => {
it('should call service.loginWithEmail and return session DTO', async () => {
const params: LoginParams = {
email: 'test@example.com',
password: 'password123',
@@ -59,7 +59,7 @@ describe('AuthController', () => {
displayName: 'Test User',
},
};
service.loginWithEmail.mockResolvedValue(session);
(service.loginWithEmail as jest.Mock).mockResolvedValue(session);
const result = await controller.login(params);
@@ -69,7 +69,7 @@ describe('AuthController', () => {
});
describe('getSession', () => {
it('should call service.getCurrentSession and return session', async () => {
it('should call service.getCurrentSession and return session DTO', async () => {
const session: AuthSessionDTO = {
token: 'token123',
user: {
@@ -78,7 +78,7 @@ describe('AuthController', () => {
displayName: 'Test User',
},
};
service.getCurrentSession.mockResolvedValue(session);
(service.getCurrentSession as jest.Mock).mockResolvedValue(session);
const result = await controller.getSession();
@@ -87,7 +87,7 @@ describe('AuthController', () => {
});
it('should return null if no session', async () => {
service.getCurrentSession.mockResolvedValue(null);
(service.getCurrentSession as jest.Mock).mockResolvedValue(null);
const result = await controller.getSession();
@@ -96,13 +96,14 @@ describe('AuthController', () => {
});
describe('logout', () => {
it('should call service.logout', async () => {
service.logout.mockResolvedValue(undefined);
it('should call service.logout and return DTO', async () => {
const dto = { success: true };
(service.logout as jest.Mock).mockResolvedValue(dto);
await controller.logout();
const result = await controller.logout();
expect(service.logout).toHaveBeenCalled();
expect(result).toEqual(dto);
});
});
});