refactor use cases
This commit is contained in:
@@ -5,7 +5,6 @@ import {
|
||||
type GetLeagueSeasonsResult,
|
||||
type GetLeagueSeasonsErrorCode,
|
||||
} from './GetLeagueSeasonsUseCase';
|
||||
import type { UseCaseOutputPort } from '@core/shared/application';
|
||||
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
|
||||
import type { ISeasonRepository } from '../../domain/repositories/ISeasonRepository';
|
||||
import type { ILeagueRepository } from '../../domain/repositories/ILeagueRepository';
|
||||
@@ -20,8 +19,6 @@ describe('GetLeagueSeasonsUseCase', () => {
|
||||
let leagueRepository: {
|
||||
findById: Mock;
|
||||
};
|
||||
let output: UseCaseOutputPort<GetLeagueSeasonsResult> & {
|
||||
present: Mock;
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
@@ -33,17 +30,10 @@ describe('GetLeagueSeasonsUseCase', () => {
|
||||
findById: vi.fn(),
|
||||
};
|
||||
|
||||
output = {
|
||||
present: vi.fn(),
|
||||
} as unknown as UseCaseOutputPort<GetLeagueSeasonsResult> & {
|
||||
present: Mock;
|
||||
};
|
||||
|
||||
useCase = new GetLeagueSeasonsUseCase(
|
||||
seasonRepository as unknown as ISeasonRepository,
|
||||
leagueRepository as unknown as ILeagueRepository,
|
||||
output,
|
||||
);
|
||||
useCase = new GetLeagueSeasonsUseCase(seasonRepository as unknown as ISeasonRepository,
|
||||
leagueRepository as unknown as ILeagueRepository);
|
||||
});
|
||||
|
||||
it('should present seasons with correct isParallelActive flags on success', async () => {
|
||||
@@ -82,10 +72,7 @@ describe('GetLeagueSeasonsUseCase', () => {
|
||||
expect(result.isOk()).toBe(true);
|
||||
expect(result.unwrap()).toBeUndefined();
|
||||
|
||||
expect(output.present).toHaveBeenCalledTimes(1);
|
||||
const presented = output.present.mock.calls[0]?.[0] as GetLeagueSeasonsResult;
|
||||
|
||||
expect(presented?.league).toBe(league);
|
||||
const presented = expect(presented?.league).toBe(league);
|
||||
expect(presented?.seasons).toHaveLength(2);
|
||||
|
||||
expect(presented?.seasons[0]?.season).toBe(seasons[0]);
|
||||
@@ -131,10 +118,7 @@ describe('GetLeagueSeasonsUseCase', () => {
|
||||
expect(result.isOk()).toBe(true);
|
||||
expect(result.unwrap()).toBeUndefined();
|
||||
|
||||
expect(output.present).toHaveBeenCalledTimes(1);
|
||||
const presented = output.present.mock.calls[0]?.[0] as GetLeagueSeasonsResult;
|
||||
|
||||
expect(presented?.seasons).toHaveLength(2);
|
||||
const presented = expect(presented?.seasons).toHaveLength(2);
|
||||
expect(presented?.seasons[0]?.isParallelActive).toBe(true);
|
||||
expect(presented?.seasons[1]?.isParallelActive).toBe(true);
|
||||
});
|
||||
@@ -154,8 +138,7 @@ describe('GetLeagueSeasonsUseCase', () => {
|
||||
|
||||
expect(err.code).toBe('LEAGUE_NOT_FOUND');
|
||||
expect(err.details.message).toBe('League not found');
|
||||
expect(output.present).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return REPOSITORY_ERROR when repository throws', async () => {
|
||||
const leagueId = 'league-1';
|
||||
@@ -173,6 +156,5 @@ describe('GetLeagueSeasonsUseCase', () => {
|
||||
|
||||
expect(err.code).toBe('REPOSITORY_ERROR');
|
||||
expect(err.details.message).toBe(errorMessage);
|
||||
expect(output.present).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user