package com.braintree.actions;

import com.braintree.model.BrainTreePaymentInfoModel;
import de.hybris.bootstrap.annotations.UnitTest;
import de.hybris.platform.b2b.process.approval.model.B2BApprovalProcessModel;
import de.hybris.platform.core.model.order.OrderModel;
import de.hybris.platform.core.model.order.payment.PaymentInfoModel;
import de.hybris.platform.processengine.action.AbstractSimpleDecisionAction;
import de.hybris.platform.servicelayer.model.ModelService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Spy;
import org.mockito.runners.MockitoJUnitRunner;

import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.atLeast;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

@UnitTest
@RunWith(MockitoJUnitRunner.class)
public class BrainTreeBookingLineEntriesTest {

    @Mock
    private B2BApprovalProcessModel b2BApprovalProcessModel;
    @Mock
    private OrderModel orderModel;
    @Mock
    private PaymentInfoModel paymentInfoModel;
    @Mock
    private BrainTreePaymentInfoModel brainTreePaymentInfoModel;
    @Mock
    private ModelService modelService;

    @InjectMocks
    @Spy
    private BrainTreeBookingLineEntries unit;

    @Test
    public void executeBrainTreeBookingLineEntriesAction(){
        when(b2BApprovalProcessModel.getOrder()).thenReturn(orderModel);
        when(orderModel.getPaymentInfo()).thenReturn(paymentInfoModel);

        unit.executeAction(b2BApprovalProcessModel);

        verify(modelService, atLeast(1)).refresh(orderModel);
    }

    @Test
    public void executeBrainTreeBookingLineEntriesActionWhenBraintreePayment(){
        when(b2BApprovalProcessModel.getOrder()).thenReturn(orderModel);
        when(orderModel.getPaymentInfo()).thenReturn(brainTreePaymentInfoModel);

        AbstractSimpleDecisionAction.Transition result = unit.executeAction(b2BApprovalProcessModel);

        verify(modelService).refresh(orderModel);
        assertEquals(AbstractSimpleDecisionAction.Transition.OK, result);
    }
}
