fix core tests
This commit is contained in:
@@ -6,6 +6,10 @@ import type { ILeagueRepository } from '../../domain/repositories/ILeagueReposit
|
||||
import type { ISeasonRepository } from '../../domain/repositories/ISeasonRepository';
|
||||
import type { ILeagueScoringConfigRepository } from '../../domain/repositories/ILeagueScoringConfigRepository';
|
||||
import type { Logger, UseCaseOutputPort } from '@core/shared/application';
|
||||
import type { ChampionshipConfig } from '../../domain/types/ChampionshipConfig';
|
||||
import type { SessionType } from '../../domain/types/SessionType';
|
||||
import type { BonusRule } from '../../domain/types/BonusRule';
|
||||
import { PointsTable } from '../../domain/value-objects/PointsTable';
|
||||
import {
|
||||
LeagueVisibility,
|
||||
MIN_RANKED_LEAGUE_DRIVERS,
|
||||
@@ -114,10 +118,11 @@ export class CreateLeagueWithSeasonAndScoringUseCase {
|
||||
}
|
||||
this.logger.info(`Scoring preset ${preset.name} (${preset.id}) retrieved.`);
|
||||
|
||||
const championships = this.createDefaultChampionshipConfigs(command);
|
||||
const scoringConfig = LeagueScoringConfig.create({
|
||||
seasonId,
|
||||
scoringPresetId: preset.id,
|
||||
championships: [], // Empty array - will be populated by preset
|
||||
championships,
|
||||
});
|
||||
this.logger.debug(`Scoring configuration created from preset ${preset.id}.`);
|
||||
|
||||
@@ -142,6 +147,92 @@ export class CreateLeagueWithSeasonAndScoringUseCase {
|
||||
}
|
||||
}
|
||||
|
||||
private createDefaultChampionshipConfigs(
|
||||
command: CreateLeagueWithSeasonAndScoringCommand,
|
||||
): ChampionshipConfig[] {
|
||||
const sessionTypes: SessionType[] = ['main'];
|
||||
|
||||
const defaultPoints = [25, 18, 15, 12, 10, 8, 6, 4, 2, 1];
|
||||
const pointsMap: Record<number, number> = {};
|
||||
defaultPoints.forEach((points, index) => {
|
||||
pointsMap[index + 1] = points;
|
||||
});
|
||||
|
||||
const pointsTableBySessionType: Record<SessionType, PointsTable> =
|
||||
{} as Record<SessionType, PointsTable>;
|
||||
const bonusRulesBySessionType: Record<SessionType, BonusRule[]> =
|
||||
{} as Record<SessionType, BonusRule[]>;
|
||||
|
||||
for (const sessionType of sessionTypes) {
|
||||
pointsTableBySessionType[sessionType] = new PointsTable(pointsMap);
|
||||
bonusRulesBySessionType[sessionType] = [];
|
||||
}
|
||||
|
||||
const configs: ChampionshipConfig[] = [];
|
||||
|
||||
if (command.enableDriverChampionship) {
|
||||
configs.push({
|
||||
id: uuidv4(),
|
||||
name: 'Driver Championship',
|
||||
type: 'driver',
|
||||
sessionTypes,
|
||||
pointsTableBySessionType,
|
||||
bonusRulesBySessionType,
|
||||
dropScorePolicy: { strategy: 'none' },
|
||||
});
|
||||
}
|
||||
|
||||
if (command.enableTeamChampionship) {
|
||||
configs.push({
|
||||
id: uuidv4(),
|
||||
name: 'Team Championship',
|
||||
type: 'team',
|
||||
sessionTypes,
|
||||
pointsTableBySessionType,
|
||||
bonusRulesBySessionType,
|
||||
dropScorePolicy: { strategy: 'none' },
|
||||
});
|
||||
}
|
||||
|
||||
if (command.enableNationsChampionship) {
|
||||
configs.push({
|
||||
id: uuidv4(),
|
||||
name: 'Nations Championship',
|
||||
type: 'nations',
|
||||
sessionTypes,
|
||||
pointsTableBySessionType,
|
||||
bonusRulesBySessionType,
|
||||
dropScorePolicy: { strategy: 'none' },
|
||||
});
|
||||
}
|
||||
|
||||
if (command.enableTrophyChampionship) {
|
||||
configs.push({
|
||||
id: uuidv4(),
|
||||
name: 'Trophy Championship',
|
||||
type: 'trophy',
|
||||
sessionTypes,
|
||||
pointsTableBySessionType,
|
||||
bonusRulesBySessionType,
|
||||
dropScorePolicy: { strategy: 'none' },
|
||||
});
|
||||
}
|
||||
|
||||
if (configs.length === 0) {
|
||||
configs.push({
|
||||
id: uuidv4(),
|
||||
name: 'Driver Championship',
|
||||
type: 'driver',
|
||||
sessionTypes,
|
||||
pointsTableBySessionType,
|
||||
bonusRulesBySessionType,
|
||||
dropScorePolicy: { strategy: 'none' },
|
||||
});
|
||||
}
|
||||
|
||||
return configs;
|
||||
}
|
||||
|
||||
private validate(
|
||||
command: CreateLeagueWithSeasonAndScoringCommand,
|
||||
): Result<void, ApplicationErrorCode<'VALIDATION_ERROR', { message: string }>> {
|
||||
|
||||
Reference in New Issue
Block a user