Files
gridpilot.gg/tests/integration/races/stewarding/get-league-protests.test.ts
Marc Mintel 6df38a462a
Some checks failed
CI / lint-typecheck (pull_request) Failing after 4m50s
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
integration tests
2026-01-23 11:44:59 +01:00

74 lines
2.7 KiB
TypeScript

import { describe, it, expect, beforeAll, beforeEach } from 'vitest';
import { RacesTestContext } from '../RacesTestContext';
import { GetLeagueProtestsUseCase } from '../../../../core/racing/application/use-cases/GetLeagueProtestsUseCase';
import { Race } from '../../../../core/racing/domain/entities/Race';
import { League } from '../../../../core/racing/domain/entities/League';
import { Driver } from '../../../../core/racing/domain/entities/Driver';
import { Protest } from '../../../../core/racing/domain/entities/Protest';
describe('GetLeagueProtestsUseCase', () => {
let context: RacesTestContext;
let getLeagueProtestsUseCase: GetLeagueProtestsUseCase;
beforeAll(() => {
context = RacesTestContext.create();
getLeagueProtestsUseCase = new GetLeagueProtestsUseCase(
context.raceRepository,
context.protestRepository,
context.driverRepository,
context.leagueRepository
);
});
beforeEach(async () => {
await context.clear();
});
it('should retrieve league protests with all related entities', async () => {
// Given: A league, race, drivers and a protest exist
const leagueId = 'l1';
const league = League.create({ id: leagueId, name: 'Pro League', description: 'Desc', ownerId: 'o1' });
await context.leagueRepository.create(league);
const raceId = 'r1';
const race = Race.create({
id: raceId,
leagueId,
scheduledAt: new Date(),
track: 'Spa',
car: 'GT3',
status: 'completed'
});
await context.raceRepository.create(race);
const driver1Id = 'd1';
const driver2Id = 'd2';
const driver1 = Driver.create({ id: driver1Id, iracingId: '100', name: 'Protester', country: 'US' });
const driver2 = Driver.create({ id: driver2Id, iracingId: '200', name: 'Accused', country: 'UK' });
await context.driverRepository.create(driver1);
await context.driverRepository.create(driver2);
const protest = Protest.create({
id: 'p1',
raceId,
protestingDriverId: driver1Id,
accusedDriverId: driver2Id,
incident: { lap: 1, description: 'Unsafe rejoin' },
timestamp: new Date()
});
await context.protestRepository.create(protest);
// When: GetLeagueProtestsUseCase.execute() is called
const result = await getLeagueProtestsUseCase.execute({ leagueId });
// Then: It should return the protest with race and driver info
expect(result.isOk()).toBe(true);
const data = result.unwrap();
expect(data.protests).toHaveLength(1);
expect(data.protests[0].protest.id).toBe('p1');
expect(data.protests[0].race?.id).toBe(raceId);
expect(data.protests[0].protestingDriver?.id).toBe(driver1Id);
expect(data.protests[0].accusedDriver?.id).toBe(driver2Id);
});
});