refactor use cases
This commit is contained in:
@@ -10,7 +10,6 @@ import { IRaceRegistrationRepository } from '../../domain/repositories/IRaceRegi
|
||||
import { IResultRepository } from '../../domain/repositories/IResultRepository';
|
||||
import { Race } from '../../domain/entities/Race';
|
||||
import { SessionType } from '../../domain/value-objects/SessionType';
|
||||
import type { UseCaseOutputPort } from '@core/shared/application/UseCaseOutputPort';
|
||||
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
|
||||
|
||||
describe('GetRaceWithSOFUseCase', () => {
|
||||
@@ -25,8 +24,6 @@ describe('GetRaceWithSOFUseCase', () => {
|
||||
findByRaceId: Mock;
|
||||
};
|
||||
let getDriverRating: Mock;
|
||||
let output: UseCaseOutputPort<GetRaceWithSOFResult> & { present: Mock };
|
||||
|
||||
beforeEach(() => {
|
||||
raceRepository = {
|
||||
findById: vi.fn(),
|
||||
@@ -41,13 +38,10 @@ describe('GetRaceWithSOFUseCase', () => {
|
||||
output = {
|
||||
present: vi.fn(),
|
||||
};
|
||||
useCase = new GetRaceWithSOFUseCase(
|
||||
raceRepository as unknown as IRaceRepository,
|
||||
useCase = new GetRaceWithSOFUseCase(raceRepository as unknown as IRaceRepository,
|
||||
registrationRepository as unknown as IRaceRegistrationRepository,
|
||||
resultRepository as unknown as IResultRepository,
|
||||
getDriverRating,
|
||||
output,
|
||||
);
|
||||
getDriverRating);
|
||||
});
|
||||
|
||||
it('should return error when race not found', async () => {
|
||||
@@ -62,8 +56,7 @@ describe('GetRaceWithSOFUseCase', () => {
|
||||
>;
|
||||
expect(err.code).toBe('RACE_NOT_FOUND');
|
||||
expect(err.details?.message).toBe('Race with id race-1 not found');
|
||||
expect(output.present).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return race with stored SOF when available', async () => {
|
||||
const race = Race.create({
|
||||
@@ -97,9 +90,7 @@ describe('GetRaceWithSOFUseCase', () => {
|
||||
|
||||
expect(result.isOk()).toBe(true);
|
||||
expect(result.unwrap()).toBeUndefined();
|
||||
expect(output.present).toHaveBeenCalledTimes(1);
|
||||
const [[presented]] = output.present.mock.calls as [[GetRaceWithSOFResult]];
|
||||
expect(presented.race.id).toBe('race-1');
|
||||
const [[presented]] = expect(presented.race.id).toBe('race-1');
|
||||
expect(presented.race.leagueId).toBe('league-1');
|
||||
expect(presented.strengthOfField).toBe(1500);
|
||||
expect(presented.registeredCount).toBe(10);
|
||||
@@ -134,9 +125,7 @@ describe('GetRaceWithSOFUseCase', () => {
|
||||
|
||||
expect(result.isOk()).toBe(true);
|
||||
expect(result.unwrap()).toBeUndefined();
|
||||
expect(output.present).toHaveBeenCalledTimes(1);
|
||||
const [[presented]] = output.present.mock.calls as [[GetRaceWithSOFResult]];
|
||||
expect(presented.strengthOfField).toBe(1500); // average
|
||||
const [[presented]] = expect(presented.strengthOfField).toBe(1500); // average
|
||||
expect(presented.participantCount).toBe(2);
|
||||
expect(registrationRepository.getRegisteredDrivers).toHaveBeenCalledWith('race-1');
|
||||
expect(resultRepository.findByRaceId).not.toHaveBeenCalled();
|
||||
@@ -172,9 +161,7 @@ describe('GetRaceWithSOFUseCase', () => {
|
||||
|
||||
expect(result.isOk()).toBe(true);
|
||||
expect(result.unwrap()).toBeUndefined();
|
||||
expect(output.present).toHaveBeenCalledTimes(1);
|
||||
const [[presented]] = output.present.mock.calls as [[GetRaceWithSOFResult]];
|
||||
expect(presented.strengthOfField).toBe(1500);
|
||||
const [[presented]] = expect(presented.strengthOfField).toBe(1500);
|
||||
expect(presented.participantCount).toBe(2);
|
||||
expect(resultRepository.findByRaceId).toHaveBeenCalledWith('race-1');
|
||||
expect(registrationRepository.getRegisteredDrivers).not.toHaveBeenCalled();
|
||||
@@ -205,9 +192,7 @@ describe('GetRaceWithSOFUseCase', () => {
|
||||
|
||||
expect(result.isOk()).toBe(true);
|
||||
expect(result.unwrap()).toBeUndefined();
|
||||
expect(output.present).toHaveBeenCalledTimes(1);
|
||||
const [[presented]] = output.present.mock.calls as [[GetRaceWithSOFResult]];
|
||||
expect(presented.strengthOfField).toBe(1400); // only one rating
|
||||
const [[presented]] = expect(presented.strengthOfField).toBe(1400); // only one rating
|
||||
expect(presented.participantCount).toBe(2);
|
||||
});
|
||||
|
||||
@@ -229,9 +214,7 @@ describe('GetRaceWithSOFUseCase', () => {
|
||||
|
||||
expect(result.isOk()).toBe(true);
|
||||
expect(result.unwrap()).toBeUndefined();
|
||||
expect(output.present).toHaveBeenCalledTimes(1);
|
||||
const [[presented]] = output.present.mock.calls as [[GetRaceWithSOFResult]];
|
||||
expect(presented.strengthOfField).toBe(null);
|
||||
const [[presented]] = expect(presented.strengthOfField).toBe(null);
|
||||
expect(presented.participantCount).toBe(0);
|
||||
});
|
||||
|
||||
@@ -247,6 +230,5 @@ describe('GetRaceWithSOFUseCase', () => {
|
||||
>;
|
||||
expect(err.code).toBe('REPOSITORY_ERROR');
|
||||
expect(err.details?.message).toBe('boom');
|
||||
expect(output.present).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user