refactor use cases
This commit is contained in:
@@ -9,7 +9,6 @@ import type { IRaceRepository } from '../../domain/repositories/IRaceRepository'
|
||||
import type { Logger } from '@core/shared/application';
|
||||
import { Race } from '../../domain/entities/Race';
|
||||
import { SessionType } from '../../domain/value-objects/SessionType';
|
||||
import type { UseCaseOutputPort } from '@core/shared/application/UseCaseOutputPort';
|
||||
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
|
||||
|
||||
describe('ReopenRaceUseCase', () => {
|
||||
@@ -23,8 +22,6 @@ describe('ReopenRaceUseCase', () => {
|
||||
info: Mock;
|
||||
error: Mock;
|
||||
};
|
||||
let output: UseCaseOutputPort<ReopenRaceResult> & { present: Mock };
|
||||
|
||||
let useCase: ReopenRaceUseCase;
|
||||
|
||||
beforeEach(() => {
|
||||
@@ -40,15 +37,8 @@ describe('ReopenRaceUseCase', () => {
|
||||
error: vi.fn(),
|
||||
};
|
||||
|
||||
output = {
|
||||
present: vi.fn(),
|
||||
} as unknown as UseCaseOutputPort<ReopenRaceResult> & { present: Mock };
|
||||
|
||||
useCase = new ReopenRaceUseCase(
|
||||
raceRepository as unknown as IRaceRepository,
|
||||
logger as unknown as Logger,
|
||||
output,
|
||||
);
|
||||
useCase = new ReopenRaceUseCase(raceRepository as unknown as IRaceRepository,
|
||||
logger as unknown as Logger);
|
||||
});
|
||||
|
||||
it('returns RACE_NOT_FOUND when race does not exist', async () => {
|
||||
@@ -65,8 +55,7 @@ describe('ReopenRaceUseCase', () => {
|
||||
>;
|
||||
expect(err.code).toBe('RACE_NOT_FOUND');
|
||||
expect(err.details.message).toContain('race-404');
|
||||
expect(output.present).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
it('reopens a completed race, persists, and presents the result', async () => {
|
||||
const race = Race.create({
|
||||
@@ -92,9 +81,7 @@ describe('ReopenRaceUseCase', () => {
|
||||
expect(updatedRace.id).toBe('race-1');
|
||||
expect(updatedRace.status.toString()).toBe('scheduled');
|
||||
|
||||
expect(output.present).toHaveBeenCalledTimes(1);
|
||||
const presented = (output.present as Mock).mock.calls[0]?.[0] as ReopenRaceResult;
|
||||
expect(presented.race.id).toBe('race-1');
|
||||
const presented = (expect(presented.race.id).toBe('race-1');
|
||||
expect(presented.race.status.toString()).toBe('scheduled');
|
||||
|
||||
expect(logger.info).toHaveBeenCalled();
|
||||
@@ -123,8 +110,7 @@ describe('ReopenRaceUseCase', () => {
|
||||
>;
|
||||
expect(err.code).toBe('INVALID_RACE_STATE');
|
||||
expect(err.details.message).toContain('already scheduled');
|
||||
expect(output.present).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
it('returns INVALID_RACE_STATE when race is running', async () => {
|
||||
const race = Race.create({
|
||||
@@ -149,8 +135,7 @@ describe('ReopenRaceUseCase', () => {
|
||||
>;
|
||||
expect(err.code).toBe('INVALID_RACE_STATE');
|
||||
expect(err.details.message).toContain('running race');
|
||||
expect(output.present).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
it('returns REPOSITORY_ERROR when repository throws unexpected error', async () => {
|
||||
raceRepository.findById.mockRejectedValue(new Error('DB error'));
|
||||
@@ -165,6 +150,5 @@ describe('ReopenRaceUseCase', () => {
|
||||
>;
|
||||
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