refactor use cases
This commit is contained in:
@@ -10,8 +10,6 @@ import { ILeagueRepository } from '../../domain/repositories/ILeagueRepository';
|
||||
import { Driver } from '../../domain/entities/Driver';
|
||||
import { League } from '../../domain/entities/League';
|
||||
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
|
||||
import type { UseCaseOutputPort } from '@core/shared/application';
|
||||
|
||||
describe('GetLeagueOwnerSummaryUseCase', () => {
|
||||
let useCase: GetLeagueOwnerSummaryUseCase;
|
||||
let leagueRepository: {
|
||||
@@ -20,8 +18,6 @@ describe('GetLeagueOwnerSummaryUseCase', () => {
|
||||
let driverRepository: {
|
||||
findById: Mock;
|
||||
};
|
||||
let output: UseCaseOutputPort<GetLeagueOwnerSummaryResult> & { present: Mock };
|
||||
|
||||
beforeEach(() => {
|
||||
leagueRepository = {
|
||||
findById: vi.fn(),
|
||||
@@ -29,15 +25,8 @@ describe('GetLeagueOwnerSummaryUseCase', () => {
|
||||
driverRepository = {
|
||||
findById: vi.fn(),
|
||||
};
|
||||
output = {
|
||||
present: vi.fn(),
|
||||
} as unknown as UseCaseOutputPort<GetLeagueOwnerSummaryResult> & { present: Mock };
|
||||
|
||||
useCase = new GetLeagueOwnerSummaryUseCase(
|
||||
leagueRepository as unknown as ILeagueRepository,
|
||||
driverRepository as unknown as IDriverRepository,
|
||||
output,
|
||||
);
|
||||
useCase = new GetLeagueOwnerSummaryUseCase(leagueRepository as unknown as ILeagueRepository,
|
||||
driverRepository as unknown as IDriverRepository);
|
||||
});
|
||||
|
||||
it('should return owner summary when league and owner exist', async () => {
|
||||
@@ -64,11 +53,7 @@ describe('GetLeagueOwnerSummaryUseCase', () => {
|
||||
|
||||
expect(result.isOk()).toBe(true);
|
||||
expect(result.unwrap()).toBeUndefined();
|
||||
expect(output.present).toHaveBeenCalledTimes(1);
|
||||
|
||||
const presented = output.present.mock.calls[0]?.[0] as GetLeagueOwnerSummaryResult;
|
||||
|
||||
expect(presented?.league).toBe(league);
|
||||
const presented = expect(presented?.league).toBe(league);
|
||||
expect(presented?.owner).toBe(driver);
|
||||
expect(presented?.rating).toBe(0);
|
||||
expect(presented?.rank).toBe(0);
|
||||
@@ -88,8 +73,7 @@ describe('GetLeagueOwnerSummaryUseCase', () => {
|
||||
>;
|
||||
expect(errorResult.code).toBe('LEAGUE_NOT_FOUND');
|
||||
expect(errorResult.details.message).toBe('League not found');
|
||||
expect(output.present).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return error when owner does not exist', async () => {
|
||||
const leagueId = 'league-1';
|
||||
@@ -114,8 +98,7 @@ describe('GetLeagueOwnerSummaryUseCase', () => {
|
||||
>;
|
||||
expect(errorResult.code).toBe('OWNER_NOT_FOUND');
|
||||
expect(errorResult.details.message).toBe('League owner not found');
|
||||
expect(output.present).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return repository error when repository throws', async () => {
|
||||
const leagueId = 'league-1';
|
||||
@@ -132,6 +115,5 @@ describe('GetLeagueOwnerSummaryUseCase', () => {
|
||||
|
||||
expect(errorResult.code).toBe('REPOSITORY_ERROR');
|
||||
expect(errorResult.details.message).toBe('DB failure');
|
||||
expect(output.present).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user