integration tests
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
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
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
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);
|
||||
});
|
||||
});
|
||||
75
tests/integration/races/stewarding/review-protest.test.ts
Normal file
75
tests/integration/races/stewarding/review-protest.test.ts
Normal file
@@ -0,0 +1,75 @@
|
||||
import { describe, it, expect, beforeAll, beforeEach } from 'vitest';
|
||||
import { RacesTestContext } from '../RacesTestContext';
|
||||
import { ReviewProtestUseCase } from '../../../../core/racing/application/use-cases/ReviewProtestUseCase';
|
||||
import { Race } from '../../../../core/racing/domain/entities/Race';
|
||||
import { Protest } from '../../../../core/racing/domain/entities/Protest';
|
||||
import { LeagueMembership } from '../../../../core/racing/domain/entities/LeagueMembership';
|
||||
|
||||
describe('ReviewProtestUseCase', () => {
|
||||
let context: RacesTestContext;
|
||||
let reviewProtestUseCase: ReviewProtestUseCase;
|
||||
|
||||
beforeAll(() => {
|
||||
context = RacesTestContext.create();
|
||||
reviewProtestUseCase = new ReviewProtestUseCase(
|
||||
context.protestRepository,
|
||||
context.raceRepository,
|
||||
context.leagueMembershipRepository,
|
||||
context.logger
|
||||
);
|
||||
});
|
||||
|
||||
beforeEach(async () => {
|
||||
await context.clear();
|
||||
});
|
||||
|
||||
it('should allow a steward to review a protest', async () => {
|
||||
// Given: A protest and a steward membership
|
||||
const leagueId = 'l1';
|
||||
const raceId = 'r1';
|
||||
const stewardId = 's1';
|
||||
|
||||
const race = Race.create({
|
||||
id: raceId,
|
||||
leagueId,
|
||||
scheduledAt: new Date(),
|
||||
track: 'Spa',
|
||||
car: 'GT3',
|
||||
status: 'completed'
|
||||
});
|
||||
await context.raceRepository.create(race);
|
||||
|
||||
const protest = Protest.create({
|
||||
id: 'p1',
|
||||
raceId,
|
||||
protestingDriverId: 'd1',
|
||||
accusedDriverId: 'd2',
|
||||
incident: { lap: 1, description: 'Unsafe rejoin' },
|
||||
filedAt: new Date()
|
||||
});
|
||||
await context.protestRepository.create(protest);
|
||||
|
||||
const membership = LeagueMembership.create({
|
||||
id: 'm1',
|
||||
leagueId,
|
||||
driverId: stewardId,
|
||||
role: 'admin',
|
||||
status: 'active'
|
||||
});
|
||||
await context.leagueMembershipRepository.saveMembership(membership);
|
||||
|
||||
// When: ReviewProtestUseCase.execute() is called
|
||||
const result = await reviewProtestUseCase.execute({
|
||||
protestId: 'p1',
|
||||
stewardId,
|
||||
decision: 'uphold',
|
||||
decisionNotes: 'Clear violation'
|
||||
});
|
||||
|
||||
// Then: The protest should be updated
|
||||
expect(result.isOk()).toBe(true);
|
||||
const updatedProtest = await context.protestRepository.findById('p1');
|
||||
expect(updatedProtest?.status.toString()).toBe('upheld');
|
||||
expect(updatedProtest?.reviewedBy).toBe(stewardId);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user