refactor dtos to ports
This commit is contained in:
@@ -3,7 +3,6 @@ import { GetRaceWithSOFUseCase } from './GetRaceWithSOFUseCase';
|
||||
import { IRaceRepository } from '../../domain/repositories/IRaceRepository';
|
||||
import { IRaceRegistrationRepository } from '../../domain/repositories/IRaceRegistrationRepository';
|
||||
import { IResultRepository } from '../../domain/repositories/IResultRepository';
|
||||
import { DriverRatingProvider } from '../ports/DriverRatingProvider';
|
||||
import { Race } from '../../domain/entities/Race';
|
||||
import { SessionType } from '../../domain/value-objects/SessionType';
|
||||
|
||||
@@ -18,9 +17,7 @@ describe('GetRaceWithSOFUseCase', () => {
|
||||
let resultRepository: {
|
||||
findByRaceId: Mock;
|
||||
};
|
||||
let driverRatingProvider: {
|
||||
getRatings: Mock;
|
||||
};
|
||||
let getDriverRating: Mock;
|
||||
|
||||
beforeEach(() => {
|
||||
raceRepository = {
|
||||
@@ -32,14 +29,12 @@ describe('GetRaceWithSOFUseCase', () => {
|
||||
resultRepository = {
|
||||
findByRaceId: vi.fn(),
|
||||
};
|
||||
driverRatingProvider = {
|
||||
getRatings: vi.fn(),
|
||||
};
|
||||
getDriverRating = vi.fn();
|
||||
useCase = new GetRaceWithSOFUseCase(
|
||||
raceRepository as unknown as IRaceRepository,
|
||||
registrationRepository as unknown as IRaceRegistrationRepository,
|
||||
resultRepository as unknown as IResultRepository,
|
||||
driverRatingProvider as unknown as DriverRatingProvider,
|
||||
getDriverRating,
|
||||
);
|
||||
});
|
||||
|
||||
@@ -96,10 +91,11 @@ describe('GetRaceWithSOFUseCase', () => {
|
||||
|
||||
raceRepository.findById.mockResolvedValue(race);
|
||||
registrationRepository.getRegisteredDrivers.mockResolvedValue(['driver-1', 'driver-2']);
|
||||
driverRatingProvider.getRatings.mockReturnValue(new Map([
|
||||
['driver-1', 1400],
|
||||
['driver-2', 1600],
|
||||
]));
|
||||
getDriverRating.mockImplementation((input) => {
|
||||
if (input.driverId === 'driver-1') return Promise.resolve({ rating: 1400, ratingChange: null });
|
||||
if (input.driverId === 'driver-2') return Promise.resolve({ rating: 1600, ratingChange: null });
|
||||
return Promise.resolve({ rating: null, ratingChange: null });
|
||||
});
|
||||
|
||||
const result = await useCase.execute({ raceId: 'race-1' });
|
||||
|
||||
@@ -127,10 +123,11 @@ describe('GetRaceWithSOFUseCase', () => {
|
||||
{ driverId: 'driver-1' },
|
||||
{ driverId: 'driver-2' },
|
||||
]);
|
||||
driverRatingProvider.getRatings.mockReturnValue(new Map([
|
||||
['driver-1', 1400],
|
||||
['driver-2', 1600],
|
||||
]));
|
||||
getDriverRating.mockImplementation((input) => {
|
||||
if (input.driverId === 'driver-1') return Promise.resolve({ rating: 1400, ratingChange: null });
|
||||
if (input.driverId === 'driver-2') return Promise.resolve({ rating: 1600, ratingChange: null });
|
||||
return Promise.resolve({ rating: null, ratingChange: null });
|
||||
});
|
||||
|
||||
const result = await useCase.execute({ raceId: 'race-1' });
|
||||
|
||||
@@ -155,10 +152,11 @@ describe('GetRaceWithSOFUseCase', () => {
|
||||
|
||||
raceRepository.findById.mockResolvedValue(race);
|
||||
registrationRepository.getRegisteredDrivers.mockResolvedValue(['driver-1', 'driver-2']);
|
||||
driverRatingProvider.getRatings.mockReturnValue(new Map([
|
||||
['driver-1', 1400],
|
||||
getDriverRating.mockImplementation((input) => {
|
||||
if (input.driverId === 'driver-1') return Promise.resolve({ rating: 1400, ratingChange: null });
|
||||
// driver-2 missing
|
||||
]));
|
||||
return Promise.resolve({ rating: null, ratingChange: null });
|
||||
});
|
||||
|
||||
const result = await useCase.execute({ raceId: 'race-1' });
|
||||
|
||||
|
||||
Reference in New Issue
Block a user