refactor use cases
This commit is contained in:
@@ -9,7 +9,6 @@ import {
|
||||
type CreateSeasonForLeagueResult,
|
||||
type LeagueConfigFormModel,
|
||||
} from '@core/racing/application/use-cases/CreateSeasonForLeagueUseCase';
|
||||
import type { UseCaseOutputPort } from '@core/shared/application';
|
||||
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
|
||||
import { Result } from '@core/shared/application/Result';
|
||||
|
||||
@@ -99,7 +98,7 @@ describe('CreateSeasonForLeagueUseCase', () => {
|
||||
listActiveByLeague: vi.fn(),
|
||||
};
|
||||
|
||||
let output: { present: Mock } & UseCaseOutputPort<CreateSeasonForLeagueResult>;
|
||||
let output: { present: Mock } ;
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
@@ -110,7 +109,7 @@ describe('CreateSeasonForLeagueUseCase', () => {
|
||||
mockLeagueFindById.mockResolvedValue({ id: 'league-1' });
|
||||
mockSeasonAdd.mockResolvedValue(undefined);
|
||||
|
||||
const useCase = new CreateSeasonForLeagueUseCase(mockLeagueRepo, mockSeasonRepo, output);
|
||||
const useCase = new CreateSeasonForLeagueUseCase(mockLeagueRepo, mockSeasonRepo);
|
||||
|
||||
const config = createLeagueConfigFormModel({
|
||||
basics: {
|
||||
@@ -147,9 +146,7 @@ describe('CreateSeasonForLeagueUseCase', () => {
|
||||
expect(result.isOk()).toBe(true);
|
||||
expect(result.unwrap()).toBeUndefined();
|
||||
|
||||
expect(output.present).toHaveBeenCalledTimes(1);
|
||||
const presented = (output.present as Mock).mock.calls[0]?.[0] as CreateSeasonForLeagueResult;
|
||||
expect(presented?.season).toBeInstanceOf(Season);
|
||||
const presented = (expect(presented?.season).toBeInstanceOf(Season);
|
||||
expect(presented?.league.id).toBe('league-1');
|
||||
});
|
||||
|
||||
@@ -166,7 +163,7 @@ describe('CreateSeasonForLeagueUseCase', () => {
|
||||
mockSeasonFindById.mockResolvedValue(sourceSeason);
|
||||
mockSeasonAdd.mockResolvedValue(undefined);
|
||||
|
||||
const useCase = new CreateSeasonForLeagueUseCase(mockLeagueRepo, mockSeasonRepo, output);
|
||||
const useCase = new CreateSeasonForLeagueUseCase(mockLeagueRepo, mockSeasonRepo);
|
||||
|
||||
const command: CreateSeasonForLeagueInput = {
|
||||
leagueId: 'league-1',
|
||||
@@ -180,15 +177,13 @@ describe('CreateSeasonForLeagueUseCase', () => {
|
||||
expect(result.isOk()).toBe(true);
|
||||
expect(result.unwrap()).toBeUndefined();
|
||||
|
||||
expect(output.present).toHaveBeenCalledTimes(1);
|
||||
const presented = (output.present as Mock).mock.calls[0]?.[0] as CreateSeasonForLeagueResult;
|
||||
expect(presented?.season.maxDrivers).toBe(40);
|
||||
const presented = (expect(presented?.season.maxDrivers).toBe(40);
|
||||
});
|
||||
|
||||
it('returns error when league not found and does not call output', async () => {
|
||||
mockLeagueFindById.mockResolvedValue(null);
|
||||
|
||||
const useCase = new CreateSeasonForLeagueUseCase(mockLeagueRepo, mockSeasonRepo, output);
|
||||
const useCase = new CreateSeasonForLeagueUseCase(mockLeagueRepo, mockSeasonRepo);
|
||||
|
||||
const command: CreateSeasonForLeagueInput = {
|
||||
leagueId: 'missing-league',
|
||||
@@ -202,14 +197,13 @@ describe('CreateSeasonForLeagueUseCase', () => {
|
||||
const error = result.unwrapErr();
|
||||
expect(error.code).toBe('LEAGUE_NOT_FOUND');
|
||||
expect(error.details?.message).toBe('League not found: missing-league');
|
||||
expect(output.present).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
it('returns validation error when source season is missing and does not call output', async () => {
|
||||
mockLeagueFindById.mockResolvedValue({ id: 'league-1' });
|
||||
mockSeasonFindById.mockResolvedValue(undefined);
|
||||
|
||||
const useCase = new CreateSeasonForLeagueUseCase(mockLeagueRepo, mockSeasonRepo, output);
|
||||
const useCase = new CreateSeasonForLeagueUseCase(mockLeagueRepo, mockSeasonRepo);
|
||||
|
||||
const command: CreateSeasonForLeagueInput = {
|
||||
leagueId: 'league-1',
|
||||
@@ -224,6 +218,5 @@ describe('CreateSeasonForLeagueUseCase', () => {
|
||||
const error = result.unwrapErr();
|
||||
expect(error.code).toBe('VALIDATION_ERROR');
|
||||
expect(error.details?.message).toBe('Source Season not found: missing-source');
|
||||
expect(output.present).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user