import { describe, expect, it } from 'vitest'; import type { ChampionshipConfig } from '../types/ChampionshipConfig'; import { PointsTable } from '../value-objects/PointsTable'; import { LeagueScoringConfig } from './LeagueScoringConfig'; const mockPointsTable = new PointsTable({ 1: 25, 2: 18, 3: 15 }); const mockChampionshipConfig: ChampionshipConfig = { id: 'champ1', name: 'Championship 1', type: 'driver', sessionTypes: ['main'], pointsTableBySessionType: { practice: mockPointsTable, qualifying: mockPointsTable, q1: mockPointsTable, q2: mockPointsTable, q3: mockPointsTable, sprint: mockPointsTable, main: mockPointsTable, timeTrial: mockPointsTable, }, dropScorePolicy: { strategy: 'none' }, }; describe('LeagueScoringConfig', () => { it('should create a league scoring config', () => { const config = LeagueScoringConfig.create({ seasonId: 'season1', championships: [mockChampionshipConfig], }); expect(config.id.toString()).toBe('scoring-config-season1'); expect(config.seasonId.toString()).toBe('season1'); expect(config.scoringPresetId).toBeUndefined(); expect(config.championships).toEqual([mockChampionshipConfig]); }); it('should create with custom id', () => { const config = LeagueScoringConfig.create({ id: 'custom-id', seasonId: 'season1', scoringPresetId: 'preset1', championships: [mockChampionshipConfig], }); expect(config.id.toString()).toBe('custom-id'); expect(config.scoringPresetId?.toString()).toBe('preset1'); }); it('should throw on invalid seasonId', () => { expect(() => LeagueScoringConfig.create({ seasonId: '', championships: [mockChampionshipConfig], })).toThrow('Season ID is required'); }); it('should throw on empty championships', () => { expect(() => LeagueScoringConfig.create({ seasonId: 'season1', championships: [], })).toThrow('At least one championship is required'); }); it('should create with multiple championships', () => { const config = LeagueScoringConfig.create({ seasonId: 'season1', championships: [mockChampionshipConfig, { ...mockChampionshipConfig, id: 'champ2' }], }); expect(config.championships).toHaveLength(2); }); });