Files
gridpilot.gg/core/racing/domain/services/ChampionshipAggregator.test.ts
Marc Mintel bf2c0fdb0c
Some checks failed
CI / lint-typecheck (pull_request) Failing after 1m29s
CI / tests (pull_request) Has been skipped
CI / contract-tests (pull_request) Has been skipped
CI / e2e-tests (pull_request) Has been skipped
CI / comment-pr (pull_request) Has been skipped
CI / commit-types (pull_request) Has been skipped
code quality
2026-01-26 01:54:57 +01:00

75 lines
2.0 KiB
TypeScript

import { describe, it, expect, vi } from 'vitest';
import { ChampionshipAggregator } from './ChampionshipAggregator';
import type { DropScoreApplier } from './DropScoreApplier';
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);
});
});