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
65 lines
2.3 KiB
TypeScript
65 lines
2.3 KiB
TypeScript
import { describe, it, expect, beforeAll, beforeEach } from 'vitest';
|
|
import { RatingTestContext } from './RatingTestContext';
|
|
import { CalculateTeamContributionUseCase } from '../../../../core/rating/application/use-cases/CalculateTeamContributionUseCase';
|
|
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 Team Contribution Use Cases', () => {
|
|
let context: RatingTestContext;
|
|
let calculateTeamContributionUseCase: CalculateTeamContributionUseCase;
|
|
|
|
beforeAll(() => {
|
|
context = RatingTestContext.create();
|
|
calculateTeamContributionUseCase = new CalculateTeamContributionUseCase({
|
|
driverRepository: context.driverRepository,
|
|
ratingRepository: context.ratingRepository,
|
|
raceRepository: context.raceRepository,
|
|
resultRepository: context.resultRepository
|
|
});
|
|
});
|
|
|
|
beforeEach(async () => {
|
|
await context.clear();
|
|
});
|
|
|
|
describe('CalculateTeamContributionUseCase', () => {
|
|
describe('UseCase - Success Path', () => {
|
|
it('should calculate team contribution for single driver', async () => {
|
|
// Given: A driver with rating
|
|
const driverId = 'd1';
|
|
const driver = Driver.create({ id: driverId, iracingId: '100', name: 'John Doe', country: 'US' });
|
|
await context.driverRepository.create(driver);
|
|
|
|
// Given: A race and result
|
|
const raceId = 'r1';
|
|
const result = {
|
|
id: 'res1',
|
|
raceId,
|
|
driverId,
|
|
position: 1,
|
|
lapsCompleted: 20,
|
|
totalTime: 3600,
|
|
fastestLap: 105,
|
|
points: 25,
|
|
incidents: 0,
|
|
startPosition: 1
|
|
};
|
|
await context.resultRepository.create(result as any);
|
|
|
|
// When: CalculateTeamContributionUseCase.execute() is called
|
|
const contribution = await calculateTeamContributionUseCase.execute({
|
|
driverId,
|
|
teamId: 't1',
|
|
raceId
|
|
});
|
|
|
|
// Then: The team contribution should be calculated
|
|
expect(contribution.driverId).toBe(driverId);
|
|
expect(contribution.teamContribution).toBeGreaterThan(0);
|
|
});
|
|
});
|
|
});
|
|
});
|