presenter refactoring

This commit is contained in:
2025-12-20 17:06:11 +01:00
parent 92be9d2e1b
commit e9d6f90bb2
109 changed files with 4159 additions and 1283 deletions

View File

@@ -23,6 +23,11 @@ describe('SponsorController', () => {
getPendingSponsorshipRequests: vi.fn(),
acceptSponsorshipRequest: vi.fn(),
rejectSponsorshipRequest: vi.fn(),
getSponsorBilling: vi.fn(),
getAvailableLeagues: vi.fn(),
getLeagueDetail: vi.fn(),
getSponsorSettings: vi.fn(),
updateSponsorSettings: vi.fn(),
},
},
],
@@ -35,7 +40,7 @@ describe('SponsorController', () => {
describe('getEntitySponsorshipPricing', () => {
it('should return sponsorship pricing', async () => {
const mockResult = { entityType: 'season', entityId: 'season-1', pricing: [] };
sponsorService.getEntitySponsorshipPricing.mockResolvedValue(mockResult);
sponsorService.getEntitySponsorshipPricing.mockResolvedValue({ viewModel: mockResult } as any);
const result = await controller.getEntitySponsorshipPricing();
@@ -47,7 +52,7 @@ describe('SponsorController', () => {
describe('getSponsors', () => {
it('should return sponsors list', async () => {
const mockResult = { sponsors: [] };
sponsorService.getSponsors.mockResolvedValue(mockResult);
sponsorService.getSponsors.mockResolvedValue({ viewModel: mockResult } as any);
const result = await controller.getSponsors();
@@ -59,10 +64,10 @@ describe('SponsorController', () => {
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 mockResult = { sponsor: { id: 's1', name: 'Test Sponsor' } };
sponsorService.createSponsor.mockResolvedValue({ viewModel: mockResult } as any);
const result = await controller.createSponsor(input);
const result = await controller.createSponsor(input as any);
expect(result).toEqual(mockResult);
expect(sponsorService.createSponsor).toHaveBeenCalledWith(input);
@@ -71,9 +76,9 @@ describe('SponsorController', () => {
describe('getSponsorDashboard', () => {
it('should return sponsor dashboard', async () => {
const sponsorId = 'sponsor-1';
const mockResult = { sponsorId, metrics: {}, sponsoredLeagues: [] };
sponsorService.getSponsorDashboard.mockResolvedValue(mockResult);
const sponsorId = 's1';
const mockResult = { sponsorId, metrics: {} as any, sponsoredLeagues: [], investment: {} as any };
sponsorService.getSponsorDashboard.mockResolvedValue({ viewModel: mockResult } as any);
const result = await controller.getSponsorDashboard(sponsorId);
@@ -82,8 +87,8 @@ describe('SponsorController', () => {
});
it('should return null when sponsor not found', async () => {
const sponsorId = 'sponsor-1';
sponsorService.getSponsorDashboard.mockResolvedValue(null);
const sponsorId = 's1';
sponsorService.getSponsorDashboard.mockResolvedValue({ viewModel: null } as any);
const result = await controller.getSponsorDashboard(sponsorId);
@@ -93,9 +98,20 @@ describe('SponsorController', () => {
describe('getSponsorSponsorships', () => {
it('should return sponsor sponsorships', async () => {
const sponsorId = 'sponsor-1';
const mockResult = { sponsorId, sponsorships: [] };
sponsorService.getSponsorSponsorships.mockResolvedValue(mockResult);
const sponsorId = 's1';
const mockResult = {
sponsorId,
sponsorName: 'S1',
sponsorships: [],
summary: {
totalSponsorships: 0,
activeSponsorships: 0,
totalInvestment: 0,
totalPlatformFees: 0,
currency: 'USD',
},
};
sponsorService.getSponsorSponsorships.mockResolvedValue({ viewModel: mockResult } as any);
const result = await controller.getSponsorSponsorships(sponsorId);
@@ -104,8 +120,8 @@ describe('SponsorController', () => {
});
it('should return null when sponsor not found', async () => {
const sponsorId = 'sponsor-1';
sponsorService.getSponsorSponsorships.mockResolvedValue(null);
const sponsorId = 's1';
sponsorService.getSponsorSponsorships.mockResolvedValue({ viewModel: null } as any);
const result = await controller.getSponsorSponsorships(sponsorId);
@@ -115,9 +131,9 @@ describe('SponsorController', () => {
describe('getSponsor', () => {
it('should return sponsor', async () => {
const sponsorId = 'sponsor-1';
const mockResult = { id: sponsorId, name: 'Test Sponsor' };
sponsorService.getSponsor.mockResolvedValue(mockResult);
const sponsorId = 's1';
const mockResult = { sponsor: { id: sponsorId, name: 'S1' } };
sponsorService.getSponsor.mockResolvedValue({ viewModel: mockResult } as any);
const result = await controller.getSponsor(sponsorId);
@@ -126,8 +142,8 @@ describe('SponsorController', () => {
});
it('should return null when sponsor not found', async () => {
const sponsorId = 'sponsor-1';
sponsorService.getSponsor.mockResolvedValue(null);
const sponsorId = 's1';
sponsorService.getSponsor.mockResolvedValue({ viewModel: null } as any);
const result = await controller.getSponsor(sponsorId);
@@ -138,8 +154,13 @@ describe('SponsorController', () => {
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 mockResult = {
entityType: 'season',
entityId: 'season-1',
requests: [],
totalCount: 0,
};
sponsorService.getPendingSponsorshipRequests.mockResolvedValue({ viewModel: mockResult } as any);
const result = await controller.getPendingSponsorshipRequests(query);
@@ -150,30 +171,33 @@ describe('SponsorController', () => {
describe('acceptSponsorshipRequest', () => {
it('should accept sponsorship request', async () => {
const requestId = 'request-1';
const input = { respondedBy: 'user-1' };
const requestId = 'r1';
const input = { respondedBy: 'u1' };
const mockResult = {
requestId,
sponsorshipId: 'sponsorship-1',
sponsorshipId: 'sp1',
status: 'accepted' as const,
acceptedAt: new Date(),
platformFee: 10,
netAmount: 90,
};
sponsorService.acceptSponsorshipRequest.mockResolvedValue(mockResult);
sponsorService.acceptSponsorshipRequest.mockResolvedValue({ viewModel: mockResult } as any);
const result = await controller.acceptSponsorshipRequest(requestId, input);
const result = await controller.acceptSponsorshipRequest(requestId, input as any);
expect(result).toEqual(mockResult);
expect(sponsorService.acceptSponsorshipRequest).toHaveBeenCalledWith(requestId, input.respondedBy);
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 requestId = 'r1';
const input = { respondedBy: 'u1' };
sponsorService.acceptSponsorshipRequest.mockResolvedValue({ viewModel: null } as any);
const result = await controller.acceptSponsorshipRequest(requestId, input);
const result = await controller.acceptSponsorshipRequest(requestId, input as any);
expect(result).toBeNull();
});
@@ -181,30 +205,118 @@ describe('SponsorController', () => {
describe('rejectSponsorshipRequest', () => {
it('should reject sponsorship request', async () => {
const requestId = 'request-1';
const input = { respondedBy: 'user-1', reason: 'Not interested' };
const requestId = 'r1';
const input = { respondedBy: 'u1', reason: 'Not interested' };
const mockResult = {
requestId,
status: 'rejected' as const,
rejectedAt: new Date(),
reason: 'Not interested',
};
sponsorService.rejectSponsorshipRequest.mockResolvedValue(mockResult);
sponsorService.rejectSponsorshipRequest.mockResolvedValue({ viewModel: mockResult } as any);
const result = await controller.rejectSponsorshipRequest(requestId, input);
const result = await controller.rejectSponsorshipRequest(requestId, input as any);
expect(result).toEqual(mockResult);
expect(sponsorService.rejectSponsorshipRequest).toHaveBeenCalledWith(requestId, input.respondedBy, input.reason);
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 requestId = 'r1';
const input = { respondedBy: 'u1' };
sponsorService.rejectSponsorshipRequest.mockResolvedValue({ viewModel: null } as any);
const result = await controller.rejectSponsorshipRequest(requestId, input);
const result = await controller.rejectSponsorshipRequest(requestId, input as any);
expect(result).toBeNull();
});
});
});
describe('getSponsorBilling', () => {
it('should return sponsor billing', async () => {
const sponsorId = 's1';
const mockResult = {
paymentMethods: [],
invoices: [],
stats: {
totalSpent: 0,
pendingAmount: 0,
nextPaymentDate: '2025-01-01',
nextPaymentAmount: 0,
activeSponsorships: 0,
averageMonthlySpend: 0,
},
};
sponsorService.getSponsorBilling.mockResolvedValue({ viewModel: mockResult } as any);
const result = await controller.getSponsorBilling(sponsorId);
expect(result).toEqual(mockResult);
expect(sponsorService.getSponsorBilling).toHaveBeenCalledWith(sponsorId);
});
});
describe('getAvailableLeagues', () => {
it('should return available leagues', async () => {
const mockResult: any[] = [];
sponsorService.getAvailableLeagues.mockResolvedValue({ viewModel: mockResult } as any);
const result = await controller.getAvailableLeagues();
expect(result).toEqual(mockResult);
expect(sponsorService.getAvailableLeagues).toHaveBeenCalled();
});
});
describe('getLeagueDetail', () => {
it('should return league detail', async () => {
const leagueId = 'league-1';
const mockResult = {
league: { id: leagueId } as any,
drivers: [],
races: [],
};
sponsorService.getLeagueDetail.mockResolvedValue({ viewModel: mockResult } as any);
const result = await controller.getLeagueDetail(leagueId);
expect(result).toEqual(mockResult);
expect(sponsorService.getLeagueDetail).toHaveBeenCalledWith(leagueId);
});
});
describe('getSponsorSettings', () => {
it('should return sponsor settings', async () => {
const sponsorId = 's1';
const mockResult = {
profile: {} as any,
notifications: {} as any,
privacy: {} as any,
};
sponsorService.getSponsorSettings.mockResolvedValue({ viewModel: mockResult } as any);
const result = await controller.getSponsorSettings(sponsorId);
expect(result).toEqual(mockResult);
expect(sponsorService.getSponsorSettings).toHaveBeenCalledWith(sponsorId);
});
});
describe('updateSponsorSettings', () => {
it('should update sponsor settings', async () => {
const sponsorId = 's1';
const input = {};
const mockResult = { success: true };
sponsorService.updateSponsorSettings.mockResolvedValue({ viewModel: mockResult } as any);
const result = await controller.updateSponsorSettings(sponsorId, input);
expect(result).toEqual(mockResult);
expect(sponsorService.updateSponsorSettings).toHaveBeenCalledWith(sponsorId, input);
});
});
});