refactor use cases
This commit is contained in:
@@ -9,25 +9,17 @@ import type { IProtestRepository } from '../../domain/repositories/IProtestRepos
|
||||
import type { IDriverRepository } from '../../domain/repositories/IDriverRepository';
|
||||
import { Protest } from '../../domain/entities/Protest';
|
||||
import { Driver } from '../../domain/entities/Driver';
|
||||
import type { UseCaseOutputPort } from '@core/shared/application';
|
||||
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
|
||||
|
||||
describe('GetRaceProtestsUseCase', () => {
|
||||
let useCase: GetRaceProtestsUseCase;
|
||||
let protestRepository: { findByRaceId: Mock };
|
||||
let driverRepository: { findById: Mock };
|
||||
let output: UseCaseOutputPort<GetRaceProtestsResult> & { present: Mock };
|
||||
|
||||
beforeEach(() => {
|
||||
protestRepository = { findByRaceId: vi.fn() };
|
||||
driverRepository = { findById: vi.fn() };
|
||||
output = { present: vi.fn() } as unknown as UseCaseOutputPort<GetRaceProtestsResult> & { present: Mock };
|
||||
|
||||
useCase = new GetRaceProtestsUseCase(
|
||||
protestRepository as unknown as IProtestRepository,
|
||||
driverRepository as unknown as IDriverRepository,
|
||||
output,
|
||||
);
|
||||
useCase = new GetRaceProtestsUseCase(protestRepository as unknown as IProtestRepository,
|
||||
driverRepository as unknown as IDriverRepository);
|
||||
});
|
||||
|
||||
it('should return protests with drivers', async () => {
|
||||
@@ -76,9 +68,7 @@ describe('GetRaceProtestsUseCase', () => {
|
||||
expect(result.isOk()).toBe(true);
|
||||
expect(result.unwrap()).toBeUndefined();
|
||||
|
||||
expect(output.present).toHaveBeenCalledTimes(1);
|
||||
const presentedRaw = output.present.mock.calls[0]?.[0];
|
||||
expect(presentedRaw).toBeDefined();
|
||||
const presentedRaw = expect(presentedRaw).toBeDefined();
|
||||
const presented = presentedRaw as GetRaceProtestsResult;
|
||||
|
||||
expect(presented.protests).toHaveLength(1);
|
||||
@@ -97,9 +87,7 @@ describe('GetRaceProtestsUseCase', () => {
|
||||
expect(result.isOk()).toBe(true);
|
||||
expect(result.unwrap()).toBeUndefined();
|
||||
|
||||
expect(output.present).toHaveBeenCalledTimes(1);
|
||||
const presentedRaw = output.present.mock.calls[0]?.[0];
|
||||
expect(presentedRaw).toBeDefined();
|
||||
const presentedRaw = expect(presentedRaw).toBeDefined();
|
||||
const presented = presentedRaw as GetRaceProtestsResult;
|
||||
|
||||
expect(presented.protests).toEqual([]);
|
||||
@@ -121,6 +109,5 @@ describe('GetRaceProtestsUseCase', () => {
|
||||
|
||||
expect(err.code).toBe('REPOSITORY_ERROR');
|
||||
expect(err.details.message).toBe('DB error');
|
||||
expect(output.present).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user