module cleanup
This commit is contained in:
210
apps/api/src/domain/sponsor/SponsorController.test.ts
Normal file
210
apps/api/src/domain/sponsor/SponsorController.test.ts
Normal file
@@ -0,0 +1,210 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { vi } from 'vitest';
|
||||
import { SponsorController } from './SponsorController';
|
||||
import { SponsorService } from './SponsorService';
|
||||
|
||||
describe('SponsorController', () => {
|
||||
let controller: SponsorController;
|
||||
let sponsorService: ReturnType<typeof vi.mocked<SponsorService>>;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
controllers: [SponsorController],
|
||||
providers: [
|
||||
{
|
||||
provide: SponsorService,
|
||||
useValue: {
|
||||
getEntitySponsorshipPricing: vi.fn(),
|
||||
getSponsors: vi.fn(),
|
||||
createSponsor: vi.fn(),
|
||||
getSponsorDashboard: vi.fn(),
|
||||
getSponsorSponsorships: vi.fn(),
|
||||
getSponsor: vi.fn(),
|
||||
getPendingSponsorshipRequests: vi.fn(),
|
||||
acceptSponsorshipRequest: vi.fn(),
|
||||
rejectSponsorshipRequest: vi.fn(),
|
||||
},
|
||||
},
|
||||
],
|
||||
}).compile();
|
||||
|
||||
controller = module.get<SponsorController>(SponsorController);
|
||||
sponsorService = vi.mocked(module.get(SponsorService));
|
||||
});
|
||||
|
||||
describe('getEntitySponsorshipPricing', () => {
|
||||
it('should return sponsorship pricing', async () => {
|
||||
const mockResult = { entityType: 'season', entityId: 'season-1', pricing: [] };
|
||||
sponsorService.getEntitySponsorshipPricing.mockResolvedValue(mockResult);
|
||||
|
||||
const result = await controller.getEntitySponsorshipPricing();
|
||||
|
||||
expect(result).toEqual(mockResult);
|
||||
expect(sponsorService.getEntitySponsorshipPricing).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('getSponsors', () => {
|
||||
it('should return sponsors list', async () => {
|
||||
const mockResult = { sponsors: [] };
|
||||
sponsorService.getSponsors.mockResolvedValue(mockResult);
|
||||
|
||||
const result = await controller.getSponsors();
|
||||
|
||||
expect(result).toEqual(mockResult);
|
||||
expect(sponsorService.getSponsors).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('createSponsor', () => {
|
||||
it('should create sponsor', async () => {
|
||||
const input = { name: 'Test Sponsor', contactEmail: 'test@example.com' };
|
||||
const mockResult = { id: 'sponsor-1', name: 'Test Sponsor' };
|
||||
sponsorService.createSponsor.mockResolvedValue(mockResult);
|
||||
|
||||
const result = await controller.createSponsor(input);
|
||||
|
||||
expect(result).toEqual(mockResult);
|
||||
expect(sponsorService.createSponsor).toHaveBeenCalledWith(input);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getSponsorDashboard', () => {
|
||||
it('should return sponsor dashboard', async () => {
|
||||
const sponsorId = 'sponsor-1';
|
||||
const mockResult = { sponsorId, metrics: {}, sponsoredLeagues: [] };
|
||||
sponsorService.getSponsorDashboard.mockResolvedValue(mockResult);
|
||||
|
||||
const result = await controller.getSponsorDashboard(sponsorId);
|
||||
|
||||
expect(result).toEqual(mockResult);
|
||||
expect(sponsorService.getSponsorDashboard).toHaveBeenCalledWith({ sponsorId });
|
||||
});
|
||||
|
||||
it('should return null when sponsor not found', async () => {
|
||||
const sponsorId = 'sponsor-1';
|
||||
sponsorService.getSponsorDashboard.mockResolvedValue(null);
|
||||
|
||||
const result = await controller.getSponsorDashboard(sponsorId);
|
||||
|
||||
expect(result).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe('getSponsorSponsorships', () => {
|
||||
it('should return sponsor sponsorships', async () => {
|
||||
const sponsorId = 'sponsor-1';
|
||||
const mockResult = { sponsorId, sponsorships: [] };
|
||||
sponsorService.getSponsorSponsorships.mockResolvedValue(mockResult);
|
||||
|
||||
const result = await controller.getSponsorSponsorships(sponsorId);
|
||||
|
||||
expect(result).toEqual(mockResult);
|
||||
expect(sponsorService.getSponsorSponsorships).toHaveBeenCalledWith({ sponsorId });
|
||||
});
|
||||
|
||||
it('should return null when sponsor not found', async () => {
|
||||
const sponsorId = 'sponsor-1';
|
||||
sponsorService.getSponsorSponsorships.mockResolvedValue(null);
|
||||
|
||||
const result = await controller.getSponsorSponsorships(sponsorId);
|
||||
|
||||
expect(result).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe('getSponsor', () => {
|
||||
it('should return sponsor', async () => {
|
||||
const sponsorId = 'sponsor-1';
|
||||
const mockResult = { id: sponsorId, name: 'Test Sponsor' };
|
||||
sponsorService.getSponsor.mockResolvedValue(mockResult);
|
||||
|
||||
const result = await controller.getSponsor(sponsorId);
|
||||
|
||||
expect(result).toEqual(mockResult);
|
||||
expect(sponsorService.getSponsor).toHaveBeenCalledWith(sponsorId);
|
||||
});
|
||||
|
||||
it('should return null when sponsor not found', async () => {
|
||||
const sponsorId = 'sponsor-1';
|
||||
sponsorService.getSponsor.mockResolvedValue(null);
|
||||
|
||||
const result = await controller.getSponsor(sponsorId);
|
||||
|
||||
expect(result).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe('getPendingSponsorshipRequests', () => {
|
||||
it('should return pending sponsorship requests', async () => {
|
||||
const query = { entityType: 'season' as const, entityId: 'season-1' };
|
||||
const mockResult = { entityType: 'season', entityId: 'season-1', requests: [], totalCount: 0 };
|
||||
sponsorService.getPendingSponsorshipRequests.mockResolvedValue(mockResult);
|
||||
|
||||
const result = await controller.getPendingSponsorshipRequests(query);
|
||||
|
||||
expect(result).toEqual(mockResult);
|
||||
expect(sponsorService.getPendingSponsorshipRequests).toHaveBeenCalledWith(query);
|
||||
});
|
||||
});
|
||||
|
||||
describe('acceptSponsorshipRequest', () => {
|
||||
it('should accept sponsorship request', async () => {
|
||||
const requestId = 'request-1';
|
||||
const input = { respondedBy: 'user-1' };
|
||||
const mockResult = {
|
||||
requestId,
|
||||
sponsorshipId: 'sponsorship-1',
|
||||
status: 'accepted' as const,
|
||||
acceptedAt: new Date(),
|
||||
platformFee: 10,
|
||||
netAmount: 90,
|
||||
};
|
||||
sponsorService.acceptSponsorshipRequest.mockResolvedValue(mockResult);
|
||||
|
||||
const result = await controller.acceptSponsorshipRequest(requestId, input);
|
||||
|
||||
expect(result).toEqual(mockResult);
|
||||
expect(sponsorService.acceptSponsorshipRequest).toHaveBeenCalledWith(requestId, input.respondedBy);
|
||||
});
|
||||
|
||||
it('should return null on error', async () => {
|
||||
const requestId = 'request-1';
|
||||
const input = { respondedBy: 'user-1' };
|
||||
sponsorService.acceptSponsorshipRequest.mockResolvedValue(null);
|
||||
|
||||
const result = await controller.acceptSponsorshipRequest(requestId, input);
|
||||
|
||||
expect(result).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe('rejectSponsorshipRequest', () => {
|
||||
it('should reject sponsorship request', async () => {
|
||||
const requestId = 'request-1';
|
||||
const input = { respondedBy: 'user-1', reason: 'Not interested' };
|
||||
const mockResult = {
|
||||
requestId,
|
||||
status: 'rejected' as const,
|
||||
rejectedAt: new Date(),
|
||||
reason: 'Not interested',
|
||||
};
|
||||
sponsorService.rejectSponsorshipRequest.mockResolvedValue(mockResult);
|
||||
|
||||
const result = await controller.rejectSponsorshipRequest(requestId, input);
|
||||
|
||||
expect(result).toEqual(mockResult);
|
||||
expect(sponsorService.rejectSponsorshipRequest).toHaveBeenCalledWith(requestId, input.respondedBy, input.reason);
|
||||
});
|
||||
|
||||
it('should return null on error', async () => {
|
||||
const requestId = 'request-1';
|
||||
const input = { respondedBy: 'user-1' };
|
||||
sponsorService.rejectSponsorshipRequest.mockResolvedValue(null);
|
||||
|
||||
const result = await controller.rejectSponsorshipRequest(requestId, input);
|
||||
|
||||
expect(result).toBeNull();
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user