diff --git a/LiteCharms.Features.MidrandBooks.Tests/OrderServiceFeatureTests.cs b/LiteCharms.Features.MidrandBooks.Tests/OrderServiceFeatureTests.cs index e14e007..ef09044 100644 --- a/LiteCharms.Features.MidrandBooks.Tests/OrderServiceFeatureTests.cs +++ b/LiteCharms.Features.MidrandBooks.Tests/OrderServiceFeatureTests.cs @@ -114,54 +114,83 @@ public class OrderServiceFeatureTests(Fixture fixture) : IClassFixture [IntegrationFact] public async Task AddShippingToOrderAsync_ShouldReturn_ResultWithSuccess() { + var request = new CreateShipping(1, 2); + var result = await orderService.AddShippingToOrderAsync(1, request, fixture.CancellationToken); + + Assert.True(result.IsSuccess); + Assert.True(result.Value > 0); } [IntegrationFact] public async Task UpdateShippingStatusAsync_ShouldReturn_ResultWithSuccess() { + var result = await orderService.UpdateShippingStatusAsync(1, ShippingStatuses.Shipped, fixture.CancellationToken); + Assert.True(result.IsSuccess); } [IntegrationFact] public async Task GetShippingByOrderIdAsync_ShouldReturn_ResultWithShipping() { + var result = await orderService.GetShippingByOrderIdAsync(1, fixture.CancellationToken); + Assert.True(result.IsSuccess); + Assert.NotNull(result.Value); } [IntegrationFact] public async Task RemoveShippingFromOrderAsync_ShouldReturn_ResultWithSuccess() { + var result = await orderService.RemoveShippingFromOrderAsync(1, 1, fixture.CancellationToken); + Assert.True(result.IsSuccess); } [IntegrationFact] public async Task UpdateShippingTrackingNumberAsync_ShouldReturn_ResultWithSuccess() { + var result = await orderService.UpdateShippingTrackingNumberAsync(1, 2, "NA0009969397"); + Assert.True(result.IsSuccess); } [IntegrationFact] - public async Task CreateShippingProviderAsync_ShouldReturn_ResultWithSuccess() + public async Task CreateShippingProviderAsync_ShouldReturn_ResultWithShippingProviderId() { + var request = new CreateShippingProvider(ShippingProviderTypes.FastWay, "FastWay Couriers", 50, "https://www.fastway.co.za/our-services/track-your-parcel"); + var result = await orderService.CreateShippingProviderAsync(request, fixture.CancellationToken); + + Assert.True(result.IsSuccess); + Assert.True(result.Value > 0); } [IntegrationFact] public async Task GetShippingProvidersAsync_ShouldReturn_ResultWithShippingProviderList() { + var result = await orderService.GetShippingProvidersAsync(true, fixture.CancellationToken); + Assert.True(result.IsSuccess); + Assert.NotEmpty(result.Value); } [IntegrationFact] public async Task GetShippingProviderAsync_ShouldReturn_ResultWithShippingProvider() { + var result = await orderService.GetShippingProviderAsync(2, fixture.CancellationToken); + Assert.True(result.IsSuccess); + Assert.NotNull(result.Value); } [IntegrationFact] public async Task UpdateShippingProviderAsync_ShouldReturn_ResultWithSuccess() { + var request = new UpdateShippingProvider(2,true, "FastWay Couriers", 50, "https://www.fastway.co.za/our-services/track-your-parcel"); + var result = await orderService.UpdateShippingProviderAsync(request, fixture.CancellationToken); + + Assert.True(result.IsSuccess); } } diff --git a/LiteCharms.Features.MidrandBooks/Extensions/Mappers.cs b/LiteCharms.Features.MidrandBooks/Extensions/Mappers.cs index 72e57d5..753bcc7 100644 --- a/LiteCharms.Features.MidrandBooks/Extensions/Mappers.cs +++ b/LiteCharms.Features.MidrandBooks/Extensions/Mappers.cs @@ -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() diff --git a/LiteCharms.Features.MidrandBooks/Orders/Models/Records.cs b/LiteCharms.Features.MidrandBooks/Orders/Models/Records.cs index c4c072a..6ffccb4 100644 --- a/LiteCharms.Features.MidrandBooks/Orders/Models/Records.cs +++ b/LiteCharms.Features.MidrandBooks/Orders/Models/Records.cs @@ -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); diff --git a/LiteCharms.Features.MidrandBooks/Orders/OrderService.cs b/LiteCharms.Features.MidrandBooks/Orders/OrderService.cs index 84c7d86..290908b 100644 --- a/LiteCharms.Features.MidrandBooks/Orders/OrderService.cs +++ b/LiteCharms.Features.MidrandBooks/Orders/OrderService.cs @@ -249,7 +249,7 @@ public sealed class OrderService(IDbContextFactory contex } } - public async ValueTask AddShippingToOrderAsync(long orderId, CreateShipping request, CancellationToken cancellationToken = default) + public async ValueTask> AddShippingToOrderAsync(long orderId, CreateShipping request, CancellationToken cancellationToken = default) { try { @@ -371,7 +371,7 @@ public sealed class OrderService(IDbContextFactory contex } } - public async ValueTask CreateShippingProviderAsync(CreateShippingProvider request, CancellationToken cancellationToken = default) + public async ValueTask> CreateShippingProviderAsync(CreateShippingProvider request, CancellationToken cancellationToken = default) { try { @@ -382,6 +382,7 @@ public sealed class OrderService(IDbContextFactory 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 contex }); return await context.SaveChangesAsync(cancellationToken) > 0 - ? Result.Ok() + ? Result.Ok(shippingProvider.Entity.Id) : Result.Fail("Failed to create shipping provider."); } catch (Exception ex)