package com.braintree.actions.order;

import de.hybris.bootstrap.annotations.UnitTest;
import de.hybris.platform.orderprocessing.model.OrderProcessModel;
import de.hybris.platform.ordersplitting.model.ConsignmentProcessModel;
import de.hybris.platform.processengine.action.AbstractSimpleDecisionAction;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;

import java.util.List;

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

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

    @InjectMocks
    private BrainTreeSubprocessesCompletedAction unit;

    @Mock
    private OrderProcessModel process;

    @Mock
    private ConsignmentProcessModel consignmentProcessModel;

    @Test
    public void shouldReturnTransitionOkIfSubprocessesCompleted() {
        //given
        when(process.getConsignmentProcesses()).thenReturn(List.of(consignmentProcessModel));
        when(consignmentProcessModel.isDone()).thenReturn(true);

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

        //then
        assertEquals(AbstractSimpleDecisionAction.Transition.OK, transition);
    }

    @Test
    public void shouldReturnTransitionNOkIfSubprocessesNotCompleted() {
        //given
        when(process.getConsignmentProcesses()).thenReturn(List.of(consignmentProcessModel));

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

        //then
        assertEquals(AbstractSimpleDecisionAction.Transition.NOK, transition);
    }

    @Test
    public void shouldReturnTransitionOkIfSubprocessesAreEmpty() {
        //when
        AbstractSimpleDecisionAction.Transition transition = unit.executeAction(process);

        //then
        assertEquals(AbstractSimpleDecisionAction.Transition.OK, transition);
    }

}
