website refactor
This commit is contained in:
@@ -1,25 +1,18 @@
|
||||
import { describe, it, expect, beforeEach, vi, Mock } from 'vitest';
|
||||
import {
|
||||
GetEntitySponsorshipPricingUseCase,
|
||||
type GetEntitySponsorshipPricingInput,
|
||||
type GetEntitySponsorshipPricingResult,
|
||||
} from './GetEntitySponsorshipPricingUseCase';
|
||||
import type { SponsorshipPricingRepository } from '../../domain/repositories/SponsorshipPricingRepository';
|
||||
import type { Logger } from '@core/shared/application';
|
||||
import type { Logger } from '@core/shared/domain/Logger';
|
||||
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
|
||||
import { beforeEach, describe, expect, it, Mock, vi } from 'vitest';
|
||||
import {
|
||||
GetEntitySponsorshipPricingUseCase,
|
||||
type GetEntitySponsorshipPricingInput
|
||||
} from './GetEntitySponsorshipPricingUseCase';
|
||||
|
||||
describe('GetEntitySponsorshipPricingUseCase', () => {
|
||||
let mockSponsorshipPricingRepo: ISponsorshipPricingRepository;
|
||||
let mockSponsorshipPricingRepo: any;
|
||||
let mockLogger: Logger;
|
||||
let mockFindByEntity: Mock;
|
||||
let mockFindPendingByEntity: Mock;
|
||||
let mockFindBySeasonId: Mock;
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
mockFindByEntity = vi.fn();
|
||||
mockFindPendingByEntity = vi.fn();
|
||||
mockFindBySeasonId = vi.fn();
|
||||
mockSponsorshipPricingRepo = {
|
||||
findByEntity: mockFindByEntity,
|
||||
findAll: vi.fn(),
|
||||
@@ -29,18 +22,17 @@ describe('GetEntitySponsorshipPricingUseCase', () => {
|
||||
save: vi.fn(),
|
||||
exists: vi.fn(),
|
||||
findAcceptingApplications: vi.fn(),
|
||||
} as ISponsorshipPricingRepository;
|
||||
};
|
||||
mockLogger = {
|
||||
debug: vi.fn(),
|
||||
info: vi.fn(),
|
||||
warn: vi.fn(),
|
||||
error: vi.fn(),
|
||||
};
|
||||
output = { present: vi.fn() } as unknown as typeof output;
|
||||
});
|
||||
|
||||
it('should return PRICING_NOT_CONFIGURED when no pricing found', async () => {
|
||||
const useCase = new GetEntitySponsorshipPricingUseCase(mockSponsorshipPricingRepo as unknown as ISponsorshipPricingRepository,
|
||||
const useCase = new GetEntitySponsorshipPricingUseCase(mockSponsorshipPricingRepo as any,
|
||||
mockLogger);
|
||||
|
||||
const dto: GetEntitySponsorshipPricingInput = {
|
||||
@@ -59,10 +51,10 @@ describe('GetEntitySponsorshipPricingUseCase', () => {
|
||||
>;
|
||||
expect(err.code).toBe('PRICING_NOT_CONFIGURED');
|
||||
expect(err.details.message).toContain('No sponsorship pricing configured');
|
||||
});
|
||||
});
|
||||
|
||||
it('should return pricing data when found', async () => {
|
||||
const useCase = new GetEntitySponsorshipPricingUseCase(mockSponsorshipPricingRepo as unknown as ISponsorshipPricingRepository,
|
||||
const useCase = new GetEntitySponsorshipPricingUseCase(mockSponsorshipPricingRepo as any,
|
||||
mockLogger);
|
||||
|
||||
const dto: GetEntitySponsorshipPricingInput = {
|
||||
@@ -88,14 +80,12 @@ describe('GetEntitySponsorshipPricingUseCase', () => {
|
||||
};
|
||||
|
||||
mockFindByEntity.mockResolvedValue(pricing);
|
||||
mockFindPendingByEntity.mockResolvedValue([]);
|
||||
mockFindBySeasonId.mockResolvedValue([]);
|
||||
|
||||
const result = await useCase.execute(dto);
|
||||
|
||||
expect(result.isOk()).toBe(true);
|
||||
expect(result.unwrap()).toBeUndefined();
|
||||
const presented = (expect(presented.entityType).toBe('season');
|
||||
const presented = result.unwrap();
|
||||
expect(presented.entityType).toBe('season');
|
||||
expect(presented.entityId).toBe('season1');
|
||||
expect(presented.acceptingApplications).toBe(true);
|
||||
expect(presented.customRequirements).toBe('Some requirements');
|
||||
@@ -116,7 +106,7 @@ describe('GetEntitySponsorshipPricingUseCase', () => {
|
||||
});
|
||||
|
||||
it('should return error when repository throws', async () => {
|
||||
const useCase = new GetEntitySponsorshipPricingUseCase(mockSponsorshipPricingRepo as unknown as ISponsorshipPricingRepository,
|
||||
const useCase = new GetEntitySponsorshipPricingUseCase(mockSponsorshipPricingRepo as any,
|
||||
mockLogger);
|
||||
|
||||
const dto: GetEntitySponsorshipPricingInput = {
|
||||
@@ -137,5 +127,5 @@ describe('GetEntitySponsorshipPricingUseCase', () => {
|
||||
>;
|
||||
expect(err.code).toBe('REPOSITORY_ERROR');
|
||||
expect(err.details.message).toBe('Repository error');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user