refactor use cases
This commit is contained in:
@@ -15,7 +15,6 @@ import type { Penalty } from '../../domain/entities/Penalty';
|
||||
import { EventScoringService } from '../../domain/services/EventScoringService';
|
||||
import type { ILeagueRepository } from '../../domain/repositories/ILeagueRepository';
|
||||
import { ChampionshipAggregator } from '../../domain/services/ChampionshipAggregator';
|
||||
import type { UseCaseOutputPort, Logger } from '@core/shared/application';
|
||||
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
|
||||
|
||||
|
||||
@@ -31,8 +30,6 @@ describe('RecalculateChampionshipStandingsUseCase', () => {
|
||||
let eventScoringService: { scoreSession: Mock };
|
||||
let championshipAggregator: { aggregate: Mock };
|
||||
let logger: Logger;
|
||||
let output: UseCaseOutputPort<RecalculateChampionshipStandingsResult> & {
|
||||
present: ReturnType<typeof vi.fn>;
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
@@ -53,8 +50,7 @@ describe('RecalculateChampionshipStandingsUseCase', () => {
|
||||
};
|
||||
output = { present: vi.fn() } as unknown as typeof output;
|
||||
|
||||
useCase = new RecalculateChampionshipStandingsUseCase(
|
||||
leagueRepository as unknown as ILeagueRepository,
|
||||
useCase = new RecalculateChampionshipStandingsUseCase(leagueRepository as unknown as ILeagueRepository,
|
||||
seasonRepository as unknown as ISeasonRepository,
|
||||
leagueScoringConfigRepository as unknown as ILeagueScoringConfigRepository,
|
||||
raceRepository as unknown as IRaceRepository,
|
||||
@@ -63,9 +59,7 @@ describe('RecalculateChampionshipStandingsUseCase', () => {
|
||||
championshipStandingRepository as unknown as IChampionshipStandingRepository,
|
||||
eventScoringService as unknown as EventScoringService,
|
||||
championshipAggregator as unknown as ChampionshipAggregator,
|
||||
logger,
|
||||
output,
|
||||
);
|
||||
logger);
|
||||
});
|
||||
|
||||
it('returns league not found error', async () => {
|
||||
@@ -85,8 +79,7 @@ describe('RecalculateChampionshipStandingsUseCase', () => {
|
||||
>;
|
||||
expect(error.code).toBe('LEAGUE_NOT_FOUND');
|
||||
expect(error.details.message).toContain('league-1');
|
||||
expect(output.present).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
it('returns season not found error when season does not exist', async () => {
|
||||
leagueRepository.findById.mockResolvedValue({ id: 'league-1' });
|
||||
@@ -105,8 +98,7 @@ describe('RecalculateChampionshipStandingsUseCase', () => {
|
||||
{ message: string }
|
||||
>;
|
||||
expect(error.code).toBe('SEASON_NOT_FOUND');
|
||||
expect(output.present).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
it('returns season not found error when season belongs to different league', async () => {
|
||||
leagueRepository.findById.mockResolvedValue({ id: 'league-1' });
|
||||
@@ -125,8 +117,7 @@ describe('RecalculateChampionshipStandingsUseCase', () => {
|
||||
{ message: string }
|
||||
>;
|
||||
expect(error.code).toBe('SEASON_NOT_FOUND');
|
||||
expect(output.present).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
it('recalculates standings successfully and presents result', async () => {
|
||||
const league = { id: 'league-1' };
|
||||
@@ -171,10 +162,7 @@ describe('RecalculateChampionshipStandingsUseCase', () => {
|
||||
|
||||
expect(result.isOk()).toBe(true);
|
||||
expect(result.unwrap()).toBeUndefined();
|
||||
expect(output.present).toHaveBeenCalledTimes(1);
|
||||
|
||||
const presentedRaw = output.present.mock.calls[0]?.[0];
|
||||
expect(presentedRaw).toBeDefined();
|
||||
const presentedRaw = expect(presentedRaw).toBeDefined();
|
||||
const presented = presentedRaw as RecalculateChampionshipStandingsResult;
|
||||
expect(presented.leagueId).toBe('league-1');
|
||||
expect(presented.seasonId).toBe('season-1');
|
||||
@@ -208,6 +196,5 @@ describe('RecalculateChampionshipStandingsUseCase', () => {
|
||||
>;
|
||||
expect(error.code).toBe('REPOSITORY_ERROR');
|
||||
expect(error.details.message).toContain('boom');
|
||||
expect(output.present).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user