This commit is contained in:
2025-12-16 21:05:01 +01:00
parent f61e3a4e5a
commit 7532c7ed6d
207 changed files with 7861 additions and 2606 deletions

View File

@@ -4,7 +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 { RacingDomainInvariantError, RacingDomainValidationError } from '../../domain/errors/RacingDomainError';
describe('CancelRaceUseCase', () => {
let useCase: CancelRaceUseCase;
@@ -52,7 +51,6 @@ describe('CancelRaceUseCase', () => {
expect(result.isOk()).toBe(true);
expect(raceRepository.findById).toHaveBeenCalledWith(raceId);
expect(raceRepository.update).toHaveBeenCalledWith(expect.objectContaining({ id: raceId, status: 'cancelled' }));
expect(logger.info).toHaveBeenCalledWith(`[CancelRaceUseCase] Race ${raceId} cancelled successfully.`);
});
it('should return error if race not found', async () => {
@@ -62,9 +60,7 @@ describe('CancelRaceUseCase', () => {
const result = await useCase.execute({ raceId });
expect(result.isErr()).toBe(true);
expect(result.unwrapErr()).toBeInstanceOf(RacingDomainValidationError);
expect(result.unwrapErr().message).toBe('Race not found');
expect(logger.warn).toHaveBeenCalledWith(`[CancelRaceUseCase] Race with ID ${raceId} not found.`);
expect(result.unwrapErr().code).toBe('RACE_NOT_FOUND');
});
it('should return domain error if race is already cancelled', async () => {
@@ -84,9 +80,7 @@ describe('CancelRaceUseCase', () => {
const result = await useCase.execute({ raceId });
expect(result.isErr()).toBe(true);
expect(result.unwrapErr()).toBeInstanceOf(RacingDomainInvariantError);
expect(result.unwrapErr().message).toBe('Race is already cancelled');
expect(logger.warn).toHaveBeenCalledWith(`[CancelRaceUseCase] Domain error cancelling race ${raceId}: Race is already cancelled`);
expect(result.unwrapErr().code).toBe('RACE_ALREADY_CANCELLED');
});
it('should return domain error if race is completed', async () => {
@@ -106,8 +100,6 @@ describe('CancelRaceUseCase', () => {
const result = await useCase.execute({ raceId });
expect(result.isErr()).toBe(true);
expect(result.unwrapErr()).toBeInstanceOf(RacingDomainInvariantError);
expect(result.unwrapErr().message).toBe('Cannot cancel a completed race');
expect(logger.warn).toHaveBeenCalledWith(`[CancelRaceUseCase] Domain error cancelling race ${raceId}: Cannot cancel a completed race`);
expect(result.unwrapErr().code).toBe('CANNOT_CANCEL_COMPLETED_RACE');
});
});