package com.braintree.actions.order;

import de.hybris.bootstrap.annotations.UnitTest;
import de.hybris.platform.core.enums.OrderStatus;
import de.hybris.platform.core.model.order.OrderModel;
import de.hybris.platform.orderprocessing.model.OrderProcessModel;
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.runners.MockitoJUnitRunner;

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

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

    @Mock
    private ModelService modelService;

    @InjectMocks
    private BrainTreeReserveOrderAmountAction unit;

    @Mock
    private OrderProcessModel process;

    @Mock
    private OrderModel order;

    @Test
    public void shouldSetPaymentAmountReversedOrderStatus() {
        //given
        when(process.getOrder()).thenReturn(order);

        //when
        AbstractSimpleDecisionAction.Transition executedAction = unit.executeAction(process);

        //then
        assertEquals(AbstractSimpleDecisionAction.Transition.OK, executedAction);
        verify(order).setStatus(OrderStatus.PAYMENT_AMOUNT_RESERVED);
        verify(modelService).save(order);
    }

}
