refactor to adapters
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { AnalyticsEntityId } from '../../../../../core/analytics/domain/value-objects/AnalyticsEntityId';
|
||||
import { AnalyticsEntityId } from '../../../core/analytics/domain/value-objects/AnalyticsEntityId';
|
||||
|
||||
describe('AnalyticsEntityId', () => {
|
||||
it('creates a valid AnalyticsEntityId from a non-empty string', () => {
|
||||
@@ -1,4 +1,4 @@
|
||||
import { AnalyticsSessionId } from '../../../../../core/analytics/domain/value-objects/AnalyticsSessionId';
|
||||
import { AnalyticsSessionId } from '../../../core/analytics/domain/value-objects/AnalyticsSessionId';
|
||||
|
||||
describe('AnalyticsSessionId', () => {
|
||||
it('creates a valid AnalyticsSessionId from a non-empty string', () => {
|
||||
@@ -1,4 +1,4 @@
|
||||
import { PageViewId } from '../../../../../core/analytics/domain/value-objects/PageViewId';
|
||||
import { PageViewId } from '../../../core/analytics/domain/value-objects/PageViewId';
|
||||
|
||||
describe('PageViewId', () => {
|
||||
it('creates a valid PageViewId from a non-empty string', () => {
|
||||
@@ -9,65 +9,10 @@ import type { ChampionshipConfig } from '@gridpilot/racing/domain/types/Champion
|
||||
import { Result } from '@gridpilot/racing/domain/entities/Result';
|
||||
import type { Penalty } from '@gridpilot/racing/domain/entities/Penalty';
|
||||
import type { ChampionshipType } from '@gridpilot/racing/domain/types/ChampionshipType';
|
||||
import { makeDriverRef } from '../../testing/factories/racing/DriverRefFactory';
|
||||
import { makePointsTable } from '../../testing/factories/racing/PointsTableFactory';
|
||||
import { makeChampionshipConfig } from '../../testing/factories/racing/ChampionshipConfigFactory';
|
||||
|
||||
function makeDriverRef(id: string): ParticipantRef {
|
||||
return {
|
||||
type: 'driver' as ChampionshipType,
|
||||
id,
|
||||
};
|
||||
}
|
||||
|
||||
function makePointsTable(points: number[]): PointsTable {
|
||||
const pointsByPosition: Record<number, number> = {};
|
||||
points.forEach((value, index) => {
|
||||
pointsByPosition[index + 1] = value;
|
||||
});
|
||||
return new PointsTable(pointsByPosition);
|
||||
}
|
||||
|
||||
function makeChampionshipConfig(params: {
|
||||
id: string;
|
||||
name: string;
|
||||
sessionTypes: SessionType[];
|
||||
mainPoints: number[];
|
||||
sprintPoints?: number[];
|
||||
mainBonusRules?: BonusRule[];
|
||||
}): ChampionshipConfig {
|
||||
const { id, name, sessionTypes, mainPoints, sprintPoints, mainBonusRules } = params;
|
||||
|
||||
const pointsTableBySessionType: Record<SessionType, PointsTable> = {} as Record<SessionType, PointsTable>;
|
||||
|
||||
sessionTypes.forEach((sessionType) => {
|
||||
if (sessionType === 'main') {
|
||||
pointsTableBySessionType[sessionType] = makePointsTable(mainPoints);
|
||||
} else if (sessionType === 'sprint' && sprintPoints) {
|
||||
pointsTableBySessionType[sessionType] = makePointsTable(sprintPoints);
|
||||
} else {
|
||||
pointsTableBySessionType[sessionType] = new PointsTable({});
|
||||
}
|
||||
});
|
||||
|
||||
const bonusRulesBySessionType: Record<SessionType, BonusRule[]> = {} as Record<SessionType, BonusRule[]>;
|
||||
sessionTypes.forEach((sessionType) => {
|
||||
if (sessionType === 'main' && mainBonusRules) {
|
||||
bonusRulesBySessionType[sessionType] = mainBonusRules;
|
||||
} else {
|
||||
bonusRulesBySessionType[sessionType] = [];
|
||||
}
|
||||
});
|
||||
|
||||
return {
|
||||
id,
|
||||
name,
|
||||
type: 'driver',
|
||||
sessionTypes,
|
||||
pointsTableBySessionType,
|
||||
bonusRulesBySessionType,
|
||||
dropScorePolicy: {
|
||||
strategy: 'none',
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
describe('EventScoringService', () => {
|
||||
const seasonId = 'season-1';
|
||||
@@ -14,16 +14,8 @@ import {
|
||||
type SeasonDropStrategy,
|
||||
} from '@gridpilot/racing/domain/value-objects/SeasonDropPolicy';
|
||||
import { SeasonStewardingConfig } from '@gridpilot/racing/domain/value-objects/SeasonStewardingConfig';
|
||||
import { createMinimalSeason, createBaseSeason } from '../../testing/factories/racing/SeasonFactory';
|
||||
|
||||
function createMinimalSeason(overrides?: Partial<Season> & { status?: SeasonStatus }) {
|
||||
return Season.create({
|
||||
id: 'season-1',
|
||||
leagueId: 'league-1',
|
||||
gameId: 'iracing',
|
||||
name: 'Test Season',
|
||||
status: overrides?.status ?? 'planned',
|
||||
});
|
||||
}
|
||||
|
||||
describe('Season aggregate lifecycle', () => {
|
||||
it('transitions Planned → Active → Completed → Archived with timestamps', () => {
|
||||
@@ -125,18 +117,6 @@ describe('Season aggregate lifecycle', () => {
|
||||
});
|
||||
|
||||
describe('Season configuration updates', () => {
|
||||
function createBaseSeason() {
|
||||
return Season.create({
|
||||
id: 'season-1',
|
||||
leagueId: 'league-1',
|
||||
gameId: 'iracing',
|
||||
name: 'Config Season',
|
||||
status: 'planned',
|
||||
startDate: new Date('2025-01-01T00:00:00Z'),
|
||||
endDate: undefined,
|
||||
maxDrivers: 24,
|
||||
});
|
||||
}
|
||||
|
||||
it('withScoringConfig returns a new Season with updated scoringConfig only', () => {
|
||||
const season = createBaseSeason();
|
||||
Reference in New Issue
Block a user