Files
gridpilot.gg/core/payments/application/use-cases/CreatePaymentUseCase.test.ts
2026-01-16 13:48:18 +01:00

57 lines
1.5 KiB
TypeScript

import { describe, it, expect, vi, type Mock } from 'vitest';
import { CreatePaymentUseCase, type CreatePaymentInput } from './CreatePaymentUseCase';
import type { PaymentRepository } from '../../domain/repositories/PaymentRepository';
import { PaymentType, PayerType, PaymentStatus } from '../../domain/entities/Payment';
describe('CreatePaymentUseCase', () => {
let paymentRepository: {
create: Mock;
};
let useCase: CreatePaymentUseCase;
beforeEach(() => {
paymentRepository = {
create: vi.fn(),
};
useCase = new CreatePaymentUseCase(
paymentRepository as unknown as IPaymentRepository,
);
});
it('creates a payment and returns result', async () => {
const input: CreatePaymentInput = {
type: PaymentType.SPONSORSHIP,
amount: 100,
payerId: 'payer-1',
payerType: PayerType.SPONSOR,
leagueId: 'league-1',
seasonId: 'season-1',
};
const createdPayment = {
id: 'payment-1',
type: PaymentType.SPONSORSHIP,
amount: 100,
platformFee: 5,
netAmount: 95,
payerId: 'payer-1',
payerType: PayerType.SPONSOR,
leagueId: 'league-1',
seasonId: 'season-1',
status: PaymentStatus.PENDING,
createdAt: new Date(),
};
paymentRepository.create.mockResolvedValue(createdPayment);
const result = await useCase.execute(input);
expect(result.isOk()).toBe(true);
expect(paymentRepository.create).toHaveBeenCalled();
if (result.isOk()) {
expect(result.value.payment).toEqual(createdPayment);
}
});
});