website refactor
This commit is contained in:
@@ -5,9 +5,6 @@ import {
|
||||
type GetRaceWithSOFResult,
|
||||
type GetRaceWithSOFErrorCode,
|
||||
} from './GetRaceWithSOFUseCase';
|
||||
import { RaceRepository } from '../../domain/repositories/RaceRepository';
|
||||
import { RaceRegistrationRepository } from '../../domain/repositories/RaceRegistrationRepository';
|
||||
import { ResultRepository } from '../../domain/repositories/ResultRepository';
|
||||
import { Race } from '../../domain/entities/Race';
|
||||
import { SessionType } from '../../domain/value-objects/SessionType';
|
||||
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
|
||||
@@ -24,6 +21,7 @@ describe('GetRaceWithSOFUseCase', () => {
|
||||
findByRaceId: Mock;
|
||||
};
|
||||
let getDriverRating: Mock;
|
||||
|
||||
beforeEach(() => {
|
||||
raceRepository = {
|
||||
findById: vi.fn(),
|
||||
@@ -35,13 +33,12 @@ describe('GetRaceWithSOFUseCase', () => {
|
||||
findByRaceId: vi.fn(),
|
||||
};
|
||||
getDriverRating = vi.fn();
|
||||
output = {
|
||||
present: vi.fn(),
|
||||
};
|
||||
useCase = new GetRaceWithSOFUseCase(raceRepository as unknown as IRaceRepository,
|
||||
registrationRepository as unknown as IRaceRegistrationRepository,
|
||||
resultRepository as unknown as IResultRepository,
|
||||
getDriverRating);
|
||||
useCase = new GetRaceWithSOFUseCase(
|
||||
raceRepository as any,
|
||||
registrationRepository as any,
|
||||
resultRepository as any,
|
||||
getDriverRating
|
||||
);
|
||||
});
|
||||
|
||||
it('should return error when race not found', async () => {
|
||||
@@ -56,7 +53,7 @@ describe('GetRaceWithSOFUseCase', () => {
|
||||
>;
|
||||
expect(err.code).toBe('RACE_NOT_FOUND');
|
||||
expect(err.details?.message).toBe('Race with id race-1 not found');
|
||||
});
|
||||
});
|
||||
|
||||
it('should return race with stored SOF when available', async () => {
|
||||
const race = Race.create({
|
||||
@@ -74,23 +71,15 @@ describe('GetRaceWithSOFUseCase', () => {
|
||||
|
||||
raceRepository.findById.mockResolvedValue(race);
|
||||
registrationRepository.getRegisteredDrivers.mockResolvedValue([
|
||||
'driver-1',
|
||||
'driver-2',
|
||||
'driver-3',
|
||||
'driver-4',
|
||||
'driver-5',
|
||||
'driver-6',
|
||||
'driver-7',
|
||||
'driver-8',
|
||||
'driver-9',
|
||||
'driver-10',
|
||||
'driver-1', 'driver-2', 'driver-3', 'driver-4', 'driver-5',
|
||||
'driver-6', 'driver-7', 'driver-8', 'driver-9', 'driver-10',
|
||||
]);
|
||||
|
||||
const result = await useCase.execute({ raceId: 'race-1' } as GetRaceWithSOFInput);
|
||||
|
||||
expect(result.isOk()).toBe(true);
|
||||
expect(result.unwrap()).toBeUndefined();
|
||||
const [[presented]] = expect(presented.race.id).toBe('race-1');
|
||||
const presented = result.unwrap();
|
||||
expect(presented.race.id).toBe('race-1');
|
||||
expect(presented.race.leagueId).toBe('league-1');
|
||||
expect(presented.strengthOfField).toBe(1500);
|
||||
expect(presented.registeredCount).toBe(10);
|
||||
@@ -124,8 +113,8 @@ describe('GetRaceWithSOFUseCase', () => {
|
||||
const result = await useCase.execute({ raceId: 'race-1' } as GetRaceWithSOFInput);
|
||||
|
||||
expect(result.isOk()).toBe(true);
|
||||
expect(result.unwrap()).toBeUndefined();
|
||||
const [[presented]] = expect(presented.strengthOfField).toBe(1500); // average
|
||||
const presented = result.unwrap();
|
||||
expect(presented.strengthOfField).toBe(1500); // average
|
||||
expect(presented.participantCount).toBe(2);
|
||||
expect(registrationRepository.getRegisteredDrivers).toHaveBeenCalledWith('race-1');
|
||||
expect(resultRepository.findByRaceId).not.toHaveBeenCalled();
|
||||
@@ -160,8 +149,8 @@ describe('GetRaceWithSOFUseCase', () => {
|
||||
const result = await useCase.execute({ raceId: 'race-1' } as GetRaceWithSOFInput);
|
||||
|
||||
expect(result.isOk()).toBe(true);
|
||||
expect(result.unwrap()).toBeUndefined();
|
||||
const [[presented]] = expect(presented.strengthOfField).toBe(1500);
|
||||
const presented = result.unwrap();
|
||||
expect(presented.strengthOfField).toBe(1500);
|
||||
expect(presented.participantCount).toBe(2);
|
||||
expect(resultRepository.findByRaceId).toHaveBeenCalledWith('race-1');
|
||||
expect(registrationRepository.getRegisteredDrivers).not.toHaveBeenCalled();
|
||||
@@ -191,8 +180,8 @@ describe('GetRaceWithSOFUseCase', () => {
|
||||
const result = await useCase.execute({ raceId: 'race-1' } as GetRaceWithSOFInput);
|
||||
|
||||
expect(result.isOk()).toBe(true);
|
||||
expect(result.unwrap()).toBeUndefined();
|
||||
const [[presented]] = expect(presented.strengthOfField).toBe(1400); // only one rating
|
||||
const presented = result.unwrap();
|
||||
expect(presented.strengthOfField).toBe(1400); // only one rating
|
||||
expect(presented.participantCount).toBe(2);
|
||||
});
|
||||
|
||||
@@ -213,12 +202,12 @@ describe('GetRaceWithSOFUseCase', () => {
|
||||
const result = await useCase.execute({ raceId: 'race-1' } as GetRaceWithSOFInput);
|
||||
|
||||
expect(result.isOk()).toBe(true);
|
||||
expect(result.unwrap()).toBeUndefined();
|
||||
const [[presented]] = expect(presented.strengthOfField).toBe(null);
|
||||
const presented = result.unwrap();
|
||||
expect(presented.strengthOfField).toBe(null);
|
||||
expect(presented.participantCount).toBe(0);
|
||||
});
|
||||
|
||||
it('should wrap repository errors in REPOSITORY_ERROR and not call output', async () => {
|
||||
it('should wrap repository errors in REPOSITORY_ERROR', async () => {
|
||||
raceRepository.findById.mockRejectedValue(new Error('boom'));
|
||||
|
||||
const result = await useCase.execute({ raceId: 'race-1' } as GetRaceWithSOFInput);
|
||||
@@ -230,5 +219,5 @@ describe('GetRaceWithSOFUseCase', () => {
|
||||
>;
|
||||
expect(err.code).toBe('REPOSITORY_ERROR');
|
||||
expect(err.details?.message).toBe('boom');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user