website refactor
This commit is contained in:
@@ -19,19 +19,19 @@ describe('GetRaceResultsDetailUseCase', () => {
|
||||
let resultRepository: { findByRaceId: Mock };
|
||||
let driverRepository: { findAll: Mock };
|
||||
let penaltyRepository: { findByRaceId: Mock };
|
||||
|
||||
beforeEach(() => {
|
||||
raceRepository = { findById: vi.fn() };
|
||||
leagueRepository = { findById: vi.fn() };
|
||||
resultRepository = { findByRaceId: vi.fn() };
|
||||
driverRepository = { findAll: vi.fn() };
|
||||
penaltyRepository = { findByRaceId: vi.fn() };
|
||||
};
|
||||
|
||||
useCase = new GetRaceResultsDetailUseCase(raceRepository as unknown as IRaceRepository,
|
||||
leagueRepository as unknown as ILeagueRepository,
|
||||
resultRepository as unknown as IResultRepository,
|
||||
driverRepository as unknown as IDriverRepository,
|
||||
penaltyRepository as unknown as IPenaltyRepository);
|
||||
useCase = new GetRaceResultsDetailUseCase(raceRepository as any,
|
||||
leagueRepository as any,
|
||||
resultRepository as any,
|
||||
driverRepository as any,
|
||||
penaltyRepository as any);
|
||||
});
|
||||
|
||||
it('presents race results detail when race exists', async () => {
|
||||
@@ -104,19 +104,18 @@ describe('GetRaceResultsDetailUseCase', () => {
|
||||
const result = await useCase.execute(input);
|
||||
|
||||
expect(result.isOk()).toBe(true);
|
||||
expect(result.unwrap()).toBeUndefined();
|
||||
const presented = result.unwrap();
|
||||
|
||||
const presented = (expect(presented.race).toEqual(race);
|
||||
expect(presented.race).toEqual(race);
|
||||
expect(presented.league).toEqual(league);
|
||||
expect(presented.results).toEqual(results);
|
||||
expect(presented.drivers).toEqual(drivers);
|
||||
expect(presented.penalties).toEqual(penalties);
|
||||
expect(presented.pointsSystem).toBeDefined();
|
||||
expect(presented.fastestLapTime).toBe(120);
|
||||
expect(presented.currentDriverId).toBe('driver-1');
|
||||
});
|
||||
|
||||
it('returns error when race not found and does not present data', async () => {
|
||||
it('returns error when race not found', async () => {
|
||||
const input: GetRaceResultsDetailInput = { raceId: 'race-1' };
|
||||
|
||||
raceRepository.findById.mockResolvedValue(null);
|
||||
@@ -131,7 +130,7 @@ describe('GetRaceResultsDetailUseCase', () => {
|
||||
|
||||
expect(error.code).toBe('RACE_NOT_FOUND');
|
||||
expect(error.details.message).toBe('Race not found');
|
||||
});
|
||||
});
|
||||
|
||||
it('returns repository error when an unexpected error occurs', async () => {
|
||||
const input: GetRaceResultsDetailInput = { raceId: 'race-1' };
|
||||
@@ -148,5 +147,5 @@ describe('GetRaceResultsDetailUseCase', () => {
|
||||
|
||||
expect(error.code).toBe('REPOSITORY_ERROR');
|
||||
expect(error.details.message).toBe('Database failure');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user