using LiteCharms.Features.MidrandBooks.Payments; using LiteCharms.Features.MidrandBooks.Payments.Models; using LiteCharms.Features.MidrandBooks.Tests.Common; namespace LiteCharms.Features.MidrandBooks.Tests; public sealed class PaymentServiceFeatureTests(Fixture fixture) : IClassFixture { private readonly PaymentService paymentService = fixture.Services.GetRequiredService(); [IntegrationFact] public async Task CreateRefundAsync_ShouldReturn_ResultWithRefundId() { var request = new CreateRefund { Amount = 50, OrderId = 2, Type = RefundTypes.Partial, Reason = "Returned damaged book", Status = RefundStatus.Completed, }; var result = await paymentService.CreateRefundAsync(request, fixture.CancellationToken); Assert.True(result.IsSuccess); Assert.True(result.Value > 0); } [IntegrationFact] public async Task WriteLedgerEntryAsync_ShouldReturn_ResultWithSuccess() { var request = new CreateLedgerEntry { CustomerId = 1, OrderId = 1, PaymentGatewayId = 1, PaymentGatewayReference = "TEST REFERENCE", PaymentId = 1, Status = LedgerStatuses.Received, }; var result = await paymentService.WriteLedgerEntryAsync(request, fixture.CancellationToken); Assert.True(result.IsSuccess); } [IntegrationFact] public async Task GetPaymentGatewayAsync_ShouldReturn_ResultWithPaymentGateway() { var result = await paymentService.GetPaymentGatewayAsync(1, fixture.CancellationToken); Assert.True(result.IsSuccess); Assert.NotNull(result.Value); } [IntegrationFact] public async Task CreatePaymentGatewayAsync_ShouldReturn_ResultWithGatewayId() { var request = new CreatePaymentGateway { IsSandbox = true, MerchantId = "10049307", MerchantKey = "ju6navn0jcbf0", Name = "Payfast", Website = "https://sandbox.payfast.co.za/eng/process", }; var result = await paymentService.CreatePaymentGatewayAsync(request, fixture.CancellationToken); Assert.True(result.IsSuccess); Assert.True(result.Value > 0); } [IntegrationFact] public async Task CompletePaymentAsync_ShouldReturn_ResultWithSuccess() { var result = await paymentService.CompletePaymentAsync(1, PaymentStatuses.Paid, fixture.CancellationToken); Assert.True(result.IsSuccess); } [IntegrationFact] public async Task UpdatePaymentAsync_ShouldReturn_ResultWithSuccess() { var result = await paymentService.UpdatePaymentAsync(1, 200, fixture.CancellationToken); Assert.True(result.IsSuccess); } [IntegrationFact] public async Task CreatePaymentAsync_ShouldReturn_ResultWithPaymentId() { var result = await paymentService.CreatePaymentAsync(100, 1, "HASHEDID", fixture.CancellationToken); Assert.True(result.IsSuccess); Assert.True(result.Value > 0); } }