refactor core presenters
This commit is contained in:
@@ -1,38 +1,42 @@
|
||||
import { describe, it, expect, beforeEach, vi, Mock } from 'vitest';
|
||||
import { GetRaceRegistrationsUseCase } from './GetRaceRegistrationsUseCase';
|
||||
import type { IRaceRegistrationRepository } from '@core/racing/domain/repositories/IRaceRegistrationRepository';
|
||||
import { RaceRegistration } from '@core/racing/domain/entities/RaceRegistration';
|
||||
|
||||
describe('GetRaceRegistrationsUseCase', () => {
|
||||
let useCase: GetRaceRegistrationsUseCase;
|
||||
let registrationRepository: { getRegisteredDrivers: Mock };
|
||||
let registrationRepository: { findByRaceId: Mock };
|
||||
|
||||
beforeEach(() => {
|
||||
registrationRepository = { getRegisteredDrivers: vi.fn() };
|
||||
registrationRepository = { findByRaceId: vi.fn() };
|
||||
useCase = new GetRaceRegistrationsUseCase(
|
||||
registrationRepository as unknown as IRaceRegistrationRepository,
|
||||
);
|
||||
});
|
||||
|
||||
it('should return registered driver ids', async () => {
|
||||
it('should return registrations', async () => {
|
||||
const raceId = 'race-1';
|
||||
const registeredDriverIds = ['driver-1', 'driver-2'];
|
||||
const registrations = [
|
||||
RaceRegistration.create({ raceId, driverId: 'driver-1' }),
|
||||
RaceRegistration.create({ raceId, driverId: 'driver-2' }),
|
||||
];
|
||||
|
||||
registrationRepository.getRegisteredDrivers.mockResolvedValue(registeredDriverIds);
|
||||
registrationRepository.findByRaceId.mockResolvedValue(registrations);
|
||||
|
||||
const result = await useCase.execute({ raceId });
|
||||
|
||||
expect(result.isOk()).toBe(true);
|
||||
const dto = result.unwrap();
|
||||
expect(dto.registeredDriverIds).toEqual(registeredDriverIds);
|
||||
const outputPort = result.unwrap();
|
||||
expect(outputPort.registrations).toEqual(registrations);
|
||||
});
|
||||
|
||||
it('should return empty array when no registrations', async () => {
|
||||
registrationRepository.getRegisteredDrivers.mockResolvedValue([]);
|
||||
registrationRepository.findByRaceId.mockResolvedValue([]);
|
||||
|
||||
const result = await useCase.execute({ raceId: 'race-1' });
|
||||
|
||||
expect(result.isOk()).toBe(true);
|
||||
const dto = result.unwrap();
|
||||
expect(dto.registeredDriverIds).toEqual([]);
|
||||
const outputPort = result.unwrap();
|
||||
expect(outputPort.registrations).toEqual([]);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user