Some checks failed
CI / lint-typecheck (pull_request) Failing after 1m29s
CI / tests (pull_request) Has been skipped
CI / contract-tests (pull_request) Has been skipped
CI / e2e-tests (pull_request) Has been skipped
CI / comment-pr (pull_request) Has been skipped
CI / commit-types (pull_request) Has been skipped
60 lines
1.9 KiB
TypeScript
60 lines
1.9 KiB
TypeScript
import { describe, it, expect, vi } from 'vitest';
|
|
import { RankingUseCase } 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([]);
|
|
});
|
|
});
|