refactor use cases
This commit is contained in:
@@ -11,7 +11,6 @@ import type { IDriverRepository } from '../../domain/repositories/IDriverReposit
|
||||
import type { IRaceRegistrationRepository } from '../../domain/repositories/IRaceRegistrationRepository';
|
||||
import type { IResultRepository } from '../../domain/repositories/IResultRepository';
|
||||
import type { ILeagueMembershipRepository } from '../../domain/repositories/ILeagueMembershipRepository';
|
||||
import type { UseCaseOutputPort } from '@core/shared/application/UseCaseOutputPort';
|
||||
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
|
||||
import { Race } from '../../domain/entities/Race';
|
||||
|
||||
@@ -23,7 +22,6 @@ describe('GetRaceDetailUseCase', () => {
|
||||
let raceRegistrationRepository: { findByRaceId: Mock };
|
||||
let resultRepository: { findByRaceId: Mock };
|
||||
let leagueMembershipRepository: { getMembership: Mock };
|
||||
let output: UseCaseOutputPort<GetRaceDetailResult> & { present: Mock };
|
||||
|
||||
beforeEach(() => {
|
||||
raceRepository = { findById: vi.fn() };
|
||||
@@ -32,7 +30,6 @@ describe('GetRaceDetailUseCase', () => {
|
||||
raceRegistrationRepository = { findByRaceId: vi.fn() };
|
||||
resultRepository = { findByRaceId: vi.fn() };
|
||||
leagueMembershipRepository = { getMembership: vi.fn() };
|
||||
output = { present: vi.fn() } as UseCaseOutputPort<GetRaceDetailResult> & { present: Mock };
|
||||
|
||||
useCase = new GetRaceDetailUseCase(
|
||||
raceRepository as unknown as IRaceRepository,
|
||||
@@ -41,11 +38,10 @@ describe('GetRaceDetailUseCase', () => {
|
||||
raceRegistrationRepository as unknown as IRaceRegistrationRepository,
|
||||
resultRepository as unknown as IResultRepository,
|
||||
leagueMembershipRepository as unknown as ILeagueMembershipRepository,
|
||||
output,
|
||||
);
|
||||
});
|
||||
|
||||
it('should present race detail when race exists', async () => {
|
||||
it('should return race detail when race exists', async () => {
|
||||
const raceId = 'race-1';
|
||||
const driverId = 'driver-1';
|
||||
const race = Race.create({
|
||||
@@ -88,10 +84,7 @@ describe('GetRaceDetailUseCase', () => {
|
||||
const result = await useCase.execute(input);
|
||||
|
||||
expect(result.isOk()).toBe(true);
|
||||
expect(result.unwrap()).toBeUndefined();
|
||||
expect(output.present).toHaveBeenCalledTimes(1);
|
||||
|
||||
const presented = output.present.mock.calls[0]?.[0] as GetRaceDetailResult;
|
||||
const presented = result.unwrap();
|
||||
expect(presented.race).toEqual(race);
|
||||
expect(presented.league).toEqual(league);
|
||||
expect(presented.registrations).toEqual(registrations);
|
||||
@@ -111,7 +104,6 @@ describe('GetRaceDetailUseCase', () => {
|
||||
const err = result.unwrapErr() as ApplicationErrorCode<GetRaceDetailErrorCode, { message: string }>;
|
||||
expect(err.code).toBe('RACE_NOT_FOUND');
|
||||
expect(err.details?.message).toBe('Race not found');
|
||||
expect(output.present).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should include user result when race is completed', async () => {
|
||||
@@ -141,10 +133,7 @@ describe('GetRaceDetailUseCase', () => {
|
||||
const result = await useCase.execute(input);
|
||||
|
||||
expect(result.isOk()).toBe(true);
|
||||
expect(result.unwrap()).toBeUndefined();
|
||||
expect(output.present).toHaveBeenCalledTimes(1);
|
||||
|
||||
const presented = output.present.mock.calls[0]?.[0] as GetRaceDetailResult;
|
||||
const presented = result.unwrap();
|
||||
expect(presented.userResult).toBe(userDomainResult);
|
||||
expect(presented.race).toEqual(race);
|
||||
expect(presented.league).toBeNull();
|
||||
@@ -162,6 +151,5 @@ describe('GetRaceDetailUseCase', () => {
|
||||
const err = result.unwrapErr() as ApplicationErrorCode<GetRaceDetailErrorCode, { message: string }>;
|
||||
expect(err.code).toBe('REPOSITORY_ERROR');
|
||||
expect(err.details.message).toBe('db down');
|
||||
expect(output.present).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user