Implemented order service tests

This commit is contained in:
Khwezi Mngoma
2026-05-29 08:18:29 +02:00
parent 2546c34ffc
commit 4397976ed8
4 changed files with 37 additions and 6 deletions
@@ -17,7 +17,8 @@ public static class Mappers
Name = entity.Name,
Type = entity.Type,
Price = entity.Price,
Enabled = entity.Enabled
Enabled = entity.Enabled,
TrackingUrl = entity.TrackingUrl,
};
public static Shipping ToModel(this Orders.Entities.Shipping entity) => new()
@@ -4,7 +4,7 @@ public sealed record CreateOrder(decimal TotalPrice, string? Notes);
public sealed record CreateOrderItem(long AuthorBookId, long ProductPriceId, int Quantity);
public sealed record CreateShipping(long OrderId, long AddressId, long ShippingProviderId, string? TrackingNumber);
public sealed record CreateShipping(long AddressId, long ShippingProviderId, string? TrackingNumber = null);
public sealed record CreateShippingProvider(ShippingProviderTypes Type, string Name, decimal Price, string TrackingUrl);
@@ -249,7 +249,7 @@ public sealed class OrderService(IDbContextFactory<MidrandBooksDbContext> contex
}
}
public async ValueTask<Result> AddShippingToOrderAsync(long orderId, CreateShipping request, CancellationToken cancellationToken = default)
public async ValueTask<Result<long>> AddShippingToOrderAsync(long orderId, CreateShipping request, CancellationToken cancellationToken = default)
{
try
{
@@ -371,7 +371,7 @@ public sealed class OrderService(IDbContextFactory<MidrandBooksDbContext> contex
}
}
public async ValueTask<Result> CreateShippingProviderAsync(CreateShippingProvider request, CancellationToken cancellationToken = default)
public async ValueTask<Result<long>> CreateShippingProviderAsync(CreateShippingProvider request, CancellationToken cancellationToken = default)
{
try
{
@@ -382,6 +382,7 @@ public sealed class OrderService(IDbContextFactory<MidrandBooksDbContext> contex
var shippingProvider = context.ShippingProviders.Add(new Entities.ShippingProvider
{
CreatedAt = DateTime.UtcNow,
Name = request.Name,
Type = request.Type,
Price = request.Price,
@@ -389,7 +390,7 @@ public sealed class OrderService(IDbContextFactory<MidrandBooksDbContext> contex
});
return await context.SaveChangesAsync(cancellationToken) > 0
? Result.Ok()
? Result.Ok(shippingProvider.Entity.Id)
: Result.Fail("Failed to create shipping provider.");
}
catch (Exception ex)