fix issues in core
This commit is contained in:
58
core/testing/factories/racing/ChampionshipConfigFactory.ts
Normal file
58
core/testing/factories/racing/ChampionshipConfigFactory.ts
Normal file
@@ -0,0 +1,58 @@
|
||||
import type { ChampionshipConfig } from '../../../racing/domain/types/ChampionshipConfig';
|
||||
import type { ChampionshipType } from '../../../racing/domain/types/ChampionshipType';
|
||||
import type { SessionType } from '../../../racing/domain/types/SessionType';
|
||||
import type { BonusRule } from '../../../racing/domain/types/BonusRule';
|
||||
import type { DropScorePolicy, DropScoreStrategy } from '../../../racing/domain/types/DropScorePolicy';
|
||||
import { PointsTable } from '../../../racing/domain/value-objects/PointsTable';
|
||||
|
||||
interface ChampionshipConfigInput {
|
||||
id: string;
|
||||
name: string;
|
||||
sessionTypes: SessionType[];
|
||||
mainPoints?: number[];
|
||||
mainBonusRules?: BonusRule[];
|
||||
type?: ChampionshipType;
|
||||
dropScorePolicy?: DropScorePolicy;
|
||||
strategy?: DropScoreStrategy;
|
||||
}
|
||||
|
||||
export function makeChampionshipConfig(input: ChampionshipConfigInput): ChampionshipConfig {
|
||||
const {
|
||||
id,
|
||||
name,
|
||||
sessionTypes,
|
||||
mainPoints = [25, 18, 15, 12, 10, 8, 6, 4, 2, 1],
|
||||
mainBonusRules = [],
|
||||
type = 'driver',
|
||||
dropScorePolicy = { strategy: 'none' },
|
||||
} = input;
|
||||
|
||||
const pointsTableBySessionType: Record<SessionType, PointsTable> = {} as Record<SessionType, PointsTable>;
|
||||
|
||||
// Convert array format to PointsTable for each session type
|
||||
sessionTypes.forEach(sessionType => {
|
||||
const pointsArray = mainPoints;
|
||||
const pointsMap: Record<number, number> = {};
|
||||
pointsArray.forEach((points, index) => {
|
||||
pointsMap[index + 1] = points;
|
||||
});
|
||||
pointsTableBySessionType[sessionType] = new PointsTable(pointsMap);
|
||||
});
|
||||
|
||||
const bonusRulesBySessionType: Record<SessionType, BonusRule[]> = {} as Record<SessionType, BonusRule[]>;
|
||||
|
||||
// Add bonus rules for each session type
|
||||
sessionTypes.forEach(sessionType => {
|
||||
bonusRulesBySessionType[sessionType] = mainBonusRules;
|
||||
});
|
||||
|
||||
return {
|
||||
id,
|
||||
name,
|
||||
type,
|
||||
sessionTypes,
|
||||
pointsTableBySessionType,
|
||||
bonusRulesBySessionType,
|
||||
dropScorePolicy,
|
||||
};
|
||||
}
|
||||
9
core/testing/factories/racing/DriverRefFactory.ts
Normal file
9
core/testing/factories/racing/DriverRefFactory.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import type { DriverId } from '../../../racing/domain/entities/DriverId';
|
||||
import type { ParticipantRef } from '../../../racing/domain/types/ParticipantRef';
|
||||
|
||||
export function makeDriverRef(driverId: string): ParticipantRef {
|
||||
return {
|
||||
id: driverId,
|
||||
type: 'driver',
|
||||
};
|
||||
}
|
||||
5
core/testing/factories/racing/PointsTableFactory.ts
Normal file
5
core/testing/factories/racing/PointsTableFactory.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
import { PointsTable } from '../../../racing/domain/value-objects/PointsTable';
|
||||
|
||||
export function makePointsTable(points: number[]): PointsTable {
|
||||
return new PointsTable(points);
|
||||
}
|
||||
Reference in New Issue
Block a user