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:
@@ -9,7 +9,7 @@
|
||||
* Focus: Business logic orchestration, NOT UI rendering
|
||||
*/
|
||||
|
||||
import { describe, it, expect, beforeAll, afterAll, beforeEach } from 'vitest';
|
||||
import { describe, it, expect, beforeAll, afterAll, beforeEach, vi } from 'vitest';
|
||||
import { InMemoryDriverRepository } from '../../../adapters/drivers/persistence/inmemory/InMemoryDriverRepository';
|
||||
import { InMemoryRaceRepository } from '../../../adapters/races/persistence/inmemory/InMemoryRaceRepository';
|
||||
import { InMemoryLeagueRepository } from '../../../adapters/leagues/persistence/inmemory/InMemoryLeagueRepository';
|
||||
@@ -17,6 +17,8 @@ import { InMemoryActivityRepository } from '../../../adapters/activity/persisten
|
||||
import { InMemoryEventPublisher } from '../../../adapters/events/InMemoryEventPublisher';
|
||||
import { GetDashboardUseCase } from '../../../core/dashboard/application/use-cases/GetDashboardUseCase';
|
||||
import { DashboardQuery } from '../../../core/dashboard/application/ports/DashboardQuery';
|
||||
import { DriverNotFoundError } from '../../../core/dashboard/domain/errors/DriverNotFoundError';
|
||||
import { ValidationError } from '../../../core/shared/errors/ValidationError';
|
||||
|
||||
describe('Dashboard Use Case Orchestration', () => {
|
||||
let driverRepository: InMemoryDriverRepository;
|
||||
@@ -592,103 +594,259 @@ describe('Dashboard Use Case Orchestration', () => {
|
||||
});
|
||||
|
||||
it('should handle driver with no data at all', async () => {
|
||||
// TODO: Implement test
|
||||
// Scenario: Driver with absolutely no data
|
||||
// Given: A driver exists
|
||||
const driverId = 'driver-no-data';
|
||||
driverRepository.addDriver({
|
||||
id: driverId,
|
||||
name: 'No Data Driver',
|
||||
rating: 1000,
|
||||
rank: 1000,
|
||||
starts: 0,
|
||||
wins: 0,
|
||||
podiums: 0,
|
||||
leagues: 0,
|
||||
});
|
||||
|
||||
// And: The driver has no statistics
|
||||
// And: The driver has no upcoming races
|
||||
// And: The driver has no championship standings
|
||||
// And: The driver has no recent activity
|
||||
// When: GetDashboardUseCase.execute() is called with driver ID
|
||||
const result = await getDashboardUseCase.execute({ driverId });
|
||||
|
||||
// Then: The result should contain basic driver info
|
||||
expect(result.driver.id).toBe(driverId);
|
||||
expect(result.driver.name).toBe('No Data Driver');
|
||||
|
||||
// And: All sections should be empty or show default values
|
||||
expect(result.upcomingRaces).toHaveLength(0);
|
||||
expect(result.championshipStandings).toHaveLength(0);
|
||||
expect(result.recentActivity).toHaveLength(0);
|
||||
expect(result.statistics.starts).toBe(0);
|
||||
|
||||
// And: EventPublisher should emit DashboardAccessedEvent
|
||||
expect(eventPublisher.getDashboardAccessedEventCount()).toBe(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('GetDashboardUseCase - Error Handling', () => {
|
||||
it('should throw error when driver does not exist', async () => {
|
||||
// TODO: Implement test
|
||||
// Scenario: Non-existent driver
|
||||
// Given: No driver exists with the given ID
|
||||
const driverId = 'non-existent';
|
||||
|
||||
// When: GetDashboardUseCase.execute() is called with non-existent driver ID
|
||||
// Then: Should throw DriverNotFoundError
|
||||
await expect(getDashboardUseCase.execute({ driverId }))
|
||||
.rejects.toThrow(DriverNotFoundError);
|
||||
|
||||
// And: EventPublisher should NOT emit any events
|
||||
expect(eventPublisher.getDashboardAccessedEventCount()).toBe(0);
|
||||
});
|
||||
|
||||
it('should throw error when driver ID is invalid', async () => {
|
||||
// TODO: Implement test
|
||||
// Scenario: Invalid driver ID
|
||||
// Given: An invalid driver ID (e.g., empty string, null, undefined)
|
||||
// Given: An invalid driver ID (e.g., empty string)
|
||||
const driverId = '';
|
||||
|
||||
// When: GetDashboardUseCase.execute() is called with invalid driver ID
|
||||
// Then: Should throw ValidationError
|
||||
await expect(getDashboardUseCase.execute({ driverId }))
|
||||
.rejects.toThrow(ValidationError);
|
||||
|
||||
// And: EventPublisher should NOT emit any events
|
||||
expect(eventPublisher.getDashboardAccessedEventCount()).toBe(0);
|
||||
});
|
||||
|
||||
it('should handle repository errors gracefully', async () => {
|
||||
// TODO: Implement test
|
||||
// Scenario: Repository throws error
|
||||
// Given: A driver exists
|
||||
const driverId = 'driver-repo-error';
|
||||
driverRepository.addDriver({
|
||||
id: driverId,
|
||||
name: 'Repo Error Driver',
|
||||
rating: 1000,
|
||||
rank: 1,
|
||||
starts: 0,
|
||||
wins: 0,
|
||||
podiums: 0,
|
||||
leagues: 0,
|
||||
});
|
||||
|
||||
// And: DriverRepository throws an error during query
|
||||
// (We use a spy to simulate error since InMemory repo doesn't fail by default)
|
||||
const spy = vi.spyOn(driverRepository, 'findDriverById').mockRejectedValue(new Error('Database connection failed'));
|
||||
|
||||
// When: GetDashboardUseCase.execute() is called
|
||||
// Then: Should propagate the error appropriately
|
||||
await expect(getDashboardUseCase.execute({ driverId }))
|
||||
.rejects.toThrow('Database connection failed');
|
||||
|
||||
// And: EventPublisher should NOT emit any events
|
||||
expect(eventPublisher.getDashboardAccessedEventCount()).toBe(0);
|
||||
|
||||
spy.mockRestore();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Dashboard Data Orchestration', () => {
|
||||
it('should correctly calculate driver statistics from race results', async () => {
|
||||
// TODO: Implement test
|
||||
// Scenario: Driver statistics calculation
|
||||
// Given: A driver exists
|
||||
// And: The driver has 10 completed races
|
||||
// And: The driver has 3 wins
|
||||
// And: The driver has 5 podiums
|
||||
const driverId = 'driver-stats-calc';
|
||||
driverRepository.addDriver({
|
||||
id: driverId,
|
||||
name: 'Stats Driver',
|
||||
rating: 1500,
|
||||
rank: 123,
|
||||
starts: 10,
|
||||
wins: 3,
|
||||
podiums: 5,
|
||||
leagues: 1,
|
||||
});
|
||||
|
||||
// When: GetDashboardUseCase.execute() is called
|
||||
const result = await getDashboardUseCase.execute({ driverId });
|
||||
|
||||
// Then: Driver statistics should show:
|
||||
// - Starts: 10
|
||||
// - Wins: 3
|
||||
// - Podiums: 5
|
||||
// - Rating: Calculated based on performance
|
||||
// - Rank: Calculated based on rating
|
||||
expect(result.statistics.starts).toBe(10);
|
||||
expect(result.statistics.wins).toBe(3);
|
||||
expect(result.statistics.podiums).toBe(5);
|
||||
expect(result.statistics.rating).toBe(1500);
|
||||
expect(result.statistics.rank).toBe(123);
|
||||
});
|
||||
|
||||
it('should correctly format upcoming race time information', async () => {
|
||||
// TODO: Implement test
|
||||
// Scenario: Upcoming race time formatting
|
||||
// Given: A driver exists
|
||||
const driverId = 'driver-time-format';
|
||||
driverRepository.addDriver({
|
||||
id: driverId,
|
||||
name: 'Time Driver',
|
||||
rating: 1000,
|
||||
rank: 1,
|
||||
starts: 0,
|
||||
wins: 0,
|
||||
podiums: 0,
|
||||
leagues: 0,
|
||||
});
|
||||
|
||||
// And: The driver has an upcoming race scheduled in 2 days 4 hours
|
||||
const scheduledDate = new Date();
|
||||
scheduledDate.setDate(scheduledDate.getDate() + 2);
|
||||
scheduledDate.setHours(scheduledDate.getHours() + 4);
|
||||
|
||||
raceRepository.addUpcomingRaces(driverId, [
|
||||
{
|
||||
id: 'race-1',
|
||||
trackName: 'Monza',
|
||||
carType: 'GT3',
|
||||
scheduledDate,
|
||||
},
|
||||
]);
|
||||
|
||||
// When: GetDashboardUseCase.execute() is called
|
||||
const result = await getDashboardUseCase.execute({ driverId });
|
||||
|
||||
// Then: The upcoming race should include:
|
||||
// - Track name
|
||||
// - Car type
|
||||
// - Scheduled date and time
|
||||
// - Time until race (formatted as "2 days 4 hours")
|
||||
expect(result.upcomingRaces).toHaveLength(1);
|
||||
expect(result.upcomingRaces[0].trackName).toBe('Monza');
|
||||
expect(result.upcomingRaces[0].carType).toBe('GT3');
|
||||
expect(result.upcomingRaces[0].scheduledDate).toBe(scheduledDate.toISOString());
|
||||
expect(result.upcomingRaces[0].timeUntilRace).toContain('2 days 4 hours');
|
||||
});
|
||||
|
||||
it('should correctly aggregate championship standings across leagues', async () => {
|
||||
// TODO: Implement test
|
||||
// Scenario: Championship standings aggregation
|
||||
// Given: A driver exists
|
||||
const driverId = 'driver-champ-agg';
|
||||
driverRepository.addDriver({
|
||||
id: driverId,
|
||||
name: 'Agg Driver',
|
||||
rating: 1000,
|
||||
rank: 1,
|
||||
starts: 0,
|
||||
wins: 0,
|
||||
podiums: 0,
|
||||
leagues: 2,
|
||||
});
|
||||
|
||||
// And: The driver is in 2 championships
|
||||
// And: In Championship A: Position 5, 150 points, 20 drivers
|
||||
// And: In Championship B: Position 12, 85 points, 15 drivers
|
||||
leagueRepository.addLeagueStandings(driverId, [
|
||||
{
|
||||
leagueId: 'league-a',
|
||||
leagueName: 'Championship A',
|
||||
position: 5,
|
||||
points: 150,
|
||||
totalDrivers: 20,
|
||||
},
|
||||
{
|
||||
leagueId: 'league-b',
|
||||
leagueName: 'Championship B',
|
||||
position: 12,
|
||||
points: 85,
|
||||
totalDrivers: 15,
|
||||
},
|
||||
]);
|
||||
|
||||
// When: GetDashboardUseCase.execute() is called
|
||||
const result = await getDashboardUseCase.execute({ driverId });
|
||||
|
||||
// Then: Championship standings should show:
|
||||
// - League A: Position 5, 150 points, 20 drivers
|
||||
// - League B: Position 12, 85 points, 15 drivers
|
||||
expect(result.championshipStandings).toHaveLength(2);
|
||||
expect(result.championshipStandings[0].leagueName).toBe('Championship A');
|
||||
expect(result.championshipStandings[0].position).toBe(5);
|
||||
expect(result.championshipStandings[1].leagueName).toBe('Championship B');
|
||||
expect(result.championshipStandings[1].position).toBe(12);
|
||||
});
|
||||
|
||||
it('should correctly format recent activity with proper status', async () => {
|
||||
// TODO: Implement test
|
||||
// Scenario: Recent activity formatting
|
||||
// Given: A driver exists
|
||||
const driverId = 'driver-activity-format';
|
||||
driverRepository.addDriver({
|
||||
id: driverId,
|
||||
name: 'Activity Driver',
|
||||
rating: 1000,
|
||||
rank: 1,
|
||||
starts: 0,
|
||||
wins: 0,
|
||||
podiums: 0,
|
||||
leagues: 0,
|
||||
});
|
||||
|
||||
// And: The driver has a race result (finished 3rd)
|
||||
// And: The driver has a league invitation event
|
||||
activityRepository.addRecentActivity(driverId, [
|
||||
{
|
||||
id: 'act-1',
|
||||
type: 'race_result',
|
||||
description: 'Finished 3rd at Monza',
|
||||
timestamp: new Date(),
|
||||
status: 'success',
|
||||
},
|
||||
{
|
||||
id: 'act-2',
|
||||
type: 'league_invitation',
|
||||
description: 'Invited to League XYZ',
|
||||
timestamp: new Date(Date.now() - 1000),
|
||||
status: 'info',
|
||||
},
|
||||
]);
|
||||
|
||||
// When: GetDashboardUseCase.execute() is called
|
||||
const result = await getDashboardUseCase.execute({ driverId });
|
||||
|
||||
// Then: Recent activity should show:
|
||||
// - Race result: Type "race_result", Status "success", Description "Finished 3rd at Monza"
|
||||
// - League invitation: Type "league_invitation", Status "info", Description "Invited to League XYZ"
|
||||
expect(result.recentActivity).toHaveLength(2);
|
||||
expect(result.recentActivity[0].type).toBe('race_result');
|
||||
expect(result.recentActivity[0].status).toBe('success');
|
||||
expect(result.recentActivity[0].description).toBe('Finished 3rd at Monza');
|
||||
|
||||
expect(result.recentActivity[1].type).toBe('league_invitation');
|
||||
expect(result.recentActivity[1].status).toBe('info');
|
||||
expect(result.recentActivity[1].description).toBe('Invited to League XYZ');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user