Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix CreateOrderPayment get user order from UC #155 #156

Merged
merged 1 commit into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<Domain.Entities.Payment?> 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.");
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -9,15 +10,17 @@ namespace FIAP.TechChallenge.ByteMeBurger.Application.Test.UseCases.Payments;
public class CreatePaymentUseCaseTest
{
private readonly Mock<IPaymentGateway> _paymentGatewayMock;

private readonly CreatePaymentUseCase _createPaymentUseCase;
private readonly Mock<IOrderRepository> _orderRepository;

private readonly Mock<IGetOrderDetailsUseCase> _getOrderDetailsUseCase;

public CreatePaymentUseCaseTest()
{
_orderRepository = new Mock<IOrderRepository>();
_paymentGatewayMock = new Mock<IPaymentGateway>();
Mock<IPaymentGatewayFactoryMethod> paymentGatewayFactory = new();
_createPaymentUseCase = new CreatePaymentUseCase(paymentGatewayFactory.Object, _orderRepository.Object);
_getOrderDetailsUseCase = new Mock<IGetOrderDetailsUseCase>();
_createPaymentUseCase = new CreatePaymentUseCase(paymentGatewayFactory.Object, _getOrderDetailsUseCase.Object);

paymentGatewayFactory.Setup(g => g.Create(It.IsAny<PaymentType>()))
.Returns(_paymentGatewayMock.Object);
Expand All @@ -37,7 +40,7 @@ public async Task Execute_ValidOrder_ShouldReturnPayment()
.With(p => p.Status, PaymentStatus.Pending)
.Create();

_orderRepository.Setup(o => o.GetAsync(It.IsAny<Guid>()))
_getOrderDetailsUseCase.Setup(o => o.Execute(It.IsAny<Guid>()))
.ReturnsAsync(order);
_paymentGatewayMock.Setup(ps => ps.CreatePaymentAsync(It.IsAny<Order>()))
.ReturnsAsync(expectedPayment);
Expand All @@ -56,7 +59,7 @@ public async Task Execute_ValidOrder_ShouldReturnPayment()
public async Task Execute_OrderNotFound_ShouldThrowDomainException()
{
// Arrange
_orderRepository.Setup(o => o.GetAsync(It.IsAny<Guid>()))
_getOrderDetailsUseCase.Setup(o => o.Execute(It.IsAny<Guid>()))
.ReturnsAsync((Order?)default);

// Act
Expand All @@ -74,7 +77,7 @@ await func.Should()
public async Task Execute_OrderAlreadyHasPayment_ShouldThrowDomainException()
{
// Arrange
_orderRepository.Setup(o => o.GetAsync(It.IsAny<Guid>()))
_getOrderDetailsUseCase.Setup(o => o.Execute(It.IsAny<Guid>()))
.ReturnsAsync(new Order
{
PaymentId = new PaymentId(Guid.NewGuid())
Expand Down
Loading