test apps api

This commit is contained in:
2025-12-23 23:14:51 +01:00
parent 16cd572c63
commit efcdbd17f2
71 changed files with 3924 additions and 913 deletions

View File

@@ -40,7 +40,7 @@ describe('SponsorController', () => {
describe('getEntitySponsorshipPricing', () => {
it('should return sponsorship pricing', async () => {
const mockResult = { entityType: 'season', entityId: 'season-1', pricing: [] };
sponsorService.getEntitySponsorshipPricing.mockResolvedValue({ viewModel: mockResult } as any);
sponsorService.getEntitySponsorshipPricing.mockResolvedValue(mockResult as any);
const result = await controller.getEntitySponsorshipPricing();
@@ -52,7 +52,7 @@ describe('SponsorController', () => {
describe('getSponsors', () => {
it('should return sponsors list', async () => {
const mockResult = { sponsors: [] };
sponsorService.getSponsors.mockResolvedValue({ viewModel: mockResult } as any);
sponsorService.getSponsors.mockResolvedValue(mockResult as any);
const result = await controller.getSponsors();
@@ -65,7 +65,7 @@ describe('SponsorController', () => {
it('should create sponsor', async () => {
const input = { name: 'Test Sponsor', contactEmail: 'test@example.com' };
const mockResult = { sponsor: { id: 's1', name: 'Test Sponsor' } };
sponsorService.createSponsor.mockResolvedValue({ viewModel: mockResult } as any);
sponsorService.createSponsor.mockResolvedValue(mockResult as any);
const result = await controller.createSponsor(input as any);
@@ -78,7 +78,7 @@ describe('SponsorController', () => {
it('should return sponsor dashboard', async () => {
const sponsorId = 's1';
const mockResult = { sponsorId, metrics: {} as any, sponsoredLeagues: [], investment: {} as any };
sponsorService.getSponsorDashboard.mockResolvedValue({ viewModel: mockResult } as any);
sponsorService.getSponsorDashboard.mockResolvedValue(mockResult as any);
const result = await controller.getSponsorDashboard(sponsorId);
@@ -86,13 +86,11 @@ describe('SponsorController', () => {
expect(sponsorService.getSponsorDashboard).toHaveBeenCalledWith({ sponsorId });
});
it('should return null when sponsor not found', async () => {
it('should throw when sponsor not found', async () => {
const sponsorId = 's1';
sponsorService.getSponsorDashboard.mockResolvedValue({ viewModel: null } as any);
sponsorService.getSponsorDashboard.mockRejectedValue(new Error('Sponsor dashboard not found'));
const result = await controller.getSponsorDashboard(sponsorId);
expect(result).toBeNull();
await expect(controller.getSponsorDashboard(sponsorId)).rejects.toBeInstanceOf(Error);
});
});
@@ -111,7 +109,7 @@ describe('SponsorController', () => {
currency: 'USD',
},
};
sponsorService.getSponsorSponsorships.mockResolvedValue({ viewModel: mockResult } as any);
sponsorService.getSponsorSponsorships.mockResolvedValue(mockResult as any);
const result = await controller.getSponsorSponsorships(sponsorId);
@@ -119,13 +117,11 @@ describe('SponsorController', () => {
expect(sponsorService.getSponsorSponsorships).toHaveBeenCalledWith({ sponsorId });
});
it('should return null when sponsor not found', async () => {
it('should throw when sponsor not found', async () => {
const sponsorId = 's1';
sponsorService.getSponsorSponsorships.mockResolvedValue({ viewModel: null } as any);
sponsorService.getSponsorSponsorships.mockRejectedValue(new Error('Sponsor sponsorships not found'));
const result = await controller.getSponsorSponsorships(sponsorId);
expect(result).toBeNull();
await expect(controller.getSponsorSponsorships(sponsorId)).rejects.toBeInstanceOf(Error);
});
});
@@ -133,7 +129,7 @@ describe('SponsorController', () => {
it('should return sponsor', async () => {
const sponsorId = 's1';
const mockResult = { sponsor: { id: sponsorId, name: 'S1' } };
sponsorService.getSponsor.mockResolvedValue({ viewModel: mockResult } as any);
sponsorService.getSponsor.mockResolvedValue(mockResult as any);
const result = await controller.getSponsor(sponsorId);
@@ -141,13 +137,11 @@ describe('SponsorController', () => {
expect(sponsorService.getSponsor).toHaveBeenCalledWith(sponsorId);
});
it('should return null when sponsor not found', async () => {
it('should throw when sponsor not found', async () => {
const sponsorId = 's1';
sponsorService.getSponsor.mockResolvedValue({ viewModel: null } as any);
sponsorService.getSponsor.mockRejectedValue(new Error('Sponsor not found'));
const result = await controller.getSponsor(sponsorId);
expect(result).toBeNull();
await expect(controller.getSponsor(sponsorId)).rejects.toBeInstanceOf(Error);
});
});
@@ -160,7 +154,7 @@ describe('SponsorController', () => {
requests: [],
totalCount: 0,
};
sponsorService.getPendingSponsorshipRequests.mockResolvedValue({ viewModel: mockResult } as any);
sponsorService.getPendingSponsorshipRequests.mockResolvedValue(mockResult as any);
const result = await controller.getPendingSponsorshipRequests(query);
@@ -181,7 +175,7 @@ describe('SponsorController', () => {
platformFee: 10,
netAmount: 90,
};
sponsorService.acceptSponsorshipRequest.mockResolvedValue({ viewModel: mockResult } as any);
sponsorService.acceptSponsorshipRequest.mockResolvedValue(mockResult as any);
const result = await controller.acceptSponsorshipRequest(requestId, input as any);
@@ -192,14 +186,12 @@ describe('SponsorController', () => {
);
});
it('should return null on error', async () => {
it('should throw on error', async () => {
const requestId = 'r1';
const input = { respondedBy: 'u1' };
sponsorService.acceptSponsorshipRequest.mockResolvedValue({ viewModel: null } as any);
sponsorService.acceptSponsorshipRequest.mockRejectedValue(new Error('Accept sponsorship request failed'));
const result = await controller.acceptSponsorshipRequest(requestId, input as any);
expect(result).toBeNull();
await expect(controller.acceptSponsorshipRequest(requestId, input as any)).rejects.toBeInstanceOf(Error);
});
});
@@ -213,7 +205,7 @@ describe('SponsorController', () => {
rejectedAt: new Date(),
reason: 'Not interested',
};
sponsorService.rejectSponsorshipRequest.mockResolvedValue({ viewModel: mockResult } as any);
sponsorService.rejectSponsorshipRequest.mockResolvedValue(mockResult as any);
const result = await controller.rejectSponsorshipRequest(requestId, input as any);
@@ -225,14 +217,12 @@ describe('SponsorController', () => {
);
});
it('should return null on error', async () => {
it('should throw on error', async () => {
const requestId = 'r1';
const input = { respondedBy: 'u1' };
sponsorService.rejectSponsorshipRequest.mockResolvedValue({ viewModel: null } as any);
sponsorService.rejectSponsorshipRequest.mockRejectedValue(new Error('Reject sponsorship request failed'));
const result = await controller.rejectSponsorshipRequest(requestId, input as any);
expect(result).toBeNull();
await expect(controller.rejectSponsorshipRequest(requestId, input as any)).rejects.toBeInstanceOf(Error);
});
});
@@ -251,7 +241,7 @@ describe('SponsorController', () => {
averageMonthlySpend: 0,
},
};
sponsorService.getSponsorBilling.mockResolvedValue({ viewModel: mockResult } as any);
sponsorService.getSponsorBilling.mockResolvedValue(mockResult as any);
const result = await controller.getSponsorBilling(sponsorId);