package com.braintree.helpers;

import de.hybris.bootstrap.annotations.UnitTest;
import de.hybris.platform.payment.dto.TransactionStatusDetails;
import de.hybris.platform.payment.enums.PaymentTransactionType;
import de.hybris.platform.payment.model.PaymentTransactionEntryModel;
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.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.when;

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

    @InjectMocks
    private OrderVoidHelper unit;

    @Mock
    private PaymentTransactionEntryModel entry;

    @Test
    public void shouldReturnTrueIfSuccessfulPartialCaptureTransaction() {
        //given
        when(entry.getType()).thenReturn(PaymentTransactionType.PARTIAL_CAPTURE);
        when(entry.getTransactionStatusDetails()).thenReturn(TransactionStatusDetails.SUCCESFULL.name());

        //when
        boolean result = unit.isSuccessfulCaptureTransaction(entry);

        //then
        assertTrue(result);

    }

    @Test
    public void shouldReturnTrueIfSuccessfulCaptureTransaction() {
        //given
        when(entry.getType()).thenReturn(PaymentTransactionType.CAPTURE);
        when(entry.getTransactionStatusDetails()).thenReturn(TransactionStatusDetails.SUCCESFULL.name());

        //when
        boolean result = unit.isSuccessfulCaptureTransaction(entry);

        //then
        assertTrue(result);

    }

    @Test
    public void shouldReturnFalseIfUnsuccessfulCaptureTransaction() {
        //given
        when(entry.getType()).thenReturn(PaymentTransactionType.CAPTURE);
        when(entry.getTransactionStatusDetails()).thenReturn(TransactionStatusDetails.INVALID_CARD_TYPE.name());

        //when
        boolean result = unit.isSuccessfulCaptureTransaction(entry);

        //then
        assertFalse(result);

    }

    @Test
    public void shouldReturnFalseIfUnsuccessfulPartialCaptureTransaction() {
        //given
        when(entry.getType()).thenReturn(PaymentTransactionType.PARTIAL_CAPTURE);
        when(entry.getTransactionStatusDetails()).thenReturn(TransactionStatusDetails.INVALID_CARD_TYPE.name());

        //when
        boolean result = unit.isSuccessfulCaptureTransaction(entry);

        //then
        assertFalse(result);

    }

    @Test
    public void shouldReturnFalseIfSuccessfulAuthorizationTransaction() {
        //given
        when(entry.getType()).thenReturn(PaymentTransactionType.AUTHORIZATION);

        //when
        boolean result = unit.isSuccessfulCaptureTransaction(entry);

        //then
        assertFalse(result);

    }

}
