refactor
This commit is contained in:
@@ -6,15 +6,59 @@ import type { ISeasonSponsorshipRepository } from '../../domain/repositories/ISe
|
||||
import type { Logger } from '@core/shared/application';
|
||||
|
||||
describe('GetEntitySponsorshipPricingUseCase', () => {
|
||||
let mockSponsorshipPricingRepo: { findByEntity: Mock };
|
||||
let mockSponsorshipRequestRepo: { findPendingByEntity: Mock };
|
||||
let mockSeasonSponsorshipRepo: { findBySeasonId: Mock };
|
||||
let mockSponsorshipPricingRepo: ISponsorshipPricingRepository;
|
||||
let mockSponsorshipRequestRepo: ISponsorshipRequestRepository;
|
||||
let mockSeasonSponsorshipRepo: ISeasonSponsorshipRepository;
|
||||
let mockLogger: Logger;
|
||||
let mockFindByEntity: Mock;
|
||||
let mockFindPendingByEntity: Mock;
|
||||
let mockFindBySeasonId: Mock;
|
||||
|
||||
beforeEach(() => {
|
||||
mockSponsorshipPricingRepo = { findByEntity: vi.fn() };
|
||||
mockSponsorshipRequestRepo = { findPendingByEntity: vi.fn() };
|
||||
mockSeasonSponsorshipRepo = { findBySeasonId: vi.fn() };
|
||||
mockFindByEntity = vi.fn();
|
||||
mockFindPendingByEntity = vi.fn();
|
||||
mockFindBySeasonId = vi.fn();
|
||||
mockSponsorshipPricingRepo = {
|
||||
findByEntity: mockFindByEntity,
|
||||
findAll: vi.fn(),
|
||||
create: vi.fn(),
|
||||
update: vi.fn(),
|
||||
delete: vi.fn(),
|
||||
save: vi.fn(),
|
||||
exists: vi.fn(),
|
||||
findAcceptingApplications: vi.fn(),
|
||||
} as ISponsorshipPricingRepository;
|
||||
mockSponsorshipRequestRepo = {
|
||||
findPendingByEntity: mockFindPendingByEntity,
|
||||
findByEntity: vi.fn(),
|
||||
findById: vi.fn(),
|
||||
save: vi.fn(),
|
||||
update: vi.fn(),
|
||||
delete: vi.fn(),
|
||||
findBySponsorId: vi.fn(),
|
||||
findByStatus: vi.fn(),
|
||||
findBySponsorIdAndStatus: vi.fn(),
|
||||
hasPendingRequest: vi.fn(),
|
||||
findPendingBySponsor: vi.fn(),
|
||||
findApprovedByEntity: vi.fn(),
|
||||
findRejectedByEntity: vi.fn(),
|
||||
countPendingByEntity: vi.fn(),
|
||||
create: vi.fn(),
|
||||
exists: vi.fn(),
|
||||
} as ISponsorshipRequestRepository;
|
||||
mockSeasonSponsorshipRepo = {
|
||||
findBySeasonId: mockFindBySeasonId,
|
||||
findById: vi.fn(),
|
||||
save: vi.fn(),
|
||||
update: vi.fn(),
|
||||
delete: vi.fn(),
|
||||
findAll: vi.fn(),
|
||||
findByLeagueId: vi.fn(),
|
||||
findBySponsorId: vi.fn(),
|
||||
findBySeasonAndTier: vi.fn(),
|
||||
create: vi.fn(),
|
||||
exists: vi.fn(),
|
||||
} as ISeasonSponsorshipRepository;
|
||||
mockLogger = {
|
||||
debug: vi.fn(),
|
||||
info: vi.fn(),
|
||||
@@ -33,7 +77,7 @@ describe('GetEntitySponsorshipPricingUseCase', () => {
|
||||
|
||||
const dto = { entityType: 'season' as const, entityId: 'season1' };
|
||||
|
||||
mockSponsorshipPricingRepo.findByEntity.mockResolvedValue(null);
|
||||
mockFindByEntity.mockResolvedValue(null);
|
||||
|
||||
const result = await useCase.execute(dto);
|
||||
|
||||
@@ -67,9 +111,9 @@ describe('GetEntitySponsorshipPricingUseCase', () => {
|
||||
},
|
||||
};
|
||||
|
||||
mockSponsorshipPricingRepo.findByEntity.mockResolvedValue(pricing);
|
||||
mockSponsorshipRequestRepo.findPendingByEntity.mockResolvedValue([]);
|
||||
mockSeasonSponsorshipRepo.findBySeasonId.mockResolvedValue([]);
|
||||
mockFindByEntity.mockResolvedValue(pricing);
|
||||
mockFindPendingByEntity.mockResolvedValue([]);
|
||||
mockFindBySeasonId.mockResolvedValue([]);
|
||||
|
||||
const result = await useCase.execute(dto);
|
||||
|
||||
@@ -115,11 +159,12 @@ describe('GetEntitySponsorshipPricingUseCase', () => {
|
||||
const dto = { entityType: 'season' as const, entityId: 'season1' };
|
||||
const error = new Error('Repository error');
|
||||
|
||||
mockSponsorshipPricingRepo.findByEntity.mockRejectedValue(error);
|
||||
mockFindByEntity.mockRejectedValue(error);
|
||||
|
||||
const result = await useCase.execute(dto);
|
||||
|
||||
expect(result.isErr()).toBe(true);
|
||||
expect(result.unwrapErr().message).toBe('Repository error');
|
||||
expect(result.unwrapErr().code).toBe('REPOSITORY_ERROR');
|
||||
expect(result.unwrapErr().details.message).toBe('Repository error');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user