core tests
This commit is contained in:
59
core/racing/application/use-cases/RankingUseCase.test.ts
Normal file
59
core/racing/application/use-cases/RankingUseCase.test.ts
Normal file
@@ -0,0 +1,59 @@
|
||||
import { describe, it, expect, vi } from 'vitest';
|
||||
import { RankingUseCase, type DriverRanking } from './RankingUseCase';
|
||||
import type { StandingRepository } from '../../domain/repositories/StandingRepository';
|
||||
import type { DriverRepository } from '../../domain/repositories/DriverRepository';
|
||||
import type { DriverStatsRepository } from '../../domain/repositories/DriverStatsRepository';
|
||||
import type { Logger } from '@core/shared/domain/Logger';
|
||||
|
||||
describe('RankingUseCase', () => {
|
||||
const mockStandingRepository = {} as StandingRepository;
|
||||
const mockDriverRepository = {} as DriverRepository;
|
||||
const mockDriverStatsRepository = {
|
||||
getAllStats: vi.fn(),
|
||||
} as unknown as DriverStatsRepository;
|
||||
const mockLogger = {
|
||||
debug: vi.fn(),
|
||||
} as unknown as Logger;
|
||||
|
||||
const useCase = new RankingUseCase(
|
||||
mockStandingRepository,
|
||||
mockDriverRepository,
|
||||
mockDriverStatsRepository,
|
||||
mockLogger
|
||||
);
|
||||
|
||||
it('should return all driver rankings', async () => {
|
||||
const mockStatsMap = new Map([
|
||||
['driver-1', { rating: 1500, wins: 2, totalRaces: 10, overallRank: 1 }],
|
||||
['driver-2', { rating: 1200, wins: 0, totalRaces: 5, overallRank: 2 }],
|
||||
]);
|
||||
vi.mocked(mockDriverStatsRepository.getAllStats).mockResolvedValue(mockStatsMap as any);
|
||||
|
||||
const result = await useCase.getAllDriverRankings();
|
||||
|
||||
expect(result).toHaveLength(2);
|
||||
expect(result).toContainEqual({
|
||||
driverId: 'driver-1',
|
||||
rating: 1500,
|
||||
wins: 2,
|
||||
totalRaces: 10,
|
||||
overallRank: 1,
|
||||
});
|
||||
expect(result).toContainEqual({
|
||||
driverId: 'driver-2',
|
||||
rating: 1200,
|
||||
wins: 0,
|
||||
totalRaces: 5,
|
||||
overallRank: 2,
|
||||
});
|
||||
expect(mockLogger.debug).toHaveBeenCalledWith('Getting all driver rankings');
|
||||
});
|
||||
|
||||
it('should return empty array when no stats exist', async () => {
|
||||
vi.mocked(mockDriverStatsRepository.getAllStats).mockResolvedValue(new Map());
|
||||
|
||||
const result = await useCase.getAllDriverRankings();
|
||||
|
||||
expect(result).toEqual([]);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user