refactor use cases
This commit is contained in:
@@ -16,7 +16,6 @@ import { SeasonSponsorship } from '../../domain/entities/season/SeasonSponsorshi
|
||||
import { Season } from '../../domain/entities/season/Season';
|
||||
import { League } from '../../domain/entities/League';
|
||||
import { Money } from '../../domain/value-objects/Money';
|
||||
import type { UseCaseOutputPort } from '@core/shared/application';
|
||||
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
|
||||
|
||||
describe('GetSponsorDashboardUseCase', () => {
|
||||
@@ -39,7 +38,6 @@ describe('GetSponsorDashboardUseCase', () => {
|
||||
let raceRepository: {
|
||||
findByLeagueId: Mock;
|
||||
};
|
||||
let output: UseCaseOutputPort<GetSponsorDashboardResult> & { present: Mock };
|
||||
|
||||
beforeEach(() => {
|
||||
sponsorRepository = {
|
||||
@@ -60,9 +58,6 @@ describe('GetSponsorDashboardUseCase', () => {
|
||||
raceRepository = {
|
||||
findByLeagueId: vi.fn(),
|
||||
};
|
||||
output = {
|
||||
present: vi.fn(),
|
||||
} as unknown as UseCaseOutputPort<GetSponsorDashboardResult> & { present: Mock };
|
||||
|
||||
useCase = new GetSponsorDashboardUseCase(
|
||||
sponsorRepository as unknown as ISponsorRepository,
|
||||
@@ -71,11 +66,10 @@ describe('GetSponsorDashboardUseCase', () => {
|
||||
leagueRepository as unknown as ILeagueRepository,
|
||||
leagueMembershipRepository as unknown as ILeagueMembershipRepository,
|
||||
raceRepository as unknown as IRaceRepository,
|
||||
output,
|
||||
);
|
||||
});
|
||||
|
||||
it('should present sponsor dashboard for existing sponsor', async () => {
|
||||
it('should return sponsor dashboard for existing sponsor', async () => {
|
||||
const sponsorId = 'sponsor-1';
|
||||
const sponsor = Sponsor.create({
|
||||
id: sponsorId,
|
||||
@@ -116,12 +110,7 @@ describe('GetSponsorDashboardUseCase', () => {
|
||||
const result = await useCase.execute(input);
|
||||
|
||||
expect(result.isOk()).toBe(true);
|
||||
expect(result.unwrap()).toBeUndefined();
|
||||
|
||||
expect(output.present).toHaveBeenCalledTimes(1);
|
||||
const dashboardRaw = (output.present as Mock).mock.calls[0]?.[0];
|
||||
expect(dashboardRaw).toBeDefined();
|
||||
const dashboard = dashboardRaw as GetSponsorDashboardResult;
|
||||
const dashboard = result.unwrap();
|
||||
|
||||
expect(dashboard).toBeDefined();
|
||||
expect(dashboard.sponsorId).toBe(sponsorId);
|
||||
@@ -146,7 +135,6 @@ describe('GetSponsorDashboardUseCase', () => {
|
||||
|
||||
expect(error.code).toBe('SPONSOR_NOT_FOUND');
|
||||
expect(error.details.message).toBe('Sponsor not found');
|
||||
expect(output.present).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should return error on repository failure', async () => {
|
||||
@@ -165,6 +153,5 @@ describe('GetSponsorDashboardUseCase', () => {
|
||||
|
||||
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