77 lines
2.2 KiB
TypeScript
77 lines
2.2 KiB
TypeScript
import { Result } from '@core/shared/application/Result';
|
|
import { GetAllRacesPresenter } from './GetAllRacesPresenter';
|
|
import type { GetAllRacesResult } from '@core/racing/application/use-cases/GetAllRacesUseCase';
|
|
|
|
describe('GetAllRacesPresenter', () => {
|
|
it('should map races and distinct leagues into the DTO', async () => {
|
|
const presenter = new GetAllRacesPresenter();
|
|
|
|
const output: GetAllRacesOutputPort = {
|
|
races: [
|
|
{
|
|
id: 'race-1',
|
|
leagueId: 'league-1',
|
|
track: 'Track A',
|
|
car: 'Car A',
|
|
status: 'scheduled',
|
|
scheduledAt: '2025-01-01T10:00:00.000Z',
|
|
strengthOfField: 1500,
|
|
leagueName: 'League One',
|
|
},
|
|
{
|
|
id: 'race-2',
|
|
leagueId: 'league-1',
|
|
track: 'Track B',
|
|
car: 'Car B',
|
|
status: 'completed',
|
|
scheduledAt: '2025-01-02T10:00:00.000Z',
|
|
strengthOfField: null,
|
|
leagueName: 'League One',
|
|
},
|
|
{
|
|
id: 'race-3',
|
|
leagueId: 'league-2',
|
|
track: 'Track C',
|
|
car: 'Car C',
|
|
status: 'running',
|
|
scheduledAt: '2025-01-03T10:00:00.000Z',
|
|
strengthOfField: 1800,
|
|
leagueName: 'League Two',
|
|
},
|
|
],
|
|
totalCount: 3,
|
|
};
|
|
|
|
await presenter.present(output);
|
|
const viewModel = presenter.getViewModel();
|
|
|
|
expect(viewModel).not.toBeNull();
|
|
expect(viewModel!.races).toHaveLength(3);
|
|
|
|
// Leagues should be distinct and match league ids/names from races
|
|
expect(viewModel!.filters.leagues).toEqual(
|
|
expect.arrayContaining([
|
|
{ id: 'league-1', name: 'League One' },
|
|
{ id: 'league-2', name: 'League Two' },
|
|
]),
|
|
);
|
|
expect(viewModel!.filters.leagues).toHaveLength(2);
|
|
});
|
|
|
|
it('should handle empty races by returning empty leagues', async () => {
|
|
const presenter = new GetAllRacesPresenter();
|
|
|
|
const output: GetAllRacesOutputPort = {
|
|
races: [],
|
|
totalCount: 0,
|
|
};
|
|
|
|
await presenter.present(output);
|
|
const viewModel = presenter.getViewModel();
|
|
|
|
expect(viewModel).not.toBeNull();
|
|
expect(viewModel!.races).toHaveLength(0);
|
|
expect(viewModel!.filters.leagues).toHaveLength(0);
|
|
});
|
|
})
|