refactor use cases
This commit is contained in:
@@ -6,14 +6,11 @@ import {
|
||||
type GetLeagueAdminErrorCode,
|
||||
} from './GetLeagueAdminUseCase';
|
||||
import type { ILeagueRepository } from '../../domain/repositories/ILeagueRepository';
|
||||
import type { UseCaseOutputPort } from '@core/shared/application/UseCaseOutputPort';
|
||||
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
|
||||
|
||||
describe('GetLeagueAdminUseCase', () => {
|
||||
let mockLeagueRepo: ILeagueRepository;
|
||||
let mockFindById: Mock;
|
||||
let output: UseCaseOutputPort<GetLeagueAdminResult> & { present: Mock };
|
||||
|
||||
beforeEach(() => {
|
||||
mockFindById = vi.fn();
|
||||
mockLeagueRepo = {
|
||||
@@ -27,15 +24,9 @@ describe('GetLeagueAdminUseCase', () => {
|
||||
searchByName: vi.fn(),
|
||||
} as ILeagueRepository;
|
||||
|
||||
output = {
|
||||
present: vi.fn(),
|
||||
} as unknown as UseCaseOutputPort<GetLeagueAdminResult> & { present: Mock };
|
||||
});
|
||||
});
|
||||
|
||||
const createUseCase = () => new GetLeagueAdminUseCase(
|
||||
mockLeagueRepo,
|
||||
output,
|
||||
);
|
||||
const createUseCase = () => new GetLeagueAdminUseCase(mockLeagueRepo);
|
||||
|
||||
const params: GetLeagueAdminInput = {
|
||||
leagueId: 'league1',
|
||||
@@ -51,8 +42,7 @@ describe('GetLeagueAdminUseCase', () => {
|
||||
const error = result.unwrapErr() as ApplicationErrorCode<GetLeagueAdminErrorCode, { message: string }>;
|
||||
expect(error.code).toBe('LEAGUE_NOT_FOUND');
|
||||
expect(error.details.message).toBe('League not found');
|
||||
expect(output.present).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return league data when league found', async () => {
|
||||
const league = { id: 'league1', ownerId: 'owner1' };
|
||||
@@ -63,9 +53,7 @@ describe('GetLeagueAdminUseCase', () => {
|
||||
|
||||
expect(result.isOk()).toBe(true);
|
||||
expect(result.unwrap()).toBeUndefined();
|
||||
expect(output.present).toHaveBeenCalledTimes(1);
|
||||
const presented = output.present.mock.calls[0]?.[0] as GetLeagueAdminResult;
|
||||
expect(presented.league.id).toBe('league1');
|
||||
const presented = expect(presented.league.id).toBe('league1');
|
||||
expect(presented.league.ownerId).toBe('owner1');
|
||||
});
|
||||
|
||||
@@ -80,6 +68,5 @@ describe('GetLeagueAdminUseCase', () => {
|
||||
const error = result.unwrapErr() as ApplicationErrorCode<GetLeagueAdminErrorCode, { message: string }>;
|
||||
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