78 lines
1.9 KiB
TypeScript
78 lines
1.9 KiB
TypeScript
import { describe, it, expect, vi, type Mock } from 'vitest';
|
|
import { GetLeagueStandingsUseCaseImpl } from './GetLeagueStandingsUseCaseImpl';
|
|
import type { ILeagueStandingsRepository, RawStanding } from '../ports/ILeagueStandingsRepository';
|
|
|
|
describe('GetLeagueStandingsUseCaseImpl', () => {
|
|
let repository: {
|
|
getLeagueStandings: Mock;
|
|
};
|
|
let useCase: GetLeagueStandingsUseCaseImpl;
|
|
|
|
beforeEach(() => {
|
|
repository = {
|
|
getLeagueStandings: vi.fn(),
|
|
} as unknown as ILeagueStandingsRepository as any;
|
|
|
|
useCase = new GetLeagueStandingsUseCaseImpl(repository as unknown as ILeagueStandingsRepository);
|
|
});
|
|
|
|
it('maps raw standings from repository to view model', async () => {
|
|
const leagueId = 'league-1';
|
|
const rawStandings: RawStanding[] = [
|
|
{
|
|
id: 's1',
|
|
leagueId,
|
|
seasonId: 'season-1',
|
|
driverId: 'driver-1',
|
|
position: 1,
|
|
points: 100,
|
|
wins: 3,
|
|
podiums: 5,
|
|
racesCompleted: 10,
|
|
},
|
|
{
|
|
id: 's2',
|
|
leagueId,
|
|
seasonId: null,
|
|
driverId: 'driver-2',
|
|
position: 2,
|
|
points: 80,
|
|
wins: 1,
|
|
podiums: null,
|
|
racesCompleted: 10,
|
|
},
|
|
];
|
|
|
|
repository.getLeagueStandings.mockResolvedValue(rawStandings);
|
|
|
|
const result = await useCase.execute(leagueId);
|
|
|
|
expect(repository.getLeagueStandings).toHaveBeenCalledWith(leagueId);
|
|
expect(result.leagueId).toBe(leagueId);
|
|
expect(result.standings).toEqual([
|
|
{
|
|
id: 's1',
|
|
leagueId,
|
|
seasonId: 'season-1',
|
|
driverId: 'driver-1',
|
|
position: 1,
|
|
points: 100,
|
|
wins: 3,
|
|
podiums: 5,
|
|
racesCompleted: 10,
|
|
},
|
|
{
|
|
id: 's2',
|
|
leagueId,
|
|
seasonId: '',
|
|
driverId: 'driver-2',
|
|
position: 2,
|
|
points: 80,
|
|
wins: 1,
|
|
podiums: 0,
|
|
racesCompleted: 10,
|
|
},
|
|
]);
|
|
});
|
|
});
|