refactor racing use cases

This commit is contained in:
2025-12-21 00:43:42 +01:00
parent e9d6f90bb2
commit c12656d671
308 changed files with 14401 additions and 7419 deletions

View File

@@ -2,8 +2,8 @@ import type { NotificationService } from '@/notifications/application/ports/Noti
import type { IWalletRepository } from '@core/payments/domain/repositories/IWalletRepository';
import type { Logger } from '@core/shared/application';
import { beforeEach, describe, expect, it, Mock, vi } from 'vitest';
import { LeagueWallet } from '../../domain/entities/LeagueWallet';
import { Season } from '../../domain/entities/Season';
import { LeagueWallet } from '../../domain/entities/league-wallet/LeagueWallet';
import { Season } from '../../domain/entities/season/Season';
import { SponsorshipRequest } from '../../domain/entities/SponsorshipRequest';
import type { ILeagueWalletRepository } from '../../domain/repositories/ILeagueWalletRepository';
import type { ISeasonRepository } from '../../domain/repositories/ISeasonRepository';
@@ -73,7 +73,11 @@ describe('AcceptSponsorshipRequestUseCase', () => {
};
});
it('should send notification to sponsor, process payment, and update wallets when accepting season sponsorship', async () => {
it('should send notification to sponsor, process payment, update wallets, and present result when accepting season sponsorship', async () => {
const output = {
present: vi.fn(),
};
const useCase = new AcceptSponsorshipRequestUseCase(
mockSponsorshipRequestRepo as unknown as ISponsorshipRequestRepository,
mockSeasonSponsorshipRepo as unknown as ISeasonSponsorshipRepository,
@@ -83,6 +87,7 @@ describe('AcceptSponsorshipRequestUseCase', () => {
mockWalletRepo as unknown as IWalletRepository,
mockLeagueWalletRepo as unknown as ILeagueWalletRepository,
mockLogger as unknown as Logger,
output,
);
const request = SponsorshipRequest.create({
@@ -135,8 +140,8 @@ describe('AcceptSponsorshipRequestUseCase', () => {
});
expect(result.isOk()).toBe(true);
const dto = result.unwrap();
expect(dto).toBeDefined();
expect(result.unwrap()).toBeUndefined();
expect(mockNotificationService.sendNotification).toHaveBeenCalledWith({
recipientId: 'sponsor1',
type: 'sponsorship_request_accepted',
@@ -146,28 +151,35 @@ describe('AcceptSponsorshipRequestUseCase', () => {
urgency: 'toast',
data: {
requestId: 'req1',
sponsorshipId: dto.sponsorshipId,
sponsorshipId: expect.any(String),
},
});
expect(processPayment).toHaveBeenCalledWith(
{
amount: Money.create(1000),
payerId: 'sponsor1',
description: 'Sponsorship payment for season season1',
metadata: { requestId: 'req1' }
}
);
expect(processPayment).toHaveBeenCalledWith({
amount: 1000,
payerId: 'sponsor1',
description: 'Sponsorship payment for season season1',
metadata: { requestId: 'req1' },
});
expect(mockWalletRepo.update).toHaveBeenCalledWith(
expect.objectContaining({
id: 'sponsor1',
balance: 1000,
})
}),
);
expect(mockLeagueWalletRepo.update).toHaveBeenCalledWith(
expect.objectContaining({
id: 'league1',
balance: expect.objectContaining({ amount: 1400 }),
})
}),
);
expect(output.present).toHaveBeenCalledWith({
requestId: 'req1',
sponsorshipId: expect.any(String),
status: 'accepted',
acceptedAt: expect.any(Date),
platformFee: expect.any(Number),
netAmount: expect.any(Number),
});
});
});