42 lines
1.5 KiB
TypeScript
42 lines
1.5 KiB
TypeScript
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: { findByRaceId: Mock };
|
|
|
|
beforeEach(() => {
|
|
registrationRepository = { findByRaceId: vi.fn() };
|
|
useCase = new GetRaceRegistrationsUseCase(
|
|
registrationRepository as unknown as IRaceRegistrationRepository,
|
|
);
|
|
});
|
|
|
|
it('should return registrations', async () => {
|
|
const raceId = 'race-1';
|
|
const registrations = [
|
|
RaceRegistration.create({ raceId, driverId: 'driver-1' }),
|
|
RaceRegistration.create({ raceId, driverId: 'driver-2' }),
|
|
];
|
|
|
|
registrationRepository.findByRaceId.mockResolvedValue(registrations);
|
|
|
|
const result = await useCase.execute({ raceId });
|
|
|
|
expect(result.isOk()).toBe(true);
|
|
const outputPort = result.unwrap();
|
|
expect(outputPort.registrations).toEqual(registrations);
|
|
});
|
|
|
|
it('should return empty array when no registrations', async () => {
|
|
registrationRepository.findByRaceId.mockResolvedValue([]);
|
|
|
|
const result = await useCase.execute({ raceId: 'race-1' });
|
|
|
|
expect(result.isOk()).toBe(true);
|
|
const outputPort = result.unwrap();
|
|
expect(outputPort.registrations).toEqual([]);
|
|
});
|
|
}); |