refactor use cases
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
import type { UseCaseOutputPort } from '@core/shared/application/UseCaseOutputPort';
|
||||
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
import type { IDriverRepository } from '../../domain/repositories/IDriverRepository';
|
||||
@@ -30,8 +29,6 @@ describe('GetLeagueDriverSeasonStatsUseCase', () => {
|
||||
let raceRepository: IRaceRepository;
|
||||
let driverRepository: IDriverRepository;
|
||||
let driverRatingPort: DriverRatingPort;
|
||||
let output: UseCaseOutputPort<GetLeagueDriverSeasonStatsResult> & { present: ReturnType<typeof vi.fn> };
|
||||
|
||||
beforeEach(() => {
|
||||
mockStandingFindByLeagueId.mockReset();
|
||||
mockResultFindByDriverIdAndLeagueId.mockReset();
|
||||
@@ -106,21 +103,14 @@ describe('GetLeagueDriverSeasonStatsUseCase', () => {
|
||||
updateDriverRating: vi.fn(),
|
||||
};
|
||||
|
||||
output = {
|
||||
present: vi.fn(),
|
||||
} as unknown as UseCaseOutputPort<GetLeagueDriverSeasonStatsResult> & {
|
||||
present: ReturnType<typeof vi.fn>;
|
||||
};
|
||||
|
||||
useCase = new GetLeagueDriverSeasonStatsUseCase(
|
||||
standingRepository,
|
||||
useCase = new GetLeagueDriverSeasonStatsUseCase(standingRepository,
|
||||
resultRepository,
|
||||
penaltyRepository,
|
||||
raceRepository,
|
||||
driverRepository,
|
||||
driverRatingPort,
|
||||
output,
|
||||
);
|
||||
driverRatingPort);
|
||||
});
|
||||
|
||||
it('should return league driver season stats for given league id', async () => {
|
||||
@@ -193,10 +183,7 @@ describe('GetLeagueDriverSeasonStatsUseCase', () => {
|
||||
|
||||
expect(result.isOk()).toBe(true);
|
||||
expect(result.unwrap()).toBeUndefined();
|
||||
expect(output.present).toHaveBeenCalledTimes(1);
|
||||
|
||||
const presented = output.present.mock.calls[0]?.[0] as GetLeagueDriverSeasonStatsResult;
|
||||
expect(presented.leagueId).toBe('league-1');
|
||||
const presented = expect(presented.leagueId).toBe('league-1');
|
||||
expect(presented.stats).toHaveLength(2);
|
||||
|
||||
expect(presented.stats[0]).toEqual({
|
||||
@@ -245,10 +232,7 @@ describe('GetLeagueDriverSeasonStatsUseCase', () => {
|
||||
|
||||
expect(result.isOk()).toBe(true);
|
||||
expect(result.unwrap()).toBeUndefined();
|
||||
expect(output.present).toHaveBeenCalledTimes(1);
|
||||
|
||||
const presented = output.present.mock.calls[0]?.[0] as GetLeagueDriverSeasonStatsResult;
|
||||
expect(presented?.stats[0]?.penaltyPoints).toBe(0);
|
||||
const presented = expect(presented?.stats[0]?.penaltyPoints).toBe(0);
|
||||
});
|
||||
|
||||
it('should return LEAGUE_NOT_FOUND when no standings are found', async () => {
|
||||
@@ -266,8 +250,7 @@ describe('GetLeagueDriverSeasonStatsUseCase', () => {
|
||||
>;
|
||||
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 an unexpected error occurs', async () => {
|
||||
const input: GetLeagueDriverSeasonStatsInput = { leagueId: 'league-1' };
|
||||
@@ -285,6 +268,5 @@ describe('GetLeagueDriverSeasonStatsUseCase', () => {
|
||||
|
||||
expect(err.code).toBe('REPOSITORY_ERROR');
|
||||
expect(err.details.message).toBe('repository failure');
|
||||
expect(output.present).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user