refactor use cases
This commit is contained in:
@@ -14,7 +14,6 @@ import { Season } from '../../domain/entities/season/Season';
|
||||
import { League } from '../../domain/entities/League';
|
||||
import { SeasonSponsorship } from '../../domain/entities/season/SeasonSponsorship';
|
||||
import { Money } from '../../domain/value-objects/Money';
|
||||
import type { UseCaseOutputPort } from '@core/shared/application/UseCaseOutputPort';
|
||||
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
|
||||
|
||||
describe('GetSeasonSponsorshipsUseCase', () => {
|
||||
@@ -34,8 +33,6 @@ describe('GetSeasonSponsorshipsUseCase', () => {
|
||||
findByLeagueId: Mock;
|
||||
};
|
||||
|
||||
let output: UseCaseOutputPort<GetSeasonSponsorshipsResult> & { present: Mock };
|
||||
|
||||
let useCase: GetSeasonSponsorshipsUseCase;
|
||||
|
||||
beforeEach(() => {
|
||||
@@ -55,18 +52,11 @@ describe('GetSeasonSponsorshipsUseCase', () => {
|
||||
findByLeagueId: vi.fn(),
|
||||
};
|
||||
|
||||
output = {
|
||||
present: vi.fn(),
|
||||
} as unknown as UseCaseOutputPort<GetSeasonSponsorshipsResult> & { present: Mock };
|
||||
|
||||
useCase = new GetSeasonSponsorshipsUseCase(
|
||||
seasonSponsorshipRepository as unknown as ISeasonSponsorshipRepository,
|
||||
useCase = new GetSeasonSponsorshipsUseCase(seasonSponsorshipRepository as unknown as ISeasonSponsorshipRepository,
|
||||
seasonRepository as unknown as ISeasonRepository,
|
||||
leagueRepository as unknown as ILeagueRepository,
|
||||
leagueMembershipRepository as unknown as ILeagueMembershipRepository,
|
||||
raceRepository as unknown as IRaceRepository,
|
||||
output,
|
||||
);
|
||||
raceRepository as unknown as IRaceRepository);
|
||||
});
|
||||
|
||||
it('returns SEASON_NOT_FOUND when season does not exist', async () => {
|
||||
@@ -83,8 +73,7 @@ describe('GetSeasonSponsorshipsUseCase', () => {
|
||||
>;
|
||||
expect(err.code).toBe('SEASON_NOT_FOUND');
|
||||
expect(err.details.message).toBe('Season not found');
|
||||
expect(output.present).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
it('returns LEAGUE_NOT_FOUND when league for season does not exist', async () => {
|
||||
const input: GetSeasonSponsorshipsInput = { seasonId: 'season-1' };
|
||||
@@ -109,8 +98,7 @@ describe('GetSeasonSponsorshipsUseCase', () => {
|
||||
>;
|
||||
expect(err.code).toBe('LEAGUE_NOT_FOUND');
|
||||
expect(err.details.message).toBe('League not found for season');
|
||||
expect(output.present).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
it('presents sponsorship details with computed metrics', async () => {
|
||||
const input: GetSeasonSponsorshipsInput = { seasonId: 'season-1' };
|
||||
@@ -162,10 +150,7 @@ describe('GetSeasonSponsorshipsUseCase', () => {
|
||||
|
||||
expect(result.isOk()).toBe(true);
|
||||
|
||||
expect(output.present).toHaveBeenCalledTimes(1);
|
||||
const presented = (output.present as Mock).mock.calls[0]?.[0] as GetSeasonSponsorshipsResult;
|
||||
|
||||
expect(presented.seasonId).toBe('season-1');
|
||||
const presented = (expect(presented.seasonId).toBe('season-1');
|
||||
expect(presented.sponsorships).toHaveLength(1);
|
||||
|
||||
const detail = presented.sponsorships[0]!;
|
||||
@@ -202,6 +187,5 @@ describe('GetSeasonSponsorshipsUseCase', () => {
|
||||
>;
|
||||
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