core tests
This commit is contained in:
57
core/racing/application/use-cases/DriverStatsUseCase.test.ts
Normal file
57
core/racing/application/use-cases/DriverStatsUseCase.test.ts
Normal file
@@ -0,0 +1,57 @@
|
||||
import { describe, it, expect, vi } from 'vitest';
|
||||
import { DriverStatsUseCase, type DriverStats } from './DriverStatsUseCase';
|
||||
import type { ResultRepository } from '../../domain/repositories/ResultRepository';
|
||||
import type { StandingRepository } from '../../domain/repositories/StandingRepository';
|
||||
import type { DriverStatsRepository } from '../../domain/repositories/DriverStatsRepository';
|
||||
import type { Logger } from '@core/shared/domain/Logger';
|
||||
|
||||
describe('DriverStatsUseCase', () => {
|
||||
const mockResultRepository = {} as ResultRepository;
|
||||
const mockStandingRepository = {} as StandingRepository;
|
||||
const mockDriverStatsRepository = {
|
||||
getDriverStats: vi.fn(),
|
||||
} as unknown as DriverStatsRepository;
|
||||
const mockLogger = {
|
||||
debug: vi.fn(),
|
||||
} as unknown as Logger;
|
||||
|
||||
const useCase = new DriverStatsUseCase(
|
||||
mockResultRepository,
|
||||
mockStandingRepository,
|
||||
mockDriverStatsRepository,
|
||||
mockLogger
|
||||
);
|
||||
|
||||
it('should return driver stats when found', async () => {
|
||||
const mockStats: DriverStats = {
|
||||
rating: 1500,
|
||||
safetyRating: 4.5,
|
||||
sportsmanshipRating: 4.8,
|
||||
totalRaces: 10,
|
||||
wins: 2,
|
||||
podiums: 5,
|
||||
dnfs: 0,
|
||||
avgFinish: 3.5,
|
||||
bestFinish: 1,
|
||||
worstFinish: 8,
|
||||
consistency: 0.9,
|
||||
experienceLevel: 'Intermediate',
|
||||
overallRank: 42,
|
||||
};
|
||||
vi.mocked(mockDriverStatsRepository.getDriverStats).mockResolvedValue(mockStats);
|
||||
|
||||
const result = await useCase.getDriverStats('driver-1');
|
||||
|
||||
expect(result).toEqual(mockStats);
|
||||
expect(mockLogger.debug).toHaveBeenCalledWith('Getting stats for driver driver-1');
|
||||
expect(mockDriverStatsRepository.getDriverStats).toHaveBeenCalledWith('driver-1');
|
||||
});
|
||||
|
||||
it('should return null when stats are not found', async () => {
|
||||
vi.mocked(mockDriverStatsRepository.getDriverStats).mockResolvedValue(null);
|
||||
|
||||
const result = await useCase.getDriverStats('non-existent');
|
||||
|
||||
expect(result).toBeNull();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user