import { describe, it, expect, vi } from 'vitest'; import { ChampionshipAggregator } from './ChampionshipAggregator'; import type { DropScoreApplier } from './DropScoreApplier'; import { Points } from '../value-objects/Points'; describe('ChampionshipAggregator', () => { const mockDropScoreApplier = { apply: vi.fn(), } as unknown as DropScoreApplier; const aggregator = new ChampionshipAggregator(mockDropScoreApplier); it('should aggregate points and sort standings by total points', () => { const seasonId = 'season-1'; const championship = { id: 'champ-1', dropScorePolicy: { strategy: 'none' }, } as any; const eventPointsByEventId = { 'event-1': [ { participant: { id: 'p1', type: 'driver' }, totalPoints: 10, basePoints: 10, bonusPoints: 0, penaltyPoints: 0 }, { participant: { id: 'p2', type: 'driver' }, totalPoints: 20, basePoints: 20, bonusPoints: 0, penaltyPoints: 0 }, ], 'event-2': [ { participant: { id: 'p1', type: 'driver' }, totalPoints: 15, basePoints: 15, bonusPoints: 0, penaltyPoints: 0 }, ], } as any; vi.mocked(mockDropScoreApplier.apply).mockImplementation((policy, events) => { const total = events.reduce((sum, e) => sum + e.points, 0); return { totalPoints: total, counted: events, dropped: [], }; }); const standings = aggregator.aggregate({ seasonId, championship, eventPointsByEventId, }); expect(standings).toHaveLength(2); // p1 should be first (10 + 15 = 25 points) expect(standings[0].participant.id).toBe('p1'); expect(standings[0].totalPoints.toNumber()).toBe(25); expect(standings[0].position.toNumber()).toBe(1); // p2 should be second (20 points) expect(standings[1].participant.id).toBe('p2'); expect(standings[1].totalPoints.toNumber()).toBe(20); expect(standings[1].position.toNumber()).toBe(2); }); });