package com.braintree.converters.populators.configuration;

import com.braintree.enums.BraintreePaymentMethodLimit;
import com.braintree.enums.BraintreePaymentMethodLimitData;
import com.braintree.hybris.data.BraintreeGooglePayConfigurationData;
import de.hybris.bootstrap.annotations.UnitTest;
import de.hybris.platform.core.model.BraintreeGooglePayConfigurationModel;
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 BraintreeGooglePayConfigurationPopulatorTest {

    private static final String MERCHANT_ID = "merchant_id";
    private static final String SELLER_COUNTRY = "seller_country";

    @Mock
    private BraintreeGooglePayConfigurationModel model;
    @InjectMocks
    private BraintreeGooglePayConfigurationPopulator unit;

    @Test
    public void shouldPopulateGooglePayConfiguration() {
        BraintreeGooglePayConfigurationData data = new BraintreeGooglePayConfigurationData();

        when(model.isEnabled()).thenReturn(true);
        when(model.isExpressCheckout()).thenReturn(true);
        when(model.getMerchantId()).thenReturn(MERCHANT_ID);
        when(model.getSellerCountryCode()).thenReturn(SELLER_COUNTRY);
        when(model.getSavedGooglePayAccountLimit()).thenReturn(BraintreePaymentMethodLimit.ONE);

        unit.populate(model, data);

        assertTrue(data.isEnabled());
        assertTrue(data.isExpressCheckout());
        assertEquals(MERCHANT_ID, data.getMerchantId());
        assertEquals(SELLER_COUNTRY, data.getSellerCountryCode());
        assertEquals(BraintreePaymentMethodLimitData.ONE, data.getSavedGooglePayAccountLimit());
    }

    @Test
    public void shouldPopulateExpressCheckoutFalseIfEnabledFalse() {
        BraintreeGooglePayConfigurationData data = new BraintreeGooglePayConfigurationData();

        when(model.isEnabled()).thenReturn(false);
        when(model.getMerchantId()).thenReturn(MERCHANT_ID);
        when(model.getSellerCountryCode()).thenReturn(SELLER_COUNTRY);
        when(model.getSavedGooglePayAccountLimit()).thenReturn(BraintreePaymentMethodLimit.ONE);

        unit.populate(model, data);

        assertFalse(data.isEnabled());
        assertFalse(data.isExpressCheckout());
        assertEquals(MERCHANT_ID, data.getMerchantId());
        assertEquals(SELLER_COUNTRY, data.getSellerCountryCode());
        assertEquals(BraintreePaymentMethodLimitData.ONE, data.getSavedGooglePayAccountLimit());
    }
}