refactor use cases
This commit is contained in:
@@ -6,7 +6,6 @@ import {
|
||||
} from './GetEntitySponsorshipPricingUseCase';
|
||||
import type { ISponsorshipPricingRepository } from '../../domain/repositories/ISponsorshipPricingRepository';
|
||||
import type { Logger } from '@core/shared/application';
|
||||
import type { UseCaseOutputPort } from '@core/shared/application/UseCaseOutputPort';
|
||||
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
|
||||
|
||||
describe('GetEntitySponsorshipPricingUseCase', () => {
|
||||
@@ -15,8 +14,6 @@ describe('GetEntitySponsorshipPricingUseCase', () => {
|
||||
let mockFindByEntity: Mock;
|
||||
let mockFindPendingByEntity: Mock;
|
||||
let mockFindBySeasonId: Mock;
|
||||
let output: UseCaseOutputPort<GetEntitySponsorshipPricingResult> & {
|
||||
present: Mock;
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
@@ -43,11 +40,8 @@ describe('GetEntitySponsorshipPricingUseCase', () => {
|
||||
});
|
||||
|
||||
it('should return PRICING_NOT_CONFIGURED when no pricing found', async () => {
|
||||
const useCase = new GetEntitySponsorshipPricingUseCase(
|
||||
mockSponsorshipPricingRepo as unknown as ISponsorshipPricingRepository,
|
||||
mockLogger,
|
||||
output,
|
||||
);
|
||||
const useCase = new GetEntitySponsorshipPricingUseCase(mockSponsorshipPricingRepo as unknown as ISponsorshipPricingRepository,
|
||||
mockLogger);
|
||||
|
||||
const dto: GetEntitySponsorshipPricingInput = {
|
||||
entityType: 'season',
|
||||
@@ -65,15 +59,11 @@ describe('GetEntitySponsorshipPricingUseCase', () => {
|
||||
>;
|
||||
expect(err.code).toBe('PRICING_NOT_CONFIGURED');
|
||||
expect(err.details.message).toContain('No sponsorship pricing configured');
|
||||
expect(output.present).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return pricing data when found', async () => {
|
||||
const useCase = new GetEntitySponsorshipPricingUseCase(
|
||||
mockSponsorshipPricingRepo as unknown as ISponsorshipPricingRepository,
|
||||
mockLogger,
|
||||
output,
|
||||
);
|
||||
const useCase = new GetEntitySponsorshipPricingUseCase(mockSponsorshipPricingRepo as unknown as ISponsorshipPricingRepository,
|
||||
mockLogger);
|
||||
|
||||
const dto: GetEntitySponsorshipPricingInput = {
|
||||
entityType: 'season',
|
||||
@@ -105,11 +95,7 @@ describe('GetEntitySponsorshipPricingUseCase', () => {
|
||||
|
||||
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 GetEntitySponsorshipPricingResult;
|
||||
|
||||
expect(presented.entityType).toBe('season');
|
||||
const presented = (expect(presented.entityType).toBe('season');
|
||||
expect(presented.entityId).toBe('season1');
|
||||
expect(presented.acceptingApplications).toBe(true);
|
||||
expect(presented.customRequirements).toBe('Some requirements');
|
||||
@@ -130,11 +116,8 @@ describe('GetEntitySponsorshipPricingUseCase', () => {
|
||||
});
|
||||
|
||||
it('should return error when repository throws', async () => {
|
||||
const useCase = new GetEntitySponsorshipPricingUseCase(
|
||||
mockSponsorshipPricingRepo as unknown as ISponsorshipPricingRepository,
|
||||
mockLogger,
|
||||
output,
|
||||
);
|
||||
const useCase = new GetEntitySponsorshipPricingUseCase(mockSponsorshipPricingRepo as unknown as ISponsorshipPricingRepository,
|
||||
mockLogger);
|
||||
|
||||
const dto: GetEntitySponsorshipPricingInput = {
|
||||
entityType: 'season',
|
||||
@@ -154,6 +137,5 @@ describe('GetEntitySponsorshipPricingUseCase', () => {
|
||||
>;
|
||||
expect(err.code).toBe('REPOSITORY_ERROR');
|
||||
expect(err.details.message).toBe('Repository error');
|
||||
expect(output.present).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user