Some checks failed
CI / lint-typecheck (pull_request) Failing after 4m51s
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
42 lines
1.9 KiB
TypeScript
42 lines
1.9 KiB
TypeScript
import { describe, it, expect, beforeEach } from 'vitest';
|
|
import { LeaderboardsTestContext } from '../LeaderboardsTestContext';
|
|
|
|
describe('GetGlobalLeaderboardsUseCase - Success Path', () => {
|
|
let context: LeaderboardsTestContext;
|
|
|
|
beforeEach(() => {
|
|
context = LeaderboardsTestContext.create();
|
|
context.clear();
|
|
});
|
|
|
|
it('should retrieve top drivers and teams with complete data', async () => {
|
|
context.repository.addDriver({ id: 'driver-1', name: 'John Smith', rating: 5.0, teamId: 'team-1', teamName: 'Racing Team A', raceCount: 50 });
|
|
context.repository.addDriver({ id: 'driver-2', name: 'Jane Doe', rating: 4.8, teamId: 'team-2', teamName: 'Speed Squad', raceCount: 45 });
|
|
|
|
context.repository.addTeam({ id: 'team-1', name: 'Racing Team A', rating: 4.9, memberCount: 5, raceCount: 100 });
|
|
context.repository.addTeam({ id: 'team-2', name: 'Speed Squad', rating: 4.7, memberCount: 3, raceCount: 80 });
|
|
|
|
const result = await context.getGlobalLeaderboardsUseCase.execute();
|
|
|
|
expect(result.drivers).toHaveLength(2);
|
|
expect(result.teams).toHaveLength(2);
|
|
expect(result.drivers[0].rank).toBe(1);
|
|
expect(result.teams[0].rank).toBe(1);
|
|
expect(context.eventPublisher.getGlobalLeaderboardsAccessedEventCount()).toBe(1);
|
|
});
|
|
|
|
it('should limit results to top 10 drivers and teams', async () => {
|
|
for (let i = 1; i <= 15; i++) {
|
|
context.repository.addDriver({ id: `driver-${i}`, name: `Driver ${i}`, rating: 5.0 - i * 0.1, raceCount: 10 + i });
|
|
context.repository.addTeam({ id: `team-${i}`, name: `Team ${i}`, rating: 5.0 - i * 0.1, memberCount: 2 + i, raceCount: 20 + i });
|
|
}
|
|
|
|
const result = await context.getGlobalLeaderboardsUseCase.execute();
|
|
|
|
expect(result.drivers).toHaveLength(10);
|
|
expect(result.teams).toHaveLength(10);
|
|
expect(result.drivers[0].rating).toBe(4.9);
|
|
expect(result.teams[0].rating).toBe(4.9);
|
|
});
|
|
});
|