refactor
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
import { vi, type Mock } from 'vitest';
|
||||
import { GetCurrentSessionUseCase } from './GetCurrentSessionUseCase';
|
||||
import { User } from '../../domain/entities/User';
|
||||
import { IUserRepository, StoredUser } from '../../domain/repositories/IUserRepository';
|
||||
|
||||
describe('GetCurrentSessionUseCase', () => {
|
||||
let useCase: GetCurrentSessionUseCase;
|
||||
let mockUserRepo: {
|
||||
findByEmail: Mock;
|
||||
findById: Mock;
|
||||
create: Mock;
|
||||
update: Mock;
|
||||
emailExists: Mock;
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
mockUserRepo = {
|
||||
findByEmail: vi.fn(),
|
||||
findById: vi.fn(),
|
||||
create: vi.fn(),
|
||||
update: vi.fn(),
|
||||
emailExists: vi.fn(),
|
||||
};
|
||||
useCase = new GetCurrentSessionUseCase(mockUserRepo as IUserRepository);
|
||||
});
|
||||
|
||||
it('should return User when user exists', async () => {
|
||||
const userId = 'user-123';
|
||||
const storedUser: StoredUser = {
|
||||
id: userId,
|
||||
email: 'test@example.com',
|
||||
displayName: 'Test User',
|
||||
passwordHash: 'hash',
|
||||
salt: 'salt',
|
||||
primaryDriverId: 'driver-123',
|
||||
createdAt: new Date(),
|
||||
};
|
||||
mockUserRepo.findById.mockResolvedValue(storedUser);
|
||||
|
||||
const result = await useCase.execute(userId);
|
||||
|
||||
expect(mockUserRepo.findById).toHaveBeenCalledWith(userId);
|
||||
expect(result).toBeInstanceOf(User);
|
||||
expect(result?.getId().value).toBe(userId);
|
||||
expect(result?.getDisplayName()).toBe('Test User');
|
||||
});
|
||||
|
||||
it('should return null when user does not exist', async () => {
|
||||
const userId = 'user-123';
|
||||
mockUserRepo.findById.mockResolvedValue(null);
|
||||
|
||||
const result = await useCase.execute(userId);
|
||||
|
||||
expect(mockUserRepo.findById).toHaveBeenCalledWith(userId);
|
||||
expect(result).toBeNull();
|
||||
});
|
||||
});
|
||||
@@ -1,4 +1,5 @@
|
||||
import { User } from '../../domain/entities/User';
|
||||
import { IUserRepository } from '../../domain/repositories/IUserRepository';
|
||||
// No direct import of apps/api DTOs in core module
|
||||
|
||||
/**
|
||||
@@ -7,9 +8,13 @@ import { User } from '../../domain/entities/User';
|
||||
* Retrieves the current user session information.
|
||||
*/
|
||||
export class GetCurrentSessionUseCase {
|
||||
constructor(private userRepo: IUserRepository) {}
|
||||
|
||||
async execute(userId: string): Promise<User | null> {
|
||||
// TODO: Implement actual logic to retrieve user and session data
|
||||
console.warn('GetCurrentSessionUseCase: Method not implemented.');
|
||||
return null;
|
||||
const stored = await this.userRepo.findById(userId);
|
||||
if (!stored) {
|
||||
return null;
|
||||
}
|
||||
return User.fromStored(stored);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
import { User } from '../../domain/entities/User';
|
||||
|
||||
export interface LoginWithIracingCallbackParams {
|
||||
code: string;
|
||||
state?: string;
|
||||
returnTo?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Application Use Case: LoginWithIracingCallbackUseCase
|
||||
*
|
||||
* Handles the callback after iRacing authentication.
|
||||
*/
|
||||
export class LoginWithIracingCallbackUseCase {
|
||||
async execute(params: LoginWithIracingCallbackParams): Promise<User> {
|
||||
// TODO: Implement actual logic for handling iRacing OAuth callback
|
||||
console.warn('LoginWithIracingCallbackUseCase: Method not implemented.');
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
export interface IracingAuthRedirectResult {
|
||||
redirectUrl: string;
|
||||
state: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Application Use Case: StartIracingAuthRedirectUseCase
|
||||
*
|
||||
* Initiates the iRacing authentication flow.
|
||||
*/
|
||||
export class StartIracingAuthRedirectUseCase {
|
||||
async execute(returnTo?: string): Promise<IracingAuthRedirectResult> {
|
||||
// TODO: Implement actual logic for initiating iRacing OAuth redirect
|
||||
console.warn('StartIracingAuthRedirectUseCase: Method not implemented.');
|
||||
return {
|
||||
redirectUrl: '/mock-iracing-redirect',
|
||||
state: 'mock-state',
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import { Achievement, AchievementProps } from '@core/identity/domain/entities/Achievement';
|
||||
|
||||
export interface IAchievementRepository {
|
||||
save(achievement: Achievement): Promise<void>;
|
||||
findById(id: string): Promise<Achievement | null>;
|
||||
}
|
||||
|
||||
export class CreateAchievementUseCase {
|
||||
constructor(private readonly achievementRepository: IAchievementRepository) {}
|
||||
|
||||
async execute(props: Omit<AchievementProps, 'createdAt'>): Promise<Achievement> {
|
||||
const achievement = Achievement.create(props);
|
||||
await this.achievementRepository.save(achievement);
|
||||
return achievement;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user