Files
gridpilot.gg/apps/api/src/domain/race/presenters/GetAllRacesPresenter.test.ts

83 lines
2.6 KiB
TypeScript

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: GetAllRacesResult = {
races: [
{
id: 'race-1',
leagueId: 'league-1',
track: 'Track A',
car: 'Car A',
status: 'scheduled',
scheduledAt: new Date('2025-01-01T10:00:00.000Z'),
strengthOfField: 1500,
},
{
id: 'race-2',
leagueId: 'league-1',
track: 'Track B',
car: 'Car B',
status: 'completed',
scheduledAt: new Date('2025-01-02T10:00:00.000Z'),
strengthOfField: undefined,
},
{
id: 'race-3',
leagueId: 'league-2',
track: 'Track C',
car: 'Car C',
status: 'running',
scheduledAt: new Date('2025-01-03T10:00:00.000Z'),
strengthOfField: 1800,
},
// eslint-disable-next-line @typescript-eslint/no-explicit-any
] as any,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
leagues: [
{ id: 'league-1', name: 'League One' },
{ id: 'league-2', name: 'League Two' },
// eslint-disable-next-line @typescript-eslint/no-explicit-any
] as any,
totalCount: 3,
};
await presenter.present(output);
const viewModel = presenter.getResponseModel();
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: GetAllRacesResult = {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
races: [] as any,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
leagues: [] as any,
totalCount: 0,
};
await presenter.present(output);
const viewModel = presenter.getResponseModel();
expect(viewModel).not.toBeNull();
expect(viewModel!.races).toHaveLength(0);
expect(viewModel!.filters.leagues).toHaveLength(0);
});
})