module cleanup

This commit is contained in:
2025-12-19 01:22:45 +01:00
parent d617654928
commit d0fac9e6c1
135 changed files with 5104 additions and 1315 deletions

View File

@@ -0,0 +1,108 @@
import { vi } from 'vitest';
import { AuthController } from './AuthController';
import { AuthService } from './AuthService';
import { SignupParams, LoginParams, AuthSessionDTO } from './dtos/AuthDto';
describe('AuthController', () => {
let controller: AuthController;
let service: ReturnType<typeof vi.mocked<AuthService>>;
beforeEach(() => {
service = vi.mocked<AuthService>({
signupWithEmail: vi.fn(),
loginWithEmail: vi.fn(),
getCurrentSession: vi.fn(),
logout: vi.fn(),
});
controller = new AuthController(service);
});
describe('signup', () => {
it('should call service.signupWithEmail and return session', async () => {
const params: SignupParams = {
email: 'test@example.com',
password: 'password123',
displayName: 'Test User',
iracingCustomerId: '12345',
primaryDriverId: 'driver1',
avatarUrl: 'http://example.com/avatar.jpg',
};
const session: AuthSessionDTO = {
token: 'token123',
user: {
userId: 'user1',
email: 'test@example.com',
displayName: 'Test User',
},
};
service.signupWithEmail.mockResolvedValue(session);
const result = await controller.signup(params);
expect(service.signupWithEmail).toHaveBeenCalledWith(params);
expect(result).toEqual(session);
});
});
describe('login', () => {
it('should call service.loginWithEmail and return session', async () => {
const params: LoginParams = {
email: 'test@example.com',
password: 'password123',
};
const session: AuthSessionDTO = {
token: 'token123',
user: {
userId: 'user1',
email: 'test@example.com',
displayName: 'Test User',
},
};
service.loginWithEmail.mockResolvedValue(session);
const result = await controller.login(params);
expect(service.loginWithEmail).toHaveBeenCalledWith(params);
expect(result).toEqual(session);
});
});
describe('getSession', () => {
it('should call service.getCurrentSession and return session', async () => {
const session: AuthSessionDTO = {
token: 'token123',
user: {
userId: 'user1',
email: 'test@example.com',
displayName: 'Test User',
},
};
service.getCurrentSession.mockResolvedValue(session);
const result = await controller.getSession();
expect(service.getCurrentSession).toHaveBeenCalled();
expect(result).toEqual(session);
});
it('should return null if no session', async () => {
service.getCurrentSession.mockResolvedValue(null);
const result = await controller.getSession();
expect(result).toBeNull();
});
});
describe('logout', () => {
it('should call service.logout', async () => {
service.logout.mockResolvedValue(undefined);
await controller.logout();
expect(service.logout).toHaveBeenCalled();
});
});
});