refactor to adapters
This commit is contained in:
49
testing/factories/racing/ChampionshipConfigFactory.ts
Normal file
49
testing/factories/racing/ChampionshipConfigFactory.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
import type { SessionType } from '@gridpilot/racing/domain/types/SessionType';
|
||||
import { PointsTable } from '@gridpilot/racing/domain/value-objects/PointsTable';
|
||||
import type { BonusRule } from '@gridpilot/racing/domain/types/BonusRule';
|
||||
import type { ChampionshipConfig } from '@gridpilot/racing/domain/types/ChampionshipConfig';
|
||||
import { makePointsTable } from './PointsTableFactory';
|
||||
|
||||
export const 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',
|
||||
},
|
||||
};
|
||||
};
|
||||
7
testing/factories/racing/DriverRefFactory.ts
Normal file
7
testing/factories/racing/DriverRefFactory.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import type { ParticipantRef } from '@gridpilot/racing/domain/types/ParticipantRef';
|
||||
import type { ChampionshipType } from '@gridpilot/racing/domain/types/ChampionshipType';
|
||||
|
||||
export const makeDriverRef = (id: string): ParticipantRef => ({
|
||||
type: 'driver' as ChampionshipType,
|
||||
id,
|
||||
});
|
||||
9
testing/factories/racing/PointsTableFactory.ts
Normal file
9
testing/factories/racing/PointsTableFactory.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import { PointsTable } from '@gridpilot/racing/domain/value-objects/PointsTable';
|
||||
|
||||
export const makePointsTable = (points: number[]): PointsTable => {
|
||||
const pointsByPosition: Record<number, number> = {};
|
||||
points.forEach((value, index) => {
|
||||
pointsByPosition[index + 1] = value;
|
||||
});
|
||||
return new PointsTable(pointsByPosition);
|
||||
};
|
||||
23
testing/factories/racing/SeasonFactory.ts
Normal file
23
testing/factories/racing/SeasonFactory.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { Season } from '@gridpilot/racing/domain/entities/Season';
|
||||
import type { SeasonStatus } from '@gridpilot/racing/domain/entities/Season';
|
||||
|
||||
export const createMinimalSeason = (overrides?: { status?: SeasonStatus }) =>
|
||||
Season.create({
|
||||
id: 'season-1',
|
||||
leagueId: 'league-1',
|
||||
gameId: 'iracing',
|
||||
name: 'Test Season',
|
||||
status: overrides?.status ?? 'planned',
|
||||
});
|
||||
|
||||
export const createBaseSeason = () =>
|
||||
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,
|
||||
});
|
||||
Reference in New Issue
Block a user