integration tests
This commit is contained in:
@@ -2,722 +2,158 @@
|
||||
* Integration Test: Race Results Use Case Orchestration
|
||||
*
|
||||
* Tests the orchestration logic of race results page-related Use Cases:
|
||||
* - GetRaceResultsUseCase: Retrieves complete race results (all finishers)
|
||||
* - GetRaceStatisticsUseCase: Retrieves race statistics (fastest lap, average lap time, etc.)
|
||||
* - GetRaceResultsDetailUseCase: Retrieves complete race results (all finishers)
|
||||
* - GetRacePenaltiesUseCase: Retrieves race penalties and incidents
|
||||
* - GetRaceStewardingActionsUseCase: Retrieves race stewarding actions
|
||||
* - GetRacePointsDistributionUseCase: Retrieves race points distribution
|
||||
* - GetRaceChampionshipImplicationsUseCase: Retrieves race championship implications
|
||||
* - Validates that Use Cases correctly interact with their Ports (Repositories, Event Publishers)
|
||||
* - Uses In-Memory adapters for fast, deterministic testing
|
||||
*
|
||||
* Adheres to Clean Architecture:
|
||||
* - Tests Core Use Cases directly
|
||||
* - Uses In-Memory adapters for repositories
|
||||
* - Follows Given/When/Then pattern
|
||||
*
|
||||
* Focus: Business logic orchestration, NOT UI rendering
|
||||
*/
|
||||
|
||||
import { describe, it, expect, beforeAll, afterAll, beforeEach } from 'vitest';
|
||||
import { InMemoryRaceRepository } from '../../../adapters/races/persistence/inmemory/InMemoryRaceRepository';
|
||||
import { InMemoryEventPublisher } from '../../../adapters/events/InMemoryEventPublisher';
|
||||
import { GetRaceResultsUseCase } from '../../../core/races/use-cases/GetRaceResultsUseCase';
|
||||
import { GetRaceStatisticsUseCase } from '../../../core/races/use-cases/GetRaceStatisticsUseCase';
|
||||
import { GetRacePenaltiesUseCase } from '../../../core/races/use-cases/GetRacePenaltiesUseCase';
|
||||
import { GetRaceStewardingActionsUseCase } from '../../../core/races/use-cases/GetRaceStewardingActionsUseCase';
|
||||
import { GetRacePointsDistributionUseCase } from '../../../core/races/use-cases/GetRacePointsDistributionUseCase';
|
||||
import { GetRaceChampionshipImplicationsUseCase } from '../../../core/races/use-cases/GetRaceChampionshipImplicationsUseCase';
|
||||
import { RaceResultsQuery } from '../../../core/races/ports/RaceResultsQuery';
|
||||
import { RaceStatisticsQuery } from '../../../core/races/ports/RaceStatisticsQuery';
|
||||
import { RacePenaltiesQuery } from '../../../core/races/ports/RacePenaltiesQuery';
|
||||
import { RaceStewardingActionsQuery } from '../../../core/races/ports/RaceStewardingActionsQuery';
|
||||
import { RacePointsDistributionQuery } from '../../../core/races/ports/RacePointsDistributionQuery';
|
||||
import { RaceChampionshipImplicationsQuery } from '../../../core/races/ports/RaceChampionshipImplicationsQuery';
|
||||
import { describe, it, expect, beforeAll, beforeEach } from 'vitest';
|
||||
import { InMemoryRaceRepository } from '../../../adapters/racing/persistence/inmemory/InMemoryRaceRepository';
|
||||
import { InMemoryLeagueRepository } from '../../../adapters/racing/persistence/inmemory/InMemoryLeagueRepository';
|
||||
import { InMemoryDriverRepository } from '../../../adapters/racing/persistence/inmemory/InMemoryDriverRepository';
|
||||
import { InMemoryResultRepository } from '../../../adapters/racing/persistence/inmemory/InMemoryResultRepository';
|
||||
import { InMemoryPenaltyRepository } from '../../../adapters/racing/persistence/inmemory/InMemoryPenaltyRepository';
|
||||
import { GetRaceResultsDetailUseCase } from '../../../core/racing/application/use-cases/GetRaceResultsDetailUseCase';
|
||||
import { GetRacePenaltiesUseCase } from '../../../core/racing/application/use-cases/GetRacePenaltiesUseCase';
|
||||
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 { Result as RaceResult } from '../../../core/racing/domain/entities/result/Result';
|
||||
import { Penalty } from '../../../core/racing/domain/entities/penalty/Penalty';
|
||||
import { Logger } from '../../../core/shared/domain/Logger';
|
||||
|
||||
describe('Race Results Use Case Orchestration', () => {
|
||||
let raceRepository: InMemoryRaceRepository;
|
||||
let eventPublisher: InMemoryEventPublisher;
|
||||
let getRaceResultsUseCase: GetRaceResultsUseCase;
|
||||
let getRaceStatisticsUseCase: GetRaceStatisticsUseCase;
|
||||
let leagueRepository: InMemoryLeagueRepository;
|
||||
let driverRepository: InMemoryDriverRepository;
|
||||
let resultRepository: InMemoryResultRepository;
|
||||
let penaltyRepository: InMemoryPenaltyRepository;
|
||||
let getRaceResultsDetailUseCase: GetRaceResultsDetailUseCase;
|
||||
let getRacePenaltiesUseCase: GetRacePenaltiesUseCase;
|
||||
let getRaceStewardingActionsUseCase: GetRaceStewardingActionsUseCase;
|
||||
let getRacePointsDistributionUseCase: GetRacePointsDistributionUseCase;
|
||||
let getRaceChampionshipImplicationsUseCase: GetRaceChampionshipImplicationsUseCase;
|
||||
let mockLogger: Logger;
|
||||
|
||||
beforeAll(() => {
|
||||
// TODO: Initialize In-Memory repositories and event publisher
|
||||
// raceRepository = new InMemoryRaceRepository();
|
||||
// eventPublisher = new InMemoryEventPublisher();
|
||||
// getRaceResultsUseCase = new GetRaceResultsUseCase({
|
||||
// raceRepository,
|
||||
// eventPublisher,
|
||||
// });
|
||||
// getRaceStatisticsUseCase = new GetRaceStatisticsUseCase({
|
||||
// raceRepository,
|
||||
// eventPublisher,
|
||||
// });
|
||||
// getRacePenaltiesUseCase = new GetRacePenaltiesUseCase({
|
||||
// raceRepository,
|
||||
// eventPublisher,
|
||||
// });
|
||||
// getRaceStewardingActionsUseCase = new GetRaceStewardingActionsUseCase({
|
||||
// raceRepository,
|
||||
// eventPublisher,
|
||||
// });
|
||||
// getRacePointsDistributionUseCase = new GetRacePointsDistributionUseCase({
|
||||
// raceRepository,
|
||||
// eventPublisher,
|
||||
// });
|
||||
// getRaceChampionshipImplicationsUseCase = new GetRaceChampionshipImplicationsUseCase({
|
||||
// raceRepository,
|
||||
// eventPublisher,
|
||||
// });
|
||||
mockLogger = {
|
||||
info: () => {},
|
||||
debug: () => {},
|
||||
warn: () => {},
|
||||
error: () => {},
|
||||
} as unknown as Logger;
|
||||
|
||||
raceRepository = new InMemoryRaceRepository(mockLogger);
|
||||
leagueRepository = new InMemoryLeagueRepository(mockLogger);
|
||||
driverRepository = new InMemoryDriverRepository(mockLogger);
|
||||
resultRepository = new InMemoryResultRepository(mockLogger, raceRepository);
|
||||
penaltyRepository = new InMemoryPenaltyRepository(mockLogger);
|
||||
|
||||
getRaceResultsDetailUseCase = new GetRaceResultsDetailUseCase(
|
||||
raceRepository,
|
||||
leagueRepository,
|
||||
resultRepository,
|
||||
driverRepository,
|
||||
penaltyRepository
|
||||
);
|
||||
|
||||
getRacePenaltiesUseCase = new GetRacePenaltiesUseCase(
|
||||
penaltyRepository,
|
||||
driverRepository
|
||||
);
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
// TODO: Clear all In-Memory repositories before each test
|
||||
// raceRepository.clear();
|
||||
// eventPublisher.clear();
|
||||
beforeEach(async () => {
|
||||
(raceRepository as any).races.clear();
|
||||
leagueRepository.clear();
|
||||
await driverRepository.clear();
|
||||
(resultRepository as any).results.clear();
|
||||
(penaltyRepository as any).penalties.clear();
|
||||
});
|
||||
|
||||
describe('GetRaceResultsUseCase - Success Path', () => {
|
||||
describe('GetRaceResultsDetailUseCase', () => {
|
||||
it('should retrieve complete race results with all finishers', async () => {
|
||||
// TODO: Implement test
|
||||
// Scenario: Driver views complete race results
|
||||
// Given: A completed race exists with multiple finishers
|
||||
// When: GetRaceResultsUseCase.execute() is called with race ID
|
||||
// Then: The result should contain all finishers
|
||||
// And: The list should be ordered by position
|
||||
// And: EventPublisher should emit RaceResultsAccessedEvent
|
||||
});
|
||||
// Given: A completed race with results
|
||||
const leagueId = 'l1';
|
||||
const league = League.create({ id: leagueId, name: 'Pro League', description: 'Desc', ownerId: 'o1' });
|
||||
await leagueRepository.create(league);
|
||||
|
||||
it('should retrieve race results with race winner', async () => {
|
||||
// TODO: Implement test
|
||||
// Scenario: Race with winner
|
||||
// Given: A completed race exists with winner
|
||||
// When: GetRaceResultsUseCase.execute() is called with race ID
|
||||
// Then: The result should show race winner
|
||||
// And: EventPublisher should emit RaceResultsAccessedEvent
|
||||
});
|
||||
const raceId = 'r1';
|
||||
const race = Race.create({
|
||||
id: raceId,
|
||||
leagueId,
|
||||
scheduledAt: new Date(Date.now() - 86400000),
|
||||
track: 'Spa',
|
||||
car: 'GT3',
|
||||
status: 'completed'
|
||||
});
|
||||
await raceRepository.create(race);
|
||||
|
||||
it('should retrieve race results with podium', async () => {
|
||||
// TODO: Implement test
|
||||
// Scenario: Race with podium
|
||||
// Given: A completed race exists with podium
|
||||
// When: GetRaceResultsUseCase.execute() is called with race ID
|
||||
// Then: The result should show top 3 finishers
|
||||
// And: EventPublisher should emit RaceResultsAccessedEvent
|
||||
});
|
||||
const driverId = 'd1';
|
||||
const driver = Driver.create({ id: driverId, iracingId: '100', name: 'John Doe', country: 'US' });
|
||||
await driverRepository.create(driver);
|
||||
|
||||
it('should retrieve race results with driver information', async () => {
|
||||
// TODO: Implement test
|
||||
// Scenario: Race results with driver information
|
||||
// Given: A completed race exists with driver information
|
||||
// When: GetRaceResultsUseCase.execute() is called with race ID
|
||||
// Then: The result should show driver name, team, car
|
||||
// And: EventPublisher should emit RaceResultsAccessedEvent
|
||||
});
|
||||
const raceResult = RaceResult.create({
|
||||
id: 'res1',
|
||||
raceId,
|
||||
driverId,
|
||||
position: 1,
|
||||
lapsCompleted: 20,
|
||||
totalTime: 3600,
|
||||
fastestLap: 105,
|
||||
points: 25
|
||||
});
|
||||
await resultRepository.create(raceResult);
|
||||
|
||||
it('should retrieve race results with position information', async () => {
|
||||
// TODO: Implement test
|
||||
// Scenario: Race results with position information
|
||||
// Given: A completed race exists with position information
|
||||
// When: GetRaceResultsUseCase.execute() is called with race ID
|
||||
// Then: The result should show position, race time, gaps
|
||||
// And: EventPublisher should emit RaceResultsAccessedEvent
|
||||
});
|
||||
// When: GetRaceResultsDetailUseCase.execute() is called
|
||||
const result = await getRaceResultsDetailUseCase.execute({ raceId });
|
||||
|
||||
it('should retrieve race results with lap information', async () => {
|
||||
// TODO: Implement test
|
||||
// Scenario: Race results with lap information
|
||||
// Given: A completed race exists with lap information
|
||||
// When: GetRaceResultsUseCase.execute() is called with race ID
|
||||
// Then: The result should show laps completed, fastest lap, average lap time
|
||||
// And: EventPublisher should emit RaceResultsAccessedEvent
|
||||
});
|
||||
|
||||
it('should retrieve race results with points information', async () => {
|
||||
// TODO: Implement test
|
||||
// Scenario: Race results with points information
|
||||
// Given: A completed race exists with points information
|
||||
// When: GetRaceResultsUseCase.execute() is called with race ID
|
||||
// Then: The result should show points earned
|
||||
// And: EventPublisher should emit RaceResultsAccessedEvent
|
||||
});
|
||||
|
||||
it('should retrieve race results with penalties information', async () => {
|
||||
// TODO: Implement test
|
||||
// Scenario: Race results with penalties information
|
||||
// Given: A completed race exists with penalties information
|
||||
// When: GetRaceResultsUseCase.execute() is called with race ID
|
||||
// Then: The result should show penalties
|
||||
// And: EventPublisher should emit RaceResultsAccessedEvent
|
||||
});
|
||||
|
||||
it('should retrieve race results with incidents information', async () => {
|
||||
// TODO: Implement test
|
||||
// Scenario: Race results with incidents information
|
||||
// Given: A completed race exists with incidents information
|
||||
// When: GetRaceResultsUseCase.execute() is called with race ID
|
||||
// Then: The result should show incidents
|
||||
// And: EventPublisher should emit RaceResultsAccessedEvent
|
||||
});
|
||||
|
||||
it('should retrieve race results with stewarding actions information', async () => {
|
||||
// TODO: Implement test
|
||||
// Scenario: Race results with stewarding actions information
|
||||
// Given: A completed race exists with stewarding actions information
|
||||
// When: GetRaceResultsUseCase.execute() is called with race ID
|
||||
// Then: The result should show stewarding actions
|
||||
// And: EventPublisher should emit RaceResultsAccessedEvent
|
||||
});
|
||||
|
||||
it('should retrieve race results with protests information', async () => {
|
||||
// TODO: Implement test
|
||||
// Scenario: Race results with protests information
|
||||
// Given: A completed race exists with protests information
|
||||
// When: GetRaceResultsUseCase.execute() is called with race ID
|
||||
// Then: The result should show protests
|
||||
// And: EventPublisher should emit RaceResultsAccessedEvent
|
||||
});
|
||||
|
||||
it('should retrieve race results with empty results', async () => {
|
||||
// TODO: Implement test
|
||||
// Scenario: Race with no results
|
||||
// Given: A race exists with no results
|
||||
// When: GetRaceResultsUseCase.execute() is called with race ID
|
||||
// Then: The result should be empty
|
||||
// And: EventPublisher should emit RaceResultsAccessedEvent
|
||||
// Then: The result should contain race and results
|
||||
expect(result.isOk()).toBe(true);
|
||||
const data = result.unwrap();
|
||||
expect(data.race.id).toBe(raceId);
|
||||
expect(data.results).toHaveLength(1);
|
||||
expect(data.results[0].driverId.toString()).toBe(driverId);
|
||||
});
|
||||
});
|
||||
|
||||
describe('GetRaceResultsUseCase - Edge Cases', () => {
|
||||
it('should handle race with missing driver information', async () => {
|
||||
// TODO: Implement test
|
||||
// Scenario: Race results with missing driver data
|
||||
// Given: A completed race exists with missing driver information
|
||||
// When: GetRaceResultsUseCase.execute() is called with race ID
|
||||
// Then: The result should contain results with available information
|
||||
// And: EventPublisher should emit RaceResultsAccessedEvent
|
||||
});
|
||||
describe('GetRacePenaltiesUseCase', () => {
|
||||
it('should retrieve race penalties with driver information', async () => {
|
||||
// Given: A race with penalties
|
||||
const raceId = 'r1';
|
||||
const driverId = 'd1';
|
||||
const stewardId = 's1';
|
||||
|
||||
it('should handle race with missing team information', async () => {
|
||||
// TODO: Implement test
|
||||
// Scenario: Race results with missing team data
|
||||
// Given: A completed race exists with missing team information
|
||||
// When: GetRaceResultsUseCase.execute() is called with race ID
|
||||
// Then: The result should contain results with available information
|
||||
// And: EventPublisher should emit RaceResultsAccessedEvent
|
||||
});
|
||||
const driver = Driver.create({ id: driverId, iracingId: '100', name: 'John Doe', country: 'US' });
|
||||
await driverRepository.create(driver);
|
||||
|
||||
const steward = Driver.create({ id: stewardId, iracingId: '200', name: 'Steward', country: 'UK' });
|
||||
await driverRepository.create(steward);
|
||||
|
||||
it('should handle race with missing car information', async () => {
|
||||
// TODO: Implement test
|
||||
// Scenario: Race results with missing car data
|
||||
// Given: A completed race exists with missing car information
|
||||
// When: GetRaceResultsUseCase.execute() is called with race ID
|
||||
// Then: The result should contain results with available information
|
||||
// And: EventPublisher should emit RaceResultsAccessedEvent
|
||||
});
|
||||
const penalty = Penalty.create({
|
||||
id: 'p1',
|
||||
raceId,
|
||||
driverId,
|
||||
type: 'time',
|
||||
value: 5,
|
||||
reason: 'Track limits',
|
||||
issuedBy: stewardId,
|
||||
status: 'applied'
|
||||
});
|
||||
await penaltyRepository.create(penalty);
|
||||
|
||||
it('should handle race with missing position information', async () => {
|
||||
// TODO: Implement test
|
||||
// Scenario: Race results with missing position data
|
||||
// Given: A completed race exists with missing position information
|
||||
// When: GetRaceResultsUseCase.execute() is called with race ID
|
||||
// Then: The result should contain results with available information
|
||||
// And: EventPublisher should emit RaceResultsAccessedEvent
|
||||
});
|
||||
|
||||
it('should handle race with missing lap information', async () => {
|
||||
// TODO: Implement test
|
||||
// Scenario: Race results with missing lap data
|
||||
// Given: A completed race exists with missing lap information
|
||||
// When: GetRaceResultsUseCase.execute() is called with race ID
|
||||
// Then: The result should contain results with available information
|
||||
// And: EventPublisher should emit RaceResultsAccessedEvent
|
||||
});
|
||||
|
||||
it('should handle race with missing points information', async () => {
|
||||
// TODO: Implement test
|
||||
// Scenario: Race results with missing points data
|
||||
// Given: A completed race exists with missing points information
|
||||
// When: GetRaceResultsUseCase.execute() is called with race ID
|
||||
// Then: The result should contain results with available information
|
||||
// And: EventPublisher should emit RaceResultsAccessedEvent
|
||||
});
|
||||
|
||||
it('should handle race with missing penalties information', async () => {
|
||||
// TODO: Implement test
|
||||
// Scenario: Race results with missing penalties data
|
||||
// Given: A completed race exists with missing penalties information
|
||||
// When: GetRaceResultsUseCase.execute() is called with race ID
|
||||
// Then: The result should contain results with available information
|
||||
// And: EventPublisher should emit RaceResultsAccessedEvent
|
||||
});
|
||||
|
||||
it('should handle race with missing incidents information', async () => {
|
||||
// TODO: Implement test
|
||||
// Scenario: Race results with missing incidents data
|
||||
// Given: A completed race exists with missing incidents information
|
||||
// When: GetRaceResultsUseCase.execute() is called with race ID
|
||||
// Then: The result should contain results with available information
|
||||
// And: EventPublisher should emit RaceResultsAccessedEvent
|
||||
});
|
||||
|
||||
it('should handle race with missing stewarding actions information', async () => {
|
||||
// TODO: Implement test
|
||||
// Scenario: Race results with missing stewarding actions data
|
||||
// Given: A completed race exists with missing stewarding actions information
|
||||
// When: GetRaceResultsUseCase.execute() is called with race ID
|
||||
// Then: The result should contain results with available information
|
||||
// And: EventPublisher should emit RaceResultsAccessedEvent
|
||||
});
|
||||
|
||||
it('should handle race with missing protests information', async () => {
|
||||
// TODO: Implement test
|
||||
// Scenario: Race results with missing protests data
|
||||
// Given: A completed race exists with missing protests information
|
||||
// When: GetRaceResultsUseCase.execute() is called with race ID
|
||||
// Then: The result should contain results with available information
|
||||
// And: EventPublisher should emit RaceResultsAccessedEvent
|
||||
});
|
||||
});
|
||||
|
||||
describe('GetRaceResultsUseCase - Error Handling', () => {
|
||||
it('should throw error when race does not exist', async () => {
|
||||
// TODO: Implement test
|
||||
// Scenario: Non-existent race
|
||||
// Given: No race exists with the given ID
|
||||
// When: GetRaceResultsUseCase.execute() is called with non-existent race ID
|
||||
// Then: Should throw RaceNotFoundError
|
||||
// And: EventPublisher should NOT emit any events
|
||||
});
|
||||
|
||||
it('should throw error when race ID is invalid', async () => {
|
||||
// TODO: Implement test
|
||||
// Scenario: Invalid race ID
|
||||
// Given: An invalid race ID (e.g., empty string, null, undefined)
|
||||
// When: GetRaceResultsUseCase.execute() is called with invalid race ID
|
||||
// Then: Should throw ValidationError
|
||||
// And: EventPublisher should NOT emit any events
|
||||
});
|
||||
|
||||
it('should handle repository errors gracefully', async () => {
|
||||
// TODO: Implement test
|
||||
// Scenario: Repository throws error
|
||||
// Given: A race exists
|
||||
// And: RaceRepository throws an error during query
|
||||
// When: GetRaceResultsUseCase.execute() is called
|
||||
// Then: Should propagate the error appropriately
|
||||
// And: EventPublisher should NOT emit any events
|
||||
});
|
||||
});
|
||||
|
||||
describe('GetRaceStatisticsUseCase - Success Path', () => {
|
||||
it('should retrieve race statistics with fastest lap', async () => {
|
||||
// TODO: Implement test
|
||||
// Scenario: Race with fastest lap
|
||||
// Given: A completed race exists with fastest lap
|
||||
// When: GetRaceStatisticsUseCase.execute() is called with race ID
|
||||
// Then: The result should show fastest lap
|
||||
// And: EventPublisher should emit RaceStatisticsAccessedEvent
|
||||
});
|
||||
|
||||
it('should retrieve race statistics with average lap time', async () => {
|
||||
// TODO: Implement test
|
||||
// Scenario: Race with average lap time
|
||||
// Given: A completed race exists with average lap time
|
||||
// When: GetRaceStatisticsUseCase.execute() is called with race ID
|
||||
// Then: The result should show average lap time
|
||||
// And: EventPublisher should emit RaceStatisticsAccessedEvent
|
||||
});
|
||||
|
||||
it('should retrieve race statistics with total incidents', async () => {
|
||||
// TODO: Implement test
|
||||
// Scenario: Race with total incidents
|
||||
// Given: A completed race exists with total incidents
|
||||
// When: GetRaceStatisticsUseCase.execute() is called with race ID
|
||||
// Then: The result should show total incidents
|
||||
// And: EventPublisher should emit RaceStatisticsAccessedEvent
|
||||
});
|
||||
|
||||
it('should retrieve race statistics with total penalties', async () => {
|
||||
// TODO: Implement test
|
||||
// Scenario: Race with total penalties
|
||||
// Given: A completed race exists with total penalties
|
||||
// When: GetRaceStatisticsUseCase.execute() is called with race ID
|
||||
// Then: The result should show total penalties
|
||||
// And: EventPublisher should emit RaceStatisticsAccessedEvent
|
||||
});
|
||||
|
||||
it('should retrieve race statistics with total protests', async () => {
|
||||
// TODO: Implement test
|
||||
// Scenario: Race with total protests
|
||||
// Given: A completed race exists with total protests
|
||||
// When: GetRaceStatisticsUseCase.execute() is called with race ID
|
||||
// Then: The result should show total protests
|
||||
// And: EventPublisher should emit RaceStatisticsAccessedEvent
|
||||
});
|
||||
|
||||
it('should retrieve race statistics with total stewarding actions', async () => {
|
||||
// TODO: Implement test
|
||||
// Scenario: Race with total stewarding actions
|
||||
// Given: A completed race exists with total stewarding actions
|
||||
// When: GetRaceStatisticsUseCase.execute() is called with race ID
|
||||
// Then: The result should show total stewarding actions
|
||||
// And: EventPublisher should emit RaceStatisticsAccessedEvent
|
||||
});
|
||||
|
||||
it('should retrieve race statistics with all metrics', async () => {
|
||||
// TODO: Implement test
|
||||
// Scenario: Race with all statistics
|
||||
// Given: A completed race exists with all statistics
|
||||
// When: GetRaceStatisticsUseCase.execute() is called with race ID
|
||||
// Then: The result should show all statistics
|
||||
// And: EventPublisher should emit RaceStatisticsAccessedEvent
|
||||
});
|
||||
|
||||
it('should retrieve race statistics with empty metrics', async () => {
|
||||
// TODO: Implement test
|
||||
// Scenario: Race with no statistics
|
||||
// Given: A completed race exists with no statistics
|
||||
// When: GetRaceStatisticsUseCase.execute() is called with race ID
|
||||
// Then: The result should show empty or default statistics
|
||||
// And: EventPublisher should emit RaceStatisticsAccessedEvent
|
||||
});
|
||||
});
|
||||
|
||||
describe('GetRaceStatisticsUseCase - Error Handling', () => {
|
||||
it('should throw error when race does not exist', async () => {
|
||||
// TODO: Implement test
|
||||
// Scenario: Non-existent race
|
||||
// Given: No race exists with the given ID
|
||||
// When: GetRaceStatisticsUseCase.execute() is called with non-existent race ID
|
||||
// Then: Should throw RaceNotFoundError
|
||||
// And: EventPublisher should NOT emit any events
|
||||
});
|
||||
|
||||
it('should handle repository errors gracefully', async () => {
|
||||
// TODO: Implement test
|
||||
// Scenario: Repository throws error
|
||||
// Given: RaceRepository throws an error during query
|
||||
// When: GetRaceStatisticsUseCase.execute() is called
|
||||
// Then: Should propagate the error appropriately
|
||||
// And: EventPublisher should NOT emit any events
|
||||
});
|
||||
});
|
||||
|
||||
describe('GetRacePenaltiesUseCase - Success Path', () => {
|
||||
it('should retrieve race penalties with penalty information', async () => {
|
||||
// TODO: Implement test
|
||||
// Scenario: Race with penalties
|
||||
// Given: A completed race exists with penalties
|
||||
// When: GetRacePenaltiesUseCase.execute() is called with race ID
|
||||
// Then: The result should show penalty information
|
||||
// And: EventPublisher should emit RacePenaltiesAccessedEvent
|
||||
});
|
||||
|
||||
it('should retrieve race penalties with incident information', async () => {
|
||||
// TODO: Implement test
|
||||
// Scenario: Race with incidents
|
||||
// Given: A completed race exists with incidents
|
||||
// When: GetRacePenaltiesUseCase.execute() is called with race ID
|
||||
// Then: The result should show incident information
|
||||
// And: EventPublisher should emit RacePenaltiesAccessedEvent
|
||||
});
|
||||
|
||||
it('should retrieve race penalties with empty results', async () => {
|
||||
// TODO: Implement test
|
||||
// Scenario: Race with no penalties
|
||||
// Given: A completed race exists with no penalties
|
||||
// When: GetRacePenaltiesUseCase.execute() is called with race ID
|
||||
// Then: The result should be empty
|
||||
// And: EventPublisher should emit RacePenaltiesAccessedEvent
|
||||
});
|
||||
});
|
||||
|
||||
describe('GetRacePenaltiesUseCase - Error Handling', () => {
|
||||
it('should throw error when race does not exist', async () => {
|
||||
// TODO: Implement test
|
||||
// Scenario: Non-existent race
|
||||
// Given: No race exists with the given ID
|
||||
// When: GetRacePenaltiesUseCase.execute() is called with non-existent race ID
|
||||
// Then: Should throw RaceNotFoundError
|
||||
// And: EventPublisher should NOT emit any events
|
||||
});
|
||||
|
||||
it('should handle repository errors gracefully', async () => {
|
||||
// TODO: Implement test
|
||||
// Scenario: Repository throws error
|
||||
// Given: RaceRepository throws an error during query
|
||||
// When: GetRacePenaltiesUseCase.execute() is called
|
||||
// Then: Should propagate the error appropriately
|
||||
// And: EventPublisher should NOT emit any events
|
||||
});
|
||||
});
|
||||
const result = await getRacePenaltiesUseCase.execute({ raceId });
|
||||
|
||||
describe('GetRaceStewardingActionsUseCase - Success Path', () => {
|
||||
it('should retrieve race stewarding actions with action information', async () => {
|
||||
// TODO: Implement test
|
||||
// Scenario: Race with stewarding actions
|
||||
// Given: A completed race exists with stewarding actions
|
||||
// When: GetRaceStewardingActionsUseCase.execute() is called with race ID
|
||||
// Then: The result should show stewarding action information
|
||||
// And: EventPublisher should emit RaceStewardingActionsAccessedEvent
|
||||
});
|
||||
|
||||
it('should retrieve race stewarding actions with empty results', async () => {
|
||||
// TODO: Implement test
|
||||
// Scenario: Race with no stewarding actions
|
||||
// Given: A completed race exists with no stewarding actions
|
||||
// When: GetRaceStewardingActionsUseCase.execute() is called with race ID
|
||||
// Then: The result should be empty
|
||||
// And: EventPublisher should emit RaceStewardingActionsAccessedEvent
|
||||
});
|
||||
});
|
||||
|
||||
describe('GetRaceStewardingActionsUseCase - Error Handling', () => {
|
||||
it('should throw error when race does not exist', async () => {
|
||||
// TODO: Implement test
|
||||
// Scenario: Non-existent race
|
||||
// Given: No race exists with the given ID
|
||||
// When: GetRaceStewardingActionsUseCase.execute() is called with non-existent race ID
|
||||
// Then: Should throw RaceNotFoundError
|
||||
// And: EventPublisher should NOT emit any events
|
||||
});
|
||||
|
||||
it('should handle repository errors gracefully', async () => {
|
||||
// TODO: Implement test
|
||||
// Scenario: Repository throws error
|
||||
// Given: RaceRepository throws an error during query
|
||||
// When: GetRaceStewardingActionsUseCase.execute() is called
|
||||
// Then: Should propagate the error appropriately
|
||||
// And: EventPublisher should NOT emit any events
|
||||
});
|
||||
});
|
||||
|
||||
describe('GetRacePointsDistributionUseCase - Success Path', () => {
|
||||
it('should retrieve race points distribution', async () => {
|
||||
// TODO: Implement test
|
||||
// Scenario: Race with points distribution
|
||||
// Given: A completed race exists with points distribution
|
||||
// When: GetRacePointsDistributionUseCase.execute() is called with race ID
|
||||
// Then: The result should show points distribution
|
||||
// And: EventPublisher should emit RacePointsDistributionAccessedEvent
|
||||
});
|
||||
|
||||
it('should retrieve race points distribution with empty results', async () => {
|
||||
// TODO: Implement test
|
||||
// Scenario: Race with no points distribution
|
||||
// Given: A completed race exists with no points distribution
|
||||
// When: GetRacePointsDistributionUseCase.execute() is called with race ID
|
||||
// Then: The result should be empty
|
||||
// And: EventPublisher should emit RacePointsDistributionAccessedEvent
|
||||
});
|
||||
});
|
||||
|
||||
describe('GetRacePointsDistributionUseCase - Error Handling', () => {
|
||||
it('should throw error when race does not exist', async () => {
|
||||
// TODO: Implement test
|
||||
// Scenario: Non-existent race
|
||||
// Given: No race exists with the given ID
|
||||
// When: GetRacePointsDistributionUseCase.execute() is called with non-existent race ID
|
||||
// Then: Should throw RaceNotFoundError
|
||||
// And: EventPublisher should NOT emit any events
|
||||
});
|
||||
|
||||
it('should handle repository errors gracefully', async () => {
|
||||
// TODO: Implement test
|
||||
// Scenario: Repository throws error
|
||||
// Given: RaceRepository throws an error during query
|
||||
// When: GetRacePointsDistributionUseCase.execute() is called
|
||||
// Then: Should propagate the error appropriately
|
||||
// And: EventPublisher should NOT emit any events
|
||||
});
|
||||
});
|
||||
|
||||
describe('GetRaceChampionshipImplicationsUseCase - Success Path', () => {
|
||||
it('should retrieve race championship implications', async () => {
|
||||
// TODO: Implement test
|
||||
// Scenario: Race with championship implications
|
||||
// Given: A completed race exists with championship implications
|
||||
// When: GetRaceChampionshipImplicationsUseCase.execute() is called with race ID
|
||||
// Then: The result should show championship implications
|
||||
// And: EventPublisher should emit RaceChampionshipImplicationsAccessedEvent
|
||||
});
|
||||
|
||||
it('should retrieve race championship implications with empty results', async () => {
|
||||
// TODO: Implement test
|
||||
// Scenario: Race with no championship implications
|
||||
// Given: A completed race exists with no championship implications
|
||||
// When: GetRaceChampionshipImplicationsUseCase.execute() is called with race ID
|
||||
// Then: The result should be empty
|
||||
// And: EventPublisher should emit RaceChampionshipImplicationsAccessedEvent
|
||||
});
|
||||
});
|
||||
|
||||
describe('GetRaceChampionshipImplicationsUseCase - Error Handling', () => {
|
||||
it('should throw error when race does not exist', async () => {
|
||||
// TODO: Implement test
|
||||
// Scenario: Non-existent race
|
||||
// Given: No race exists with the given ID
|
||||
// When: GetRaceChampionshipImplicationsUseCase.execute() is called with non-existent race ID
|
||||
// Then: Should throw RaceNotFoundError
|
||||
// And: EventPublisher should NOT emit any events
|
||||
});
|
||||
|
||||
it('should handle repository errors gracefully', async () => {
|
||||
// TODO: Implement test
|
||||
// Scenario: Repository throws error
|
||||
// Given: RaceRepository throws an error during query
|
||||
// When: GetRaceChampionshipImplicationsUseCase.execute() is called
|
||||
// Then: Should propagate the error appropriately
|
||||
// And: EventPublisher should NOT emit any events
|
||||
});
|
||||
});
|
||||
|
||||
describe('Race Results Page Data Orchestration', () => {
|
||||
it('should correctly orchestrate data for race results page', async () => {
|
||||
// TODO: Implement test
|
||||
// Scenario: Race results page data orchestration
|
||||
// Given: A completed race exists with all information
|
||||
// When: Multiple use cases are executed for the same race
|
||||
// Then: Each use case should return its respective data
|
||||
// And: EventPublisher should emit appropriate events for each use case
|
||||
});
|
||||
|
||||
it('should correctly format race results for display', async () => {
|
||||
// TODO: Implement test
|
||||
// Scenario: Race results formatting
|
||||
// Given: A completed race exists with all information
|
||||
// When: GetRaceResultsUseCase.execute() is called
|
||||
// Then: The result should format:
|
||||
// - Driver name: Clearly displayed
|
||||
// - Team: Clearly displayed
|
||||
// - Car: Clearly displayed
|
||||
// - Position: Clearly displayed
|
||||
// - Race time: Formatted correctly
|
||||
// - Gaps: Formatted correctly
|
||||
// - Laps completed: Clearly displayed
|
||||
// - Points earned: Clearly displayed
|
||||
// - Fastest lap: Formatted correctly
|
||||
// - Average lap time: Formatted correctly
|
||||
// - Penalties: Clearly displayed
|
||||
// - Incidents: Clearly displayed
|
||||
// - Stewarding actions: Clearly displayed
|
||||
// - Protests: Clearly displayed
|
||||
});
|
||||
|
||||
it('should correctly format race statistics for display', async () => {
|
||||
// TODO: Implement test
|
||||
// Scenario: Race statistics formatting
|
||||
// Given: A completed race exists with all statistics
|
||||
// When: GetRaceStatisticsUseCase.execute() is called
|
||||
// Then: The result should format:
|
||||
// - Fastest lap: Formatted correctly
|
||||
// - Average lap time: Formatted correctly
|
||||
// - Total incidents: Clearly displayed
|
||||
// - Total penalties: Clearly displayed
|
||||
// - Total protests: Clearly displayed
|
||||
// - Total stewarding actions: Clearly displayed
|
||||
});
|
||||
|
||||
it('should correctly format race penalties for display', async () => {
|
||||
// TODO: Implement test
|
||||
// Scenario: Race penalties formatting
|
||||
// Given: A completed race exists with penalties
|
||||
// When: GetRacePenaltiesUseCase.execute() is called
|
||||
// Then: The result should format:
|
||||
// - Penalty ID: Clearly displayed
|
||||
// - Penalty type: Clearly displayed
|
||||
// - Penalty severity: Clearly displayed
|
||||
// - Penalty recipient: Clearly displayed
|
||||
// - Penalty reason: Clearly displayed
|
||||
// - Penalty timestamp: Formatted correctly
|
||||
});
|
||||
|
||||
it('should correctly format race stewarding actions for display', async () => {
|
||||
// TODO: Implement test
|
||||
// Scenario: Race stewarding actions formatting
|
||||
// Given: A completed race exists with stewarding actions
|
||||
// When: GetRaceStewardingActionsUseCase.execute() is called
|
||||
// Then: The result should format:
|
||||
// - Stewarding action ID: Clearly displayed
|
||||
// - Stewarding action type: Clearly displayed
|
||||
// - Stewarding action recipient: Clearly displayed
|
||||
// - Stewarding action reason: Clearly displayed
|
||||
// - Stewarding action timestamp: Formatted correctly
|
||||
});
|
||||
|
||||
it('should correctly format race points distribution for display', async () => {
|
||||
// TODO: Implement test
|
||||
// Scenario: Race points distribution formatting
|
||||
// Given: A completed race exists with points distribution
|
||||
// When: GetRacePointsDistributionUseCase.execute() is called
|
||||
// Then: The result should format:
|
||||
// - Points distribution: Clearly displayed
|
||||
// - Championship implications: Clearly displayed
|
||||
});
|
||||
|
||||
it('should correctly format race championship implications for display', async () => {
|
||||
// TODO: Implement test
|
||||
// Scenario: Race championship implications formatting
|
||||
// Given: A completed race exists with championship implications
|
||||
// When: GetRaceChampionshipImplicationsUseCase.execute() is called
|
||||
// Then: The result should format:
|
||||
// - Championship implications: Clearly displayed
|
||||
// - Points changes: Clearly displayed
|
||||
// - Position changes: Clearly displayed
|
||||
});
|
||||
|
||||
it('should correctly handle race with no results', async () => {
|
||||
// TODO: Implement test
|
||||
// Scenario: Race with no results
|
||||
// Given: A race exists with no results
|
||||
// When: GetRaceResultsUseCase.execute() is called
|
||||
// Then: The result should be empty
|
||||
// And: EventPublisher should emit RaceResultsAccessedEvent
|
||||
});
|
||||
|
||||
it('should correctly handle race with no statistics', async () => {
|
||||
// TODO: Implement test
|
||||
// Scenario: Race with no statistics
|
||||
// Given: A race exists with no statistics
|
||||
// When: GetRaceStatisticsUseCase.execute() is called
|
||||
// Then: The result should show empty or default statistics
|
||||
// And: EventPublisher should emit RaceStatisticsAccessedEvent
|
||||
});
|
||||
|
||||
it('should correctly handle race with no penalties', async () => {
|
||||
// TODO: Implement test
|
||||
// Scenario: Race with no penalties
|
||||
// Given: A race exists with no penalties
|
||||
// When: GetRacePenaltiesUseCase.execute() is called
|
||||
// Then: The result should be empty
|
||||
// And: EventPublisher should emit RacePenaltiesAccessedEvent
|
||||
});
|
||||
|
||||
it('should correctly handle race with no stewarding actions', async () => {
|
||||
// TODO: Implement test
|
||||
// Scenario: Race with no stewarding actions
|
||||
// Given: A race exists with no stewarding actions
|
||||
// When: GetRaceStewardingActionsUseCase.execute() is called
|
||||
// Then: The result should be empty
|
||||
// And: EventPublisher should emit RaceStewardingActionsAccessedEvent
|
||||
});
|
||||
|
||||
it('should correctly handle race with no points distribution', async () => {
|
||||
// TODO: Implement test
|
||||
// Scenario: Race with no points distribution
|
||||
// Given: A race exists with no points distribution
|
||||
// When: GetRacePointsDistributionUseCase.execute() is called
|
||||
// Then: The result should be empty
|
||||
// And: EventPublisher should emit RacePointsDistributionAccessedEvent
|
||||
});
|
||||
|
||||
it('should correctly handle race with no championship implications', async () => {
|
||||
// TODO: Implement test
|
||||
// Scenario: Race with no championship implications
|
||||
// Given: A race exists with no championship implications
|
||||
// When: GetRaceChampionshipImplicationsUseCase.execute() is called
|
||||
// Then: The result should be empty
|
||||
// And: EventPublisher should emit RaceChampionshipImplicationsAccessedEvent
|
||||
// Then: It should return penalties and drivers
|
||||
expect(result.isOk()).toBe(true);
|
||||
const data = result.unwrap();
|
||||
expect(data.penalties).toHaveLength(1);
|
||||
expect(data.drivers.some(d => d.id === driverId)).toBe(true);
|
||||
expect(data.drivers.some(d => d.id === stewardId)).toBe(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user