refactor use cases
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import { describe, it, expect, beforeEach, vi, type Mock } from 'vitest';
|
||||
import type { UseCaseOutputPort } from '@core/shared/application';
|
||||
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
|
||||
import {
|
||||
GetLeagueStandingsUseCase,
|
||||
@@ -20,8 +19,6 @@ describe('GetLeagueStandingsUseCase', () => {
|
||||
let driverRepository: {
|
||||
findById: Mock;
|
||||
};
|
||||
let output: UseCaseOutputPort<GetLeagueStandingsResult> & { present: Mock };
|
||||
|
||||
beforeEach(() => {
|
||||
standingRepository = {
|
||||
findByLeagueId: vi.fn(),
|
||||
@@ -33,11 +30,8 @@ describe('GetLeagueStandingsUseCase', () => {
|
||||
present: vi.fn(),
|
||||
};
|
||||
|
||||
useCase = new GetLeagueStandingsUseCase(
|
||||
standingRepository as unknown as IStandingRepository,
|
||||
driverRepository as unknown as IDriverRepository,
|
||||
output,
|
||||
);
|
||||
useCase = new GetLeagueStandingsUseCase(standingRepository as unknown as IStandingRepository,
|
||||
driverRepository as unknown as IDriverRepository);
|
||||
});
|
||||
|
||||
it('should present standings with drivers mapped and return ok result', async () => {
|
||||
@@ -83,10 +77,7 @@ describe('GetLeagueStandingsUseCase', () => {
|
||||
expect(result.isOk()).toBe(true);
|
||||
expect(result.unwrap()).toBeUndefined();
|
||||
|
||||
expect(output.present).toHaveBeenCalledTimes(1);
|
||||
const presented = output.present.mock.calls[0]![0] as GetLeagueStandingsResult;
|
||||
|
||||
expect(presented.standings).toHaveLength(2);
|
||||
const presented = expect(presented.standings).toHaveLength(2);
|
||||
expect(presented.standings[0]).toEqual({
|
||||
driverId: 'driver-1',
|
||||
driver: driver1,
|
||||
@@ -115,6 +106,5 @@ describe('GetLeagueStandingsUseCase', () => {
|
||||
|
||||
expect(error.code).toBe('REPOSITORY_ERROR');
|
||||
expect(error.details.message).toBe('DB error');
|
||||
expect(output.present).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user