refactor use cases
This commit is contained in:
@@ -9,7 +9,6 @@ import type { ILeagueRepository } from '../../domain/repositories/ILeagueReposit
|
||||
import type { ISeasonRepository } from '../../domain/repositories/ISeasonRepository';
|
||||
import type { ILeagueScoringConfigRepository } from '../../domain/repositories/ILeagueScoringConfigRepository';
|
||||
import type { IGameRepository } from '../../domain/repositories/IGameRepository';
|
||||
import type { UseCaseOutputPort } from '@core/shared/application/UseCaseOutputPort';
|
||||
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
|
||||
|
||||
describe('GetLeagueFullConfigUseCase', () => {
|
||||
@@ -20,8 +19,6 @@ describe('GetLeagueFullConfigUseCase', () => {
|
||||
findBySeasonId: ReturnType<typeof vi.fn>;
|
||||
};
|
||||
let gameRepository: IGameRepository & { findById: ReturnType<typeof vi.fn> };
|
||||
let output: UseCaseOutputPort<GetLeagueFullConfigResult> & { present: ReturnType<typeof vi.fn> };
|
||||
|
||||
beforeEach(() => {
|
||||
leagueRepository = {
|
||||
findById: vi.fn(),
|
||||
@@ -40,17 +37,12 @@ describe('GetLeagueFullConfigUseCase', () => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
} as any;
|
||||
|
||||
output = { present: vi.fn() } as unknown as UseCaseOutputPort<GetLeagueFullConfigResult> & {
|
||||
present: ReturnType<typeof vi.fn>;
|
||||
};
|
||||
|
||||
useCase = new GetLeagueFullConfigUseCase(
|
||||
leagueRepository,
|
||||
useCase = new GetLeagueFullConfigUseCase(leagueRepository,
|
||||
seasonRepository,
|
||||
leagueScoringConfigRepository,
|
||||
gameRepository,
|
||||
output,
|
||||
);
|
||||
gameRepository);
|
||||
});
|
||||
|
||||
it('should return league config when league exists', async () => {
|
||||
@@ -88,9 +80,7 @@ describe('GetLeagueFullConfigUseCase', () => {
|
||||
expect(result.isOk()).toBe(true);
|
||||
expect(result.unwrap()).toBeUndefined();
|
||||
|
||||
expect(output.present).toHaveBeenCalledTimes(1);
|
||||
const firstCall = output.present.mock.calls[0]!;
|
||||
const presented = firstCall[0] as GetLeagueFullConfigResult;
|
||||
const firstCall = const presented = firstCall[0] as GetLeagueFullConfigResult;
|
||||
|
||||
expect(presented.config.league).toEqual(mockLeague);
|
||||
expect(presented.config.activeSeason).toEqual(mockSeasons[0]);
|
||||
@@ -113,8 +103,7 @@ describe('GetLeagueFullConfigUseCase', () => {
|
||||
|
||||
expect(error.code).toBe('LEAGUE_NOT_FOUND');
|
||||
expect(error.details.message).toBe('League not found');
|
||||
expect(output.present).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
it('should handle no active season', async () => {
|
||||
const input: GetLeagueFullConfigInput = { leagueId: 'league-1' };
|
||||
@@ -133,10 +122,7 @@ describe('GetLeagueFullConfigUseCase', () => {
|
||||
|
||||
expect(result.isOk()).toBe(true);
|
||||
expect(result.unwrap()).toBeUndefined();
|
||||
expect(output.present).toHaveBeenCalledTimes(1);
|
||||
|
||||
const firstCall = output.present.mock.calls[0]!;
|
||||
const presented = firstCall[0] as GetLeagueFullConfigResult;
|
||||
const firstCall = const presented = firstCall[0] as GetLeagueFullConfigResult;
|
||||
|
||||
expect(presented.config.league).toEqual(mockLeague);
|
||||
expect(presented.config.activeSeason).toBeUndefined();
|
||||
@@ -160,6 +146,5 @@ describe('GetLeagueFullConfigUseCase', () => {
|
||||
|
||||
expect(error.code).toBe('REPOSITORY_ERROR');
|
||||
expect(error.details.message).toBe('Repository failure');
|
||||
expect(output.present).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user