website refactor
This commit is contained in:
@@ -1,15 +1,18 @@
|
||||
import { describe, it, expect, vi, Mocked, beforeEach } from 'vitest';
|
||||
import { LeagueService } from './LeagueService';
|
||||
import { LeaguesApiClient } from '@/lib/api/leagues/LeaguesApiClient';
|
||||
import { RacesApiClient } from '@/lib/api/races/RacesApiClient';
|
||||
import type { CreateLeagueInputDTO } from '@/lib/types/generated/CreateLeagueInputDTO';
|
||||
import type { CreateLeagueOutputDTO } from '@/lib/types/generated/CreateLeagueOutputDTO';
|
||||
import type { RemoveLeagueMemberOutputDTO } from '@/lib/types/generated/RemoveLeagueMemberOutputDTO';
|
||||
|
||||
describe('LeagueService', () => {
|
||||
let mockApiClient: Mocked<LeaguesApiClient>;
|
||||
let mockRacesApiClient: Mocked<RacesApiClient>;
|
||||
let service: LeagueService;
|
||||
|
||||
beforeEach(() => {
|
||||
process.env.API_BASE_URL = process.env.API_BASE_URL || 'http://localhost:3001';
|
||||
mockApiClient = {
|
||||
getAllWithCapacity: vi.fn(),
|
||||
getAllWithCapacityAndScoring: vi.fn(),
|
||||
@@ -17,12 +20,20 @@ describe('LeagueService', () => {
|
||||
getTotal: vi.fn(),
|
||||
getSchedule: vi.fn(),
|
||||
getMemberships: vi.fn(),
|
||||
getLeagueConfig: vi.fn(),
|
||||
create: vi.fn(),
|
||||
removeRosterMember: vi.fn(),
|
||||
updateRosterMemberRole: vi.fn(),
|
||||
} as unknown as Mocked<LeaguesApiClient>;
|
||||
|
||||
mockRacesApiClient = {
|
||||
getPageData: vi.fn(),
|
||||
} as unknown as Mocked<RacesApiClient>;
|
||||
|
||||
mockApiClient.getLeagueConfig.mockResolvedValue({ form: null } as any);
|
||||
|
||||
service = new LeagueService(mockApiClient);
|
||||
(service as any).racesApiClient = mockRacesApiClient;
|
||||
});
|
||||
|
||||
describe('getAllLeagues', () => {
|
||||
@@ -145,6 +156,43 @@ describe('LeagueService', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('getLeagueDetailData', () => {
|
||||
it('should use races page-data to enrich races with status/strengthOfField', async () => {
|
||||
const leagueId = 'league-123';
|
||||
const league = { id: leagueId, name: 'League One', createdAt: '2024-01-01T00:00:00Z' } as any;
|
||||
|
||||
mockApiClient.getAllWithCapacityAndScoring.mockResolvedValue({ totalCount: 1, leagues: [league] } as any);
|
||||
mockApiClient.getMemberships.mockResolvedValue({ members: [] } as any);
|
||||
mockRacesApiClient.getPageData.mockResolvedValue({
|
||||
races: [
|
||||
{
|
||||
id: 'race-1',
|
||||
track: 'Monza',
|
||||
car: 'GT3',
|
||||
scheduledAt: '2026-01-01T00:00:00.000Z',
|
||||
status: 'running',
|
||||
leagueId,
|
||||
leagueName: 'League One',
|
||||
strengthOfField: 2500,
|
||||
isUpcoming: false,
|
||||
isLive: true,
|
||||
isPast: false,
|
||||
},
|
||||
],
|
||||
} as any);
|
||||
|
||||
const result = await service.getLeagueDetailData(leagueId);
|
||||
|
||||
expect(result.isOk()).toBe(true);
|
||||
const dto = result.unwrap();
|
||||
expect(dto.races).toHaveLength(1);
|
||||
expect((dto.races[0] as any).status).toBe('running');
|
||||
expect((dto.races[0] as any).strengthOfField).toBe(2500);
|
||||
expect(dto.races[0]!.name).toBe('Monza - GT3');
|
||||
expect(dto.races[0]!.date).toBe('2026-01-01T00:00:00.000Z');
|
||||
});
|
||||
});
|
||||
|
||||
describe('getLeagueMemberships', () => {
|
||||
it('should call apiClient.getMemberships and return DTO', async () => {
|
||||
const leagueId = 'league-123';
|
||||
|
||||
Reference in New Issue
Block a user