Some checks failed
CI / lint-typecheck (pull_request) Failing after 12s
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
165 lines
5.1 KiB
TypeScript
165 lines
5.1 KiB
TypeScript
import { describe, it, expect, beforeEach } from 'vitest';
|
|
import { DashboardTestContext } from '../DashboardTestContext';
|
|
|
|
describe('GetDashboardUseCase - Success Path', () => {
|
|
const context = DashboardTestContext.create();
|
|
|
|
beforeEach(() => {
|
|
context.clear();
|
|
});
|
|
|
|
it('should retrieve complete dashboard data for a driver with all data', async () => {
|
|
const driverId = 'driver-123';
|
|
context.driverRepository.addDriver({
|
|
id: driverId,
|
|
name: 'John Doe',
|
|
avatar: 'https://example.com/avatar.jpg',
|
|
rating: 1500,
|
|
rank: 123,
|
|
starts: 10,
|
|
wins: 3,
|
|
podiums: 5,
|
|
leagues: 2,
|
|
});
|
|
|
|
context.raceRepository.addUpcomingRaces(driverId, [
|
|
{
|
|
id: 'race-1',
|
|
trackName: 'Monza',
|
|
carType: 'GT3',
|
|
scheduledDate: new Date(Date.now() + 2 * 24 * 60 * 60 * 1000),
|
|
},
|
|
{
|
|
id: 'race-2',
|
|
trackName: 'Spa',
|
|
carType: 'GT3',
|
|
scheduledDate: new Date(Date.now() + 5 * 24 * 60 * 60 * 1000),
|
|
},
|
|
{
|
|
id: 'race-3',
|
|
trackName: 'Nürburgring',
|
|
carType: 'GT3',
|
|
scheduledDate: new Date(Date.now() + 1 * 24 * 60 * 60 * 1000),
|
|
},
|
|
{
|
|
id: 'race-4',
|
|
trackName: 'Silverstone',
|
|
carType: 'GT3',
|
|
scheduledDate: new Date(Date.now() + 7 * 24 * 60 * 60 * 1000),
|
|
},
|
|
{
|
|
id: 'race-5',
|
|
trackName: 'Imola',
|
|
carType: 'GT3',
|
|
scheduledDate: new Date(Date.now() + 3 * 24 * 60 * 60 * 1000),
|
|
},
|
|
]);
|
|
|
|
context.leagueRepository.addLeagueStandings(driverId, [
|
|
{
|
|
leagueId: 'league-1',
|
|
leagueName: 'GT3 Championship',
|
|
position: 5,
|
|
points: 150,
|
|
totalDrivers: 20,
|
|
},
|
|
{
|
|
leagueId: 'league-2',
|
|
leagueName: 'Endurance Series',
|
|
position: 12,
|
|
points: 85,
|
|
totalDrivers: 15,
|
|
},
|
|
]);
|
|
|
|
context.activityRepository.addRecentActivity(driverId, [
|
|
{
|
|
id: 'activity-1',
|
|
type: 'race_result',
|
|
description: 'Finished 3rd at Monza',
|
|
timestamp: new Date(Date.now() - 1 * 24 * 60 * 60 * 1000),
|
|
status: 'success',
|
|
},
|
|
{
|
|
id: 'activity-2',
|
|
type: 'league_invitation',
|
|
description: 'Invited to League XYZ',
|
|
timestamp: new Date(Date.now() - 2 * 24 * 60 * 60 * 1000),
|
|
status: 'info',
|
|
},
|
|
{
|
|
id: 'activity-3',
|
|
type: 'achievement',
|
|
description: 'Reached 1500 rating',
|
|
timestamp: new Date(Date.now() - 3 * 24 * 60 * 60 * 1000),
|
|
status: 'success',
|
|
},
|
|
]);
|
|
|
|
const result = await context.getDashboardUseCase.execute({ driverId });
|
|
|
|
expect(result).toBeDefined();
|
|
expect(result.driver.id).toBe(driverId);
|
|
expect(result.driver.name).toBe('John Doe');
|
|
expect(result.driver.avatar).toBe('https://example.com/avatar.jpg');
|
|
|
|
expect(result.statistics.rating).toBe(1500);
|
|
expect(result.statistics.rank).toBe(123);
|
|
expect(result.statistics.starts).toBe(10);
|
|
expect(result.statistics.wins).toBe(3);
|
|
expect(result.statistics.podiums).toBe(5);
|
|
expect(result.statistics.leagues).toBe(2);
|
|
|
|
expect(result.upcomingRaces).toHaveLength(3);
|
|
expect(result.upcomingRaces[0]!.trackName).toBe('Nürburgring');
|
|
expect(result.upcomingRaces[1]!.trackName).toBe('Monza');
|
|
expect(result.upcomingRaces[2]!.trackName).toBe('Imola');
|
|
|
|
expect(result.championshipStandings).toHaveLength(2);
|
|
expect(result.championshipStandings[0]!.leagueName).toBe('GT3 Championship');
|
|
expect(result.championshipStandings[0]!.position).toBe(5);
|
|
expect(result.championshipStandings[0]!.points).toBe(150);
|
|
expect(result.championshipStandings[0]!.totalDrivers).toBe(20);
|
|
|
|
expect(result.recentActivity).toHaveLength(3);
|
|
expect(result.recentActivity[0]!.description).toBe('Finished 3rd at Monza');
|
|
expect(result.recentActivity[0]!.status).toBe('success');
|
|
expect(result.recentActivity[1]!.description).toBe('Invited to League XYZ');
|
|
expect(result.recentActivity[2]!.description).toBe('Reached 1500 rating');
|
|
|
|
expect(context.eventPublisher.getDashboardAccessedEventCount()).toBe(1);
|
|
});
|
|
|
|
it('should retrieve dashboard data for a new driver with no history', async () => {
|
|
const driverId = 'new-driver-456';
|
|
context.driverRepository.addDriver({
|
|
id: driverId,
|
|
name: 'New Driver',
|
|
rating: 1000,
|
|
rank: 1000,
|
|
starts: 0,
|
|
wins: 0,
|
|
podiums: 0,
|
|
leagues: 0,
|
|
});
|
|
|
|
const result = await context.getDashboardUseCase.execute({ driverId });
|
|
|
|
expect(result).toBeDefined();
|
|
expect(result.driver.id).toBe(driverId);
|
|
expect(result.driver.name).toBe('New Driver');
|
|
expect(result.statistics.rating).toBe(1000);
|
|
expect(result.statistics.rank).toBe(1000);
|
|
expect(result.statistics.starts).toBe(0);
|
|
expect(result.statistics.wins).toBe(0);
|
|
expect(result.statistics.podiums).toBe(0);
|
|
expect(result.statistics.leagues).toBe(0);
|
|
|
|
expect(result.upcomingRaces).toHaveLength(0);
|
|
expect(result.championshipStandings).toHaveLength(0);
|
|
expect(result.recentActivity).toHaveLength(0);
|
|
|
|
expect(context.eventPublisher.getDashboardAccessedEventCount()).toBe(1);
|
|
});
|
|
});
|