resolve todos in core

This commit is contained in:
2025-12-20 11:02:15 +01:00
parent 7bbad511e2
commit a87cf27fb9
10 changed files with 396 additions and 199 deletions

View File

@@ -5,11 +5,14 @@ import type { ISponsorshipRequestRepository } from '../../domain/repositories/IS
describe('RejectSponsorshipRequestUseCase', () => {
let useCase: RejectSponsorshipRequestUseCase;
let sponsorshipRequestRepo: { findById: Mock; update: Mock };
let notificationPort: { notifySponsorshipRequestRejected: Mock };
beforeEach(() => {
sponsorshipRequestRepo = { findById: vi.fn(), update: vi.fn() };
notificationPort = { notifySponsorshipRequestRejected: vi.fn() };
useCase = new RejectSponsorshipRequestUseCase(
sponsorshipRequestRepo as unknown as ISponsorshipRequestRepository,
notificationPort as any,
);
});
@@ -48,14 +51,20 @@ describe('RejectSponsorshipRequestUseCase', () => {
});
});
it('should reject the request successfully', async () => {
it('should reject the request successfully and notify sponsor with reason', async () => {
const respondedAt = new Date('2023-01-01T00:00:00Z');
const mockRequest = {
id: 'request-1',
sponsorId: 'sponsor-1',
entityType: 'season',
entityId: 'season-1',
tier: 'main',
offeredAmount: { amount: 1000, currency: 'USD' },
status: 'pending',
isPending: vi.fn().mockReturnValue(true),
reject: vi.fn().mockReturnValue({
id: 'request-1',
respondedAt: new Date('2023-01-01T00:00:00Z'),
respondedAt,
rejectionReason: 'Not interested',
}),
};
@@ -72,20 +81,39 @@ describe('RejectSponsorshipRequestUseCase', () => {
expect(result.unwrap()).toEqual({
requestId: 'request-1',
status: 'rejected',
rejectedAt: new Date('2023-01-01T00:00:00Z'),
rejectedAt: respondedAt,
reason: 'Not interested',
});
expect(sponsorshipRequestRepo.update).toHaveBeenCalledWith(mockRequest.reject());
expect(notificationPort.notifySponsorshipRequestRejected).toHaveBeenCalledTimes(1);
expect(notificationPort.notifySponsorshipRequestRejected).toHaveBeenCalledWith({
requestId: 'request-1',
sponsorId: 'sponsor-1',
entityType: 'season',
entityId: 'season-1',
tier: 'main',
offeredAmountCents: 1000,
currency: 'USD',
rejectedAt: respondedAt,
rejectedBy: 'driver-1',
rejectionReason: 'Not interested',
});
});
it('should reject the request successfully without reason', async () => {
it('should reject the request successfully and notify sponsor without reason', async () => {
const respondedAt = new Date('2023-01-01T00:00:00Z');
const mockRequest = {
id: 'request-1',
sponsorId: 'sponsor-1',
entityType: 'season',
entityId: 'season-1',
tier: 'main',
offeredAmount: { amount: 1000, currency: 'USD' },
status: 'pending',
isPending: vi.fn().mockReturnValue(true),
reject: vi.fn().mockReturnValue({
id: 'request-1',
respondedAt: new Date('2023-01-01T00:00:00Z'),
respondedAt,
rejectionReason: undefined,
}),
};
@@ -101,8 +129,21 @@ describe('RejectSponsorshipRequestUseCase', () => {
expect(result.unwrap()).toEqual({
requestId: 'request-1',
status: 'rejected',
rejectedAt: new Date('2023-01-01T00:00:00Z'),
rejectedAt: respondedAt,
});
expect(sponsorshipRequestRepo.update).toHaveBeenCalledWith(mockRequest.reject());
expect(notificationPort.notifySponsorshipRequestRejected).toHaveBeenCalledTimes(1);
expect(notificationPort.notifySponsorshipRequestRejected).toHaveBeenCalledWith({
requestId: 'request-1',
sponsorId: 'sponsor-1',
entityType: 'season',
entityId: 'season-1',
tier: 'main',
offeredAmountCents: 1000,
currency: 'USD',
rejectedAt: respondedAt,
rejectedBy: 'driver-1',
rejectionReason: undefined,
});
});
});