refactor use cases

This commit is contained in:
2026-01-08 15:34:51 +01:00
parent d984ab24a8
commit 52e9a2f6a7
362 changed files with 5192 additions and 8409 deletions

View File

@@ -8,7 +8,6 @@ import {
import type { ISeasonRepository } from '../../domain/repositories/ISeasonRepository';
import type { ILeagueRepository } from '../../domain/repositories/ILeagueRepository';
import { Season } from '../../domain/entities/season/Season';
import type { UseCaseOutputPort } from '@core/shared/application';
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
describe('GetSeasonDetailsUseCase', () => {
@@ -19,8 +18,6 @@ describe('GetSeasonDetailsUseCase', () => {
let seasonRepository: {
findById: Mock;
};
let output: UseCaseOutputPort<GetSeasonDetailsResult> & {
present: Mock;
};
beforeEach(() => {
@@ -34,11 +31,8 @@ describe('GetSeasonDetailsUseCase', () => {
present: vi.fn(),
};
useCase = new GetSeasonDetailsUseCase(
leagueRepository as unknown as ILeagueRepository,
seasonRepository as unknown as ISeasonRepository,
output,
);
useCase = new GetSeasonDetailsUseCase(leagueRepository as unknown as ILeagueRepository,
seasonRepository as unknown as ISeasonRepository);
});
it('returns full details for a season belonging to the league', async () => {
@@ -64,12 +58,8 @@ describe('GetSeasonDetailsUseCase', () => {
expect(result.isOk()).toBe(true);
expect(result.unwrap()).toBeUndefined();
expect(output.present).toHaveBeenCalledTimes(1);
const presented =
(output.present.mock.calls[0]?.[0] as GetSeasonDetailsResult | undefined) ??
undefined;
expect(presented).toBeDefined();
(expect(presented).toBeDefined();
expect(presented?.leagueId).toBe('league-1');
expect(presented?.season.id).toBe('season-1');
expect(presented?.season.leagueId).toBe('league-1');
@@ -98,8 +88,7 @@ describe('GetSeasonDetailsUseCase', () => {
expect(error.code).toBe('LEAGUE_NOT_FOUND');
expect(error.details.message).toBe('League not found: league-1');
expect(output.present).not.toHaveBeenCalled();
});
});
it('returns error when season not found', async () => {
const league = { id: 'league-1' };
@@ -124,8 +113,7 @@ describe('GetSeasonDetailsUseCase', () => {
expect(error.details.message).toBe(
'Season season-1 does not belong to league league-1',
);
expect(output.present).not.toHaveBeenCalled();
});
});
it('returns error when season belongs to different league', async () => {
const league = { id: 'league-1' };
@@ -158,8 +146,7 @@ describe('GetSeasonDetailsUseCase', () => {
expect(error.details.message).toBe(
'Season season-1 does not belong to league league-1',
);
expect(output.present).not.toHaveBeenCalled();
});
});
it('returns repository error when an unexpected exception occurs', async () => {
leagueRepository.findById.mockRejectedValue(
@@ -182,6 +169,5 @@ describe('GetSeasonDetailsUseCase', () => {
expect(error.code).toBe('REPOSITORY_ERROR');
expect(error.details.message).toBe('Unexpected repository failure');
expect(output.present).not.toHaveBeenCalled();
});
});
});