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
79 lines
3.2 KiB
TypeScript
79 lines
3.2 KiB
TypeScript
import { describe, it, expect, beforeAll, beforeEach } from 'vitest';
|
|
import { RatingTestContext } from './RatingTestContext';
|
|
import { GetRatingLeaderboardUseCase } from '../../../../core/rating/application/use-cases/GetRatingLeaderboardUseCase';
|
|
import { Driver } from '../../../../core/racing/domain/entities/Driver';
|
|
import { Rating } from '../../../../core/rating/domain/entities/Rating';
|
|
import { DriverId } from '../../../../core/racing/domain/entities/DriverId';
|
|
import { RaceId } from '../../../../core/racing/domain/entities/RaceId';
|
|
|
|
describe('Rating Leaderboard Use Cases', () => {
|
|
let context: RatingTestContext;
|
|
let getRatingLeaderboardUseCase: GetRatingLeaderboardUseCase;
|
|
|
|
beforeAll(() => {
|
|
context = RatingTestContext.create();
|
|
getRatingLeaderboardUseCase = new GetRatingLeaderboardUseCase({
|
|
driverRepository: context.driverRepository,
|
|
ratingRepository: context.ratingRepository
|
|
});
|
|
});
|
|
|
|
beforeEach(async () => {
|
|
await context.clear();
|
|
});
|
|
|
|
describe('GetRatingLeaderboardUseCase', () => {
|
|
describe('UseCase - Success Path', () => {
|
|
it('should retrieve driver leaderboard sorted by rating', async () => {
|
|
// Given: Multiple drivers with different ratings
|
|
const drivers = [
|
|
Driver.create({ id: 'd1', iracingId: '100', name: 'John Doe', country: 'US' }),
|
|
Driver.create({ id: 'd2', iracingId: '101', name: 'Jane Smith', country: 'UK' }),
|
|
Driver.create({ id: 'd3', iracingId: '102', name: 'Bob Johnson', country: 'CA' })
|
|
];
|
|
for (const driver of drivers) {
|
|
await context.driverRepository.create(driver);
|
|
}
|
|
|
|
// Given: Ratings for each driver
|
|
const ratings = [
|
|
Rating.create({
|
|
driverId: DriverId.create('d1'),
|
|
raceId: RaceId.create('r1'),
|
|
rating: 1500,
|
|
components: { resultsStrength: 80, consistency: 75, cleanDriving: 90, racecraft: 85, reliability: 95, teamContribution: 70 },
|
|
timestamp: new Date()
|
|
}),
|
|
Rating.create({
|
|
driverId: DriverId.create('d2'),
|
|
raceId: RaceId.create('r1'),
|
|
rating: 1600,
|
|
components: { resultsStrength: 85, consistency: 80, cleanDriving: 92, racecraft: 88, reliability: 96, teamContribution: 75 },
|
|
timestamp: new Date()
|
|
}),
|
|
Rating.create({
|
|
driverId: DriverId.create('d3'),
|
|
raceId: RaceId.create('r1'),
|
|
rating: 1400,
|
|
components: { resultsStrength: 75, consistency: 70, cleanDriving: 88, racecraft: 82, reliability: 93, teamContribution: 65 },
|
|
timestamp: new Date()
|
|
})
|
|
];
|
|
for (const rating of ratings) {
|
|
await context.ratingRepository.save(rating);
|
|
}
|
|
|
|
// When: GetRatingLeaderboardUseCase.execute() is called
|
|
const result = await getRatingLeaderboardUseCase.execute({});
|
|
|
|
// Then: The leaderboard should be retrieved sorted by rating
|
|
expect(result).toHaveLength(3);
|
|
expect(result[0].driverId.toString()).toBe('d2'); // Highest rating
|
|
expect(result[0].rating).toBe(1600);
|
|
expect(result[1].driverId.toString()).toBe('d1');
|
|
expect(result[2].driverId.toString()).toBe('d3');
|
|
});
|
|
});
|
|
});
|
|
});
|