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

@@ -4,8 +4,6 @@ import type { IRaceRepository } from '../../domain/repositories/IRaceRepository'
import type { Logger } from '@core/shared/application';
import { Race } from '../../domain/entities/Race';
import { SessionType } from '../../domain/value-objects/SessionType';
import type { UseCaseOutputPort } from '@core/shared/application/UseCaseOutputPort';
describe('CancelRaceUseCase', () => {
let useCase: CancelRaceUseCase;
let raceRepository: {
@@ -18,8 +16,6 @@ describe('CancelRaceUseCase', () => {
info: Mock;
error: Mock;
};
let output: UseCaseOutputPort<CancelRaceResult> & { present: Mock };
beforeEach(() => {
raceRepository = {
findById: vi.fn(),
@@ -31,12 +27,8 @@ describe('CancelRaceUseCase', () => {
info: vi.fn(),
error: vi.fn(),
};
output = { present: vi.fn() } as unknown as UseCaseOutputPort<CancelRaceResult> & { present: Mock };
useCase = new CancelRaceUseCase(
raceRepository as unknown as IRaceRepository,
logger as unknown as Logger,
output,
);
useCase = new CancelRaceUseCase(raceRepository as unknown as IRaceRepository,
logger as unknown as Logger);
});
it('should cancel race successfully', async () => {
@@ -63,9 +55,7 @@ describe('CancelRaceUseCase', () => {
expect(updatedRace.id).toBe(raceId);
expect(updatedRace.status.toString()).toBe('cancelled');
expect(output.present).toHaveBeenCalledTimes(1);
const presented = (output.present as Mock).mock.calls[0]?.[0] as CancelRaceResult;
expect(presented.race.id).toBe(raceId);
const presented = (expect(presented.race.id).toBe(raceId);
expect(presented.race.status.toString()).toBe('cancelled');
});
@@ -77,8 +67,7 @@ describe('CancelRaceUseCase', () => {
expect(result.isErr()).toBe(true);
expect(result.unwrapErr().code).toBe('RACE_NOT_FOUND');
expect(output.present).not.toHaveBeenCalled();
});
});
it('should return domain error if race is already cancelled', async () => {
const raceId = 'race-1';
@@ -102,8 +91,7 @@ describe('CancelRaceUseCase', () => {
if ('details' in err && err.details && typeof err.details === 'object' && 'message' in err.details) {
expect(err.details.message).toContain('already cancelled');
}
expect(output.present).not.toHaveBeenCalled();
});
});
it('should return domain error if race is completed', async () => {
const raceId = 'race-1';
@@ -127,6 +115,5 @@ describe('CancelRaceUseCase', () => {
if ('details' in err && err.details && typeof err.details === 'object' && 'message' in err.details) {
expect(err.details.message).toContain('completed race');
}
expect(output.present).not.toHaveBeenCalled();
});
});
});