fix core tests
This commit is contained in:
@@ -127,17 +127,42 @@ describe('GetLeagueDriverSeasonStatsUseCase', () => {
|
||||
const input: GetLeagueDriverSeasonStatsInput = { leagueId: 'league-1' };
|
||||
|
||||
const mockStandings = [
|
||||
{ driverId: 'driver-1', position: 1, points: 100, racesCompleted: 5 },
|
||||
{ driverId: 'driver-2', position: 2, points: 80, racesCompleted: 5 },
|
||||
{
|
||||
driverId: { toString: () => 'driver-1' },
|
||||
position: { toNumber: () => 1 },
|
||||
points: { toNumber: () => 100 },
|
||||
},
|
||||
{
|
||||
driverId: { toString: () => 'driver-2' },
|
||||
position: { toNumber: () => 2 },
|
||||
points: { toNumber: () => 80 },
|
||||
},
|
||||
];
|
||||
const mockRaces = [
|
||||
{ id: 'race-1' },
|
||||
{ id: 'race-2' },
|
||||
{ id: 'race-3' },
|
||||
{ id: 'race-4' },
|
||||
{ id: 'race-5' },
|
||||
];
|
||||
const mockRaces = [{ id: 'race-1' }, { id: 'race-2' }];
|
||||
const mockPenalties = [
|
||||
{ driverId: 'driver-1', status: 'applied', type: 'points_deduction', value: 10 },
|
||||
];
|
||||
const mockResults = [{ position: 1 }];
|
||||
const mockRating = { rating: 1500, ratingChange: 50 };
|
||||
const mockDriver = { id: 'driver-1', name: 'Driver One', teamId: 'team-1' };
|
||||
const mockTeam = { id: 'team-1', name: 'Team One' };
|
||||
|
||||
const mockDriver1Results = [
|
||||
{ position: { toNumber: () => 1 } },
|
||||
{ position: { toNumber: () => 1 } },
|
||||
{ position: { toNumber: () => 1 } },
|
||||
{ position: { toNumber: () => 1 } },
|
||||
{ position: { toNumber: () => 1 } },
|
||||
];
|
||||
const mockDriver2Results = [
|
||||
{ position: { toNumber: () => 2 } },
|
||||
{ position: { toNumber: () => 2 } },
|
||||
{ position: { toNumber: () => 2 } },
|
||||
{ position: { toNumber: () => 2 } },
|
||||
{ position: { toNumber: () => 2 } },
|
||||
];
|
||||
|
||||
mockStandingFindByLeagueId.mockResolvedValue(mockStandings);
|
||||
mockRaceFindByLeagueId.mockResolvedValue(mockRaces);
|
||||
@@ -145,14 +170,24 @@ describe('GetLeagueDriverSeasonStatsUseCase', () => {
|
||||
if (raceId === 'race-1') return Promise.resolve(mockPenalties);
|
||||
return Promise.resolve([]);
|
||||
});
|
||||
mockDriverRatingGetRating.mockReturnValue(mockRating);
|
||||
mockResultFindByDriverIdAndLeagueId.mockResolvedValue(mockResults);
|
||||
mockDriverFindById.mockImplementation((id: string) => {
|
||||
if (id === 'driver-1') return Promise.resolve(mockDriver);
|
||||
if (id === 'driver-2') return Promise.resolve({ id: 'driver-2', name: 'Driver Two' });
|
||||
|
||||
mockDriverRatingGetRating.mockImplementation((driverId: string) => {
|
||||
if (driverId === 'driver-1') return Promise.resolve(1500);
|
||||
if (driverId === 'driver-2') return Promise.resolve(1400);
|
||||
return Promise.resolve(null);
|
||||
});
|
||||
|
||||
mockResultFindByDriverIdAndLeagueId.mockImplementation((driverId: string) => {
|
||||
if (driverId === 'driver-1') return Promise.resolve(mockDriver1Results);
|
||||
if (driverId === 'driver-2') return Promise.resolve(mockDriver2Results);
|
||||
return Promise.resolve([]);
|
||||
});
|
||||
|
||||
mockDriverFindById.mockImplementation((id: string) => {
|
||||
if (id === 'driver-1') return Promise.resolve({ id: 'driver-1', name: { toString: () => 'Driver One' } });
|
||||
if (id === 'driver-2') return Promise.resolve({ id: 'driver-2', name: { toString: () => 'Driver Two' } });
|
||||
return Promise.resolve(null);
|
||||
});
|
||||
mockTeamFindById.mockResolvedValue(mockTeam);
|
||||
|
||||
const result = await useCase.execute(input);
|
||||
|
||||
@@ -163,25 +198,26 @@ describe('GetLeagueDriverSeasonStatsUseCase', () => {
|
||||
const presented = output.present.mock.calls[0]?.[0] as GetLeagueDriverSeasonStatsResult;
|
||||
expect(presented.leagueId).toBe('league-1');
|
||||
expect(presented.stats).toHaveLength(2);
|
||||
|
||||
expect(presented.stats[0]).toEqual({
|
||||
leagueId: 'league-1',
|
||||
driverId: 'driver-1',
|
||||
position: 1,
|
||||
driverName: 'Driver One',
|
||||
teamId: 'team-1',
|
||||
teamName: 'Team One',
|
||||
teamId: undefined,
|
||||
teamName: undefined,
|
||||
totalPoints: 100,
|
||||
basePoints: 90,
|
||||
basePoints: 110,
|
||||
penaltyPoints: -10,
|
||||
bonusPoints: 0,
|
||||
pointsPerRace: 20,
|
||||
racesStarted: 1,
|
||||
racesFinished: 1,
|
||||
racesStarted: 5,
|
||||
racesFinished: 5,
|
||||
dnfs: 0,
|
||||
noShows: 1,
|
||||
noShows: 0,
|
||||
avgFinish: 1,
|
||||
rating: 1500,
|
||||
ratingChange: 50,
|
||||
ratingChange: null,
|
||||
});
|
||||
});
|
||||
|
||||
@@ -189,20 +225,21 @@ describe('GetLeagueDriverSeasonStatsUseCase', () => {
|
||||
const input: GetLeagueDriverSeasonStatsInput = { leagueId: 'league-1' };
|
||||
|
||||
const mockStandings = [
|
||||
{ driverId: 'driver-1', position: 1, points: 100, racesCompleted: 5 },
|
||||
{
|
||||
driverId: { toString: () => 'driver-1' },
|
||||
position: { toNumber: () => 1 },
|
||||
points: { toNumber: () => 100 },
|
||||
},
|
||||
];
|
||||
const mockRaces = [{ id: 'race-1' }];
|
||||
const mockResults = [{ position: 1 }];
|
||||
const mockRating = { rating: null, ratingChange: null };
|
||||
const mockDriver = { id: 'driver-1', name: 'Driver One' };
|
||||
const mockResults = [{ position: { toNumber: () => 1 } }];
|
||||
|
||||
mockStandingFindByLeagueId.mockResolvedValue(mockStandings);
|
||||
mockRaceFindByLeagueId.mockResolvedValue(mockRaces);
|
||||
mockPenaltyFindByRaceId.mockResolvedValue([]);
|
||||
mockDriverRatingGetRating.mockReturnValue(mockRating);
|
||||
mockDriverRatingGetRating.mockResolvedValue(null);
|
||||
mockResultFindByDriverIdAndLeagueId.mockResolvedValue(mockResults);
|
||||
mockDriverFindById.mockResolvedValue(mockDriver);
|
||||
mockTeamFindById.mockResolvedValue(null);
|
||||
mockDriverFindById.mockResolvedValue({ id: 'driver-1', name: { toString: () => 'Driver One' } });
|
||||
|
||||
const result = await useCase.execute(input);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user