package com.braintree.converters.populators.configuration;

import com.braintree.enums.BraintreeIntent;
import com.braintree.enums.BraintreePaymentMethodLimit;
import com.braintree.enums.BraintreePaymentMethodLimitData;
import com.braintree.hybris.data.BraintreePayPalConfigurationData;
import de.hybris.bootstrap.annotations.UnitTest;
import de.hybris.platform.core.model.BraintreePayPalConfigurationModel;
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.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.when;

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

    private static final String INTENT = "sale";
    private static final String BILLING_AGREEMENT_TEXT = "Billing Agreement text";

    @Mock
    private BraintreePayPalConfigurationModel model;
    @InjectMocks
    private BraintreePayPalConfigurationPopulator unit;

    @Test
    public void shouldPopulatePayPalConfiguration() {
        BraintreePayPalConfigurationData data = new BraintreePayPalConfigurationData();

        when(model.isPayPalEnabled()).thenReturn(true);
        when(model.isExpressCheckout()).thenReturn(true);
        when(model.isPayLater()).thenReturn(true);
        when(model.isPayLaterForNonUsCountries()).thenReturn(true);
        when(model.isChangePaymentMethodButton()).thenReturn(true);
        when(model.isCreditMessagesEnabled()).thenReturn(true);
        when(model.getIntent()).thenReturn(BraintreeIntent.SALE);
        when(model.getBillingAgreementText()).thenReturn(BILLING_AGREEMENT_TEXT);
        when(model.getSavedPayPalAccountLimit()).thenReturn(BraintreePaymentMethodLimit.ONE);

        unit.populate(model, data);

        assertTrue(data.isPayPalEnabled());
        assertTrue(data.isExpressCheckout());
        assertTrue(data.isPayLater());
        assertTrue(data.isPayLaterForNonUsCountries());
        assertTrue(data.isChangePaymentMethodButton());
        assertTrue(data.isCreditMessagesEnabled());
        assertEquals(INTENT, data.getIntent());
        assertEquals(BILLING_AGREEMENT_TEXT, data.getBillingAgreementText());
        assertEquals(BraintreePaymentMethodLimitData.ONE, data.getSavedPayPalAccountLimit());
    }

    @Test
    public void shouldPopulateExpressChekoutFalseifEnableFalse() {
        BraintreePayPalConfigurationData data = new BraintreePayPalConfigurationData();

        when(model.isPayPalEnabled()).thenReturn(false);
        when(model.isPayLater()).thenReturn(true);
        when(model.isPayLaterForNonUsCountries()).thenReturn(true);
        when(model.isChangePaymentMethodButton()).thenReturn(true);
        when(model.isCreditMessagesEnabled()).thenReturn(true);
        when(model.getIntent()).thenReturn(BraintreeIntent.SALE);
        when(model.getBillingAgreementText()).thenReturn(BILLING_AGREEMENT_TEXT);
        when(model.getSavedPayPalAccountLimit()).thenReturn(BraintreePaymentMethodLimit.ONE);

        unit.populate(model, data);

        assertFalse(data.isPayPalEnabled());
        assertFalse(data.isExpressCheckout());
        assertTrue(data.isPayLater());
        assertTrue(data.isPayLaterForNonUsCountries());
        assertTrue(data.isChangePaymentMethodButton());
        assertTrue(data.isCreditMessagesEnabled());
        assertEquals(INTENT, data.getIntent());
        assertEquals(BILLING_AGREEMENT_TEXT, data.getBillingAgreementText());
        assertEquals(BraintreePaymentMethodLimitData.ONE, data.getSavedPayPalAccountLimit());
    }
}