wip league admin tools
This commit is contained in:
@@ -4,6 +4,7 @@ import { RacesApiClient } from '../../api/races/RacesApiClient';
|
||||
import { RaceDetailViewModel } from '../../view-models/RaceDetailViewModel';
|
||||
import { RacesPageViewModel } from '../../view-models/RacesPageViewModel';
|
||||
import { RaceStatsViewModel } from '../../view-models/RaceStatsViewModel';
|
||||
import type { RaceDetailsViewModel } from '../../view-models/RaceDetailsViewModel';
|
||||
|
||||
describe('RaceService', () => {
|
||||
let mockApiClient: Mocked<RacesApiClient>;
|
||||
@@ -57,6 +58,38 @@ describe('RaceService', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('getRaceDetails', () => {
|
||||
it('should call apiClient.getDetail and return a ViewModel-shaped object (no DTOs)', async () => {
|
||||
const raceId = 'race-123';
|
||||
const driverId = 'driver-456';
|
||||
|
||||
const mockDto = {
|
||||
race: {
|
||||
id: raceId,
|
||||
track: 'Test Track',
|
||||
car: 'Test Car',
|
||||
scheduledAt: '2023-12-31T20:00:00Z',
|
||||
status: 'completed',
|
||||
sessionType: 'race',
|
||||
},
|
||||
league: { id: 'league-1', name: 'Test League', description: 'Desc', settings: { maxDrivers: 32 } },
|
||||
entryList: [],
|
||||
registration: { isUserRegistered: true, canRegister: false },
|
||||
userResult: null,
|
||||
};
|
||||
|
||||
mockApiClient.getDetail.mockResolvedValue(mockDto as any);
|
||||
|
||||
const result: RaceDetailsViewModel = await service.getRaceDetails(raceId, driverId);
|
||||
|
||||
expect(mockApiClient.getDetail).toHaveBeenCalledWith(raceId, driverId);
|
||||
expect(result.race?.id).toBe(raceId);
|
||||
expect(result.league?.id).toBe('league-1');
|
||||
expect(result.registration.isUserRegistered).toBe(true);
|
||||
expect(result.canReopenRace).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getRacesPageData', () => {
|
||||
it('should call apiClient.getPageData and return RacesPageViewModel with transformed data', async () => {
|
||||
const mockDto = {
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
import { RacesApiClient } from '../../api/races/RacesApiClient';
|
||||
import { RaceDetailEntryViewModel } from '../../view-models/RaceDetailEntryViewModel';
|
||||
import { RaceDetailUserResultViewModel } from '../../view-models/RaceDetailUserResultViewModel';
|
||||
import { RaceDetailViewModel } from '../../view-models/RaceDetailViewModel';
|
||||
import { RacesPageViewModel } from '../../view-models/RacesPageViewModel';
|
||||
import { RaceStatsViewModel } from '../../view-models/RaceStatsViewModel';
|
||||
import type { RaceDetailsViewModel } from '../../view-models/RaceDetailsViewModel';
|
||||
import type { FileProtestCommandDTO } from '../../types/generated/FileProtestCommandDTO';
|
||||
import type { RaceStatsDTO } from '../../types/generated/RaceStatsDTO';
|
||||
/**
|
||||
@@ -26,6 +29,55 @@ export class RaceService {
|
||||
return new RaceDetailViewModel(dto, driverId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get race details for pages/components (DTO-free shape)
|
||||
*/
|
||||
async getRaceDetails(
|
||||
raceId: string,
|
||||
driverId: string
|
||||
): Promise<RaceDetailsViewModel> {
|
||||
const dto: any = await this.apiClient.getDetail(raceId, driverId);
|
||||
|
||||
const raceDto: any = dto?.race ?? null;
|
||||
const leagueDto: any = dto?.league ?? null;
|
||||
|
||||
const registrationDto: any = dto?.registration ?? {};
|
||||
const isUserRegistered = Boolean(registrationDto.isUserRegistered ?? registrationDto.isRegistered ?? false);
|
||||
const canRegister = Boolean(registrationDto.canRegister);
|
||||
|
||||
const status = String(raceDto?.status ?? '');
|
||||
const canReopenRace = status === 'completed' || status === 'cancelled';
|
||||
|
||||
return {
|
||||
race: raceDto
|
||||
? {
|
||||
id: String(raceDto.id ?? ''),
|
||||
track: String(raceDto.track ?? ''),
|
||||
car: String(raceDto.car ?? ''),
|
||||
scheduledAt: String(raceDto.scheduledAt ?? ''),
|
||||
status,
|
||||
sessionType: String(raceDto.sessionType ?? ''),
|
||||
}
|
||||
: null,
|
||||
league: leagueDto
|
||||
? {
|
||||
id: String(leagueDto.id ?? ''),
|
||||
name: String(leagueDto.name ?? ''),
|
||||
description: leagueDto.description ?? null,
|
||||
settings: leagueDto.settings,
|
||||
}
|
||||
: null,
|
||||
entryList: (dto?.entryList ?? []).map((entry: any) => new RaceDetailEntryViewModel(entry, driverId)),
|
||||
registration: {
|
||||
canRegister,
|
||||
isUserRegistered,
|
||||
},
|
||||
userResult: dto?.userResult ? new RaceDetailUserResultViewModel(dto.userResult) : null,
|
||||
canReopenRace,
|
||||
error: dto?.error,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Get races page data with view model transformation
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user