Completed payment service implementation
This commit is contained in:
@@ -0,0 +1,98 @@
|
||||
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<Fixture>
|
||||
{
|
||||
private readonly PaymentService paymentService = fixture.Services.GetRequiredService<PaymentService>();
|
||||
|
||||
[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);
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,47 @@ public class ProductServiceFeatureTests(Fixture fixture, ITestOutputHelper outpu
|
||||
{
|
||||
private readonly ProductService productService = fixture.Services.GetRequiredService<ProductService>();
|
||||
|
||||
[IntegrationFact]
|
||||
public async Task CheckProductStockAvailabilityAsync_ShouldReturn_ResultWithProductInventory()
|
||||
{
|
||||
var result = await productService.CheckProductStockAvailabilityAsync(1, 1, fixture.CancellationToken);
|
||||
|
||||
Assert.True(result.IsSuccess);
|
||||
Assert.NotNull(result.Value);
|
||||
}
|
||||
|
||||
[IntegrationFact]
|
||||
public async Task ReserveProductInventoryAsync_ShouldReturn_ResultWithSuccess()
|
||||
{
|
||||
var request = new ReserveStock
|
||||
{
|
||||
ProductId = 1,
|
||||
ProductPriceId = 1,
|
||||
Reservation = 100,
|
||||
};
|
||||
|
||||
var result = await productService.ReserveProductInventoryAsync(request, fixture.CancellationToken);
|
||||
|
||||
Assert.True(result.IsSuccess);
|
||||
Assert.True(result.Value > 0);
|
||||
}
|
||||
|
||||
[IntegrationFact]
|
||||
public async Task AllocateProductInventoryAsync_ShouldReturn_ResultWithSuccess()
|
||||
{
|
||||
var request = new AllocateStock
|
||||
{
|
||||
ProductId = 1,
|
||||
ProductPriceId = 1,
|
||||
Allocation = 500,
|
||||
};
|
||||
|
||||
var result = await productService.AllocateProductInventoryAsync(request, fixture.CancellationToken);
|
||||
|
||||
Assert.True(result.IsSuccess);
|
||||
Assert.True(result.Value > 0);
|
||||
}
|
||||
|
||||
[IntegrationFact]
|
||||
public async Task AddProductCategoryAsync_ShouldReturn_ResultWithId()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user