refactor use cases

This commit is contained in:
2026-01-08 15:34:51 +01:00
parent d984ab24a8
commit 52e9a2f6a7
362 changed files with 5192 additions and 8409 deletions

View File

@@ -7,24 +7,17 @@ import {
} from './GetRacePenaltiesUseCase';
import type { IPenaltyRepository } from '../../domain/repositories/IPenaltyRepository';
import type { IDriverRepository } from '../../domain/repositories/IDriverRepository';
import type { UseCaseOutputPort } from '@core/shared/application';
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
describe('GetRacePenaltiesUseCase', () => {
let useCase: GetRacePenaltiesUseCase;
let penaltyRepository: { findByRaceId: Mock };
let driverRepository: { findById: Mock };
let output: UseCaseOutputPort<GetRacePenaltiesResult> & { present: Mock };
beforeEach(() => {
penaltyRepository = { findByRaceId: vi.fn() };
driverRepository = { findById: vi.fn() };
output = { present: vi.fn() } as UseCaseOutputPort<GetRacePenaltiesResult> & { present: Mock };
useCase = new GetRacePenaltiesUseCase(
penaltyRepository as unknown as IPenaltyRepository,
driverRepository as unknown as IDriverRepository,
output,
);
useCase = new GetRacePenaltiesUseCase(penaltyRepository as unknown as IPenaltyRepository,
driverRepository as unknown as IDriverRepository);
});
it('should return penalties with drivers', async () => {
@@ -53,11 +46,9 @@ describe('GetRacePenaltiesUseCase', () => {
const result = await useCase.execute(input);
expect(result.isOk()).toBe(true);
expect(result.unwrap()).toBeUndefined();
expect(output.present).toHaveBeenCalledTimes(1);
const presented = output.present.mock.calls[0]![0] as GetRacePenaltiesResult;
expect(presented.penalties).toEqual(penalties);
expect(presented.drivers).toEqual(drivers);
const resultValue = result.unwrap();
expect(resultValue.penalties).toEqual(penalties);
expect(resultValue.drivers).toEqual(drivers);
});
it('should return empty when no penalties', async () => {
@@ -68,11 +59,9 @@ describe('GetRacePenaltiesUseCase', () => {
const result = await useCase.execute(input);
expect(result.isOk()).toBe(true);
expect(result.unwrap()).toBeUndefined();
expect(output.present).toHaveBeenCalledTimes(1);
const presented = output.present.mock.calls[0]![0] as GetRacePenaltiesResult;
expect(presented.penalties).toEqual([]);
expect(presented.drivers).toEqual([]);
const resultValue = result.unwrap();
expect(resultValue.penalties).toEqual([]);
expect(resultValue.drivers).toEqual([]);
});
it('should return repository error when repository throws', async () => {
@@ -89,6 +78,5 @@ describe('GetRacePenaltiesUseCase', () => {
>;
expect(err.code).toBe('REPOSITORY_ERROR');
expect(err.details.message).toBe('Repository failure');
expect(output.present).not.toHaveBeenCalled();
});
});
});