website refactor

This commit is contained in:
2026-01-16 15:20:25 +01:00
parent 7e02fc3ea5
commit 37b1aa626c
325 changed files with 2167 additions and 2782 deletions

View File

@@ -1,22 +1,12 @@
import { describe, it, expect, beforeEach, vi, type Mock } from 'vitest';
import {
RecalculateChampionshipStandingsUseCase,
type RecalculateChampionshipStandingsInput,
type RecalculateChampionshipStandingsResult,
type RecalculateChampionshipStandingsErrorCode,
} from './RecalculateChampionshipStandingsUseCase';
import type { SeasonRepository } from '../../domain/repositories/SeasonRepository';
import type { LeagueScoringConfigRepository } from '../../domain/repositories/LeagueScoringConfigRepository';
import type { RaceRepository } from '../../domain/repositories/RaceRepository';
import type { ResultRepository } from '../../domain/repositories/ResultRepository';
import type { PenaltyRepository } from '../../domain/repositories/PenaltyRepository';
import type { ChampionshipStandingRepository } from '../../domain/repositories/ChampionshipStandingRepository';
import type { Penalty } from '../../domain/entities/Penalty';
import { EventScoringService } from '../../domain/services/EventScoringService';
import type { LeagueRepository } from '../../domain/repositories/LeagueRepository';
import { ChampionshipAggregator } from '../../domain/services/ChampionshipAggregator';
import type { Logger } from '@core/shared/domain/Logger';
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
import { beforeEach, describe, expect, it, vi, type Mock } from 'vitest';
import type { Penalty } from '../../domain/entities/Penalty';
import {
RecalculateChampionshipStandingsUseCase,
type RecalculateChampionshipStandingsErrorCode,
type RecalculateChampionshipStandingsInput
} from './RecalculateChampionshipStandingsUseCase';
describe('RecalculateChampionshipStandingsUseCase', () => {
let useCase: RecalculateChampionshipStandingsUseCase;
@@ -30,7 +20,6 @@ describe('RecalculateChampionshipStandingsUseCase', () => {
let eventScoringService: { scoreSession: Mock };
let championshipAggregator: { aggregate: Mock };
let logger: Logger;
};
beforeEach(() => {
leagueRepository = { findById: vi.fn() };
@@ -47,18 +36,17 @@ describe('RecalculateChampionshipStandingsUseCase', () => {
info: vi.fn(),
warn: vi.fn(),
error: vi.fn(),
};
output = { present: vi.fn() } as unknown as typeof output;
} as any;
useCase = new RecalculateChampionshipStandingsUseCase(leagueRepository as unknown as ILeagueRepository,
seasonRepository as unknown as ISeasonRepository,
leagueScoringConfigRepository as unknown as ILeagueScoringConfigRepository,
raceRepository as unknown as IRaceRepository,
resultRepository as unknown as IResultRepository,
penaltyRepository as unknown as IPenaltyRepository,
championshipStandingRepository as unknown as IChampionshipStandingRepository,
eventScoringService as unknown as EventScoringService,
championshipAggregator as unknown as ChampionshipAggregator,
useCase = new RecalculateChampionshipStandingsUseCase(leagueRepository as any,
seasonRepository as any,
leagueScoringConfigRepository as any,
raceRepository as any,
resultRepository as any,
penaltyRepository as any,
championshipStandingRepository as any,
eventScoringService as any,
championshipAggregator as any,
logger);
});
@@ -79,7 +67,7 @@ describe('RecalculateChampionshipStandingsUseCase', () => {
>;
expect(error.code).toBe('LEAGUE_NOT_FOUND');
expect(error.details.message).toContain('league-1');
});
});
it('returns season not found error when season does not exist', async () => {
leagueRepository.findById.mockResolvedValue({ id: 'league-1' });
@@ -98,7 +86,7 @@ describe('RecalculateChampionshipStandingsUseCase', () => {
{ message: string }
>;
expect(error.code).toBe('SEASON_NOT_FOUND');
});
});
it('returns season not found error when season belongs to different league', async () => {
leagueRepository.findById.mockResolvedValue({ id: 'league-1' });
@@ -117,9 +105,9 @@ describe('RecalculateChampionshipStandingsUseCase', () => {
{ message: string }
>;
expect(error.code).toBe('SEASON_NOT_FOUND');
});
});
it('recalculates standings successfully and presents result', async () => {
it('recalculates standings successfully and returns result', async () => {
const league = { id: 'league-1' };
const season = { id: 'season-1', leagueId: 'league-1' };
const championship = {
@@ -161,9 +149,7 @@ describe('RecalculateChampionshipStandingsUseCase', () => {
const result = await useCase.execute(input);
expect(result.isOk()).toBe(true);
expect(result.unwrap()).toBeUndefined();
const presentedRaw = expect(presentedRaw).toBeDefined();
const presented = presentedRaw as RecalculateChampionshipStandingsResult;
const presented = result.unwrap();
expect(presented.leagueId).toBe('league-1');
expect(presented.seasonId).toBe('season-1');
expect(presented.entries).toHaveLength(1);
@@ -175,7 +161,7 @@ describe('RecalculateChampionshipStandingsUseCase', () => {
});
});
it('wraps repository failures in REPOSITORY_ERROR and does not call output', async () => {
it('wraps repository failures in REPOSITORY_ERROR', async () => {
leagueRepository.findById.mockResolvedValue({ id: 'league-1' });
seasonRepository.findById.mockResolvedValue({ id: 'season-1', leagueId: 'league-1' });
leagueScoringConfigRepository.findBySeasonId.mockImplementation(() => {
@@ -196,5 +182,5 @@ describe('RecalculateChampionshipStandingsUseCase', () => {
>;
expect(error.code).toBe('REPOSITORY_ERROR');
expect(error.details.message).toContain('boom');
});
});
});