From 5bfb3576db044265903669c53160d6b4495078d5 Mon Sep 17 00:00:00 2001 From: Italo Pessoa Date: Tue, 24 Sep 2024 08:12:38 -0300 Subject: [PATCH] fix CreateOrderPayment get user order from UC #155 --- .../UseCases/Payment/CreatePaymentUseCase.cs | 9 +++++---- .../UseCases/Payments/CreatePaymentUseCaseTest.cs | 15 +++++++++------ 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/FIAP.TechChallenge.ByteMeBurger.Application/UseCases/Payment/CreatePaymentUseCase.cs b/src/FIAP.TechChallenge.ByteMeBurger.Application/UseCases/Payment/CreatePaymentUseCase.cs index 223452a..1220a90 100644 --- a/src/FIAP.TechChallenge.ByteMeBurger.Application/UseCases/Payment/CreatePaymentUseCase.cs +++ b/src/FIAP.TechChallenge.ByteMeBurger.Application/UseCases/Payment/CreatePaymentUseCase.cs @@ -1,3 +1,4 @@ +using FIAP.TechChallenge.ByteMeBurger.Application.UseCases.Orders; using FIAP.TechChallenge.ByteMeBurger.Domain.Base; using FIAP.TechChallenge.ByteMeBurger.Domain.Events; using FIAP.TechChallenge.ByteMeBurger.Domain.Interfaces; @@ -8,17 +9,17 @@ namespace FIAP.TechChallenge.ByteMeBurger.Application.UseCases.Payment; public class CreatePaymentUseCase : ICreatePaymentUseCase { private readonly IPaymentGatewayFactoryMethod _paymentGatewayFactory; - private readonly IOrderRepository _orderRepository; + private readonly IGetOrderDetailsUseCase _getOrderDetailsUseCase; - public CreatePaymentUseCase(IPaymentGatewayFactoryMethod paymentGatewayFactory, IOrderRepository orderRepository) + public CreatePaymentUseCase(IPaymentGatewayFactoryMethod paymentGatewayFactory, IGetOrderDetailsUseCase getOrderDetailsUseCase) { _paymentGatewayFactory = paymentGatewayFactory; - _orderRepository = orderRepository; + _getOrderDetailsUseCase = getOrderDetailsUseCase; } public async Task Execute(Guid orderId, PaymentType paymentType) { - var order = await _orderRepository.GetAsync(orderId); + var order = await _getOrderDetailsUseCase.Execute(orderId); if (order is null) throw new EntityNotFoundException("Order not found."); diff --git a/tests/FIAP.TechChallenge.ByteMeBurger.Application.Test/UseCases/Payments/CreatePaymentUseCaseTest.cs b/tests/FIAP.TechChallenge.ByteMeBurger.Application.Test/UseCases/Payments/CreatePaymentUseCaseTest.cs index 75d76f2..e2f6ba6 100644 --- a/tests/FIAP.TechChallenge.ByteMeBurger.Application.Test/UseCases/Payments/CreatePaymentUseCaseTest.cs +++ b/tests/FIAP.TechChallenge.ByteMeBurger.Application.Test/UseCases/Payments/CreatePaymentUseCaseTest.cs @@ -1,4 +1,5 @@ using AutoFixture; +using FIAP.TechChallenge.ByteMeBurger.Application.UseCases.Orders; using FIAP.TechChallenge.ByteMeBurger.Application.UseCases.Payment; using FIAP.TechChallenge.ByteMeBurger.Domain.Base; using FIAP.TechChallenge.ByteMeBurger.Domain.Interfaces; @@ -9,15 +10,17 @@ namespace FIAP.TechChallenge.ByteMeBurger.Application.Test.UseCases.Payments; public class CreatePaymentUseCaseTest { private readonly Mock _paymentGatewayMock; + private readonly CreatePaymentUseCase _createPaymentUseCase; - private readonly Mock _orderRepository; + + private readonly Mock _getOrderDetailsUseCase; public CreatePaymentUseCaseTest() { - _orderRepository = new Mock(); _paymentGatewayMock = new Mock(); Mock paymentGatewayFactory = new(); - _createPaymentUseCase = new CreatePaymentUseCase(paymentGatewayFactory.Object, _orderRepository.Object); + _getOrderDetailsUseCase = new Mock(); + _createPaymentUseCase = new CreatePaymentUseCase(paymentGatewayFactory.Object, _getOrderDetailsUseCase.Object); paymentGatewayFactory.Setup(g => g.Create(It.IsAny())) .Returns(_paymentGatewayMock.Object); @@ -37,7 +40,7 @@ public async Task Execute_ValidOrder_ShouldReturnPayment() .With(p => p.Status, PaymentStatus.Pending) .Create(); - _orderRepository.Setup(o => o.GetAsync(It.IsAny())) + _getOrderDetailsUseCase.Setup(o => o.Execute(It.IsAny())) .ReturnsAsync(order); _paymentGatewayMock.Setup(ps => ps.CreatePaymentAsync(It.IsAny())) .ReturnsAsync(expectedPayment); @@ -56,7 +59,7 @@ public async Task Execute_ValidOrder_ShouldReturnPayment() public async Task Execute_OrderNotFound_ShouldThrowDomainException() { // Arrange - _orderRepository.Setup(o => o.GetAsync(It.IsAny())) + _getOrderDetailsUseCase.Setup(o => o.Execute(It.IsAny())) .ReturnsAsync((Order?)default); // Act @@ -74,7 +77,7 @@ await func.Should() public async Task Execute_OrderAlreadyHasPayment_ShouldThrowDomainException() { // Arrange - _orderRepository.Setup(o => o.GetAsync(It.IsAny())) + _getOrderDetailsUseCase.Setup(o => o.Execute(It.IsAny())) .ReturnsAsync(new Order { PaymentId = new PaymentId(Guid.NewGuid())