package com.braintree.customersupportbackoffice.handler;

import com.hybris.cockpitng.dataaccess.facades.object.ObjectFacade;
import com.hybris.cockpitng.engine.WidgetInstanceManager;
import com.hybris.cockpitng.util.notifications.NotificationService;
import com.hybris.cockpitng.util.notifications.event.NotificationEvent;
import de.hybris.bootstrap.annotations.UnitTest;
import de.hybris.platform.core.model.BraintreeGeneralConfigurationModel;
import de.hybris.platform.core.model.BraintreeGooglePayConfigurationModel;
import de.hybris.platform.core.model.BraintreePluginConfigurationModel;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.runners.MockitoJUnitRunner;

import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

@UnitTest
@RunWith(MockitoJUnitRunner.class)
public class BraintreeGooglePayConfigurationLogicHandlerTest {
    private static final String GOOGLE_PAY_CONFIGURATION_DISABLED = "googlePayConfigurationDisabled";
    private static final String GOOGLE_PAY_ACCOUNT_LIMITATION_DISABLED = "googlePayAccountLimitationDisabled";
    @Mock
    private NotificationService notificationService;
    @Mock
    private ObjectFacade objectFacade;
    @Mock
    private WidgetInstanceManager widgetInstanceManager;
    @Mock
    private BraintreeGooglePayConfigurationModel braintreeGooglePayConfigurationModel;
    @Mock
    private BraintreeGeneralConfigurationModel generalConfigurationModel;
    @Mock
    private BraintreePluginConfigurationModel pluginConfigurationModel;
    @InjectMocks
    private BraintreeGooglePayConfigurationLogicHandler unit;
    @Test
    public void shouldPerformSaveWhenGooglePayIsDisabled() throws Exception{
        when(braintreeGooglePayConfigurationModel.isEnabled()).thenReturn(false);
        unit.performSave(widgetInstanceManager,braintreeGooglePayConfigurationModel);
        verify(notificationService).notifyUser(widgetInstanceManager, GOOGLE_PAY_CONFIGURATION_DISABLED,
                NotificationEvent.Level.INFO);
    }

    @Test
    public void shouldBeforeEditorAreaRenderWhenGooglePayIsDisabled(){
        when(braintreeGooglePayConfigurationModel.isEnabled()).thenReturn(false);
        when(braintreeGooglePayConfigurationModel.getPluginConfiguration()).thenReturn(pluginConfigurationModel);
        when(pluginConfigurationModel.getBraintreeGeneralConfiguration()).thenReturn(generalConfigurationModel);
        unit.beforeEditorAreaRender(widgetInstanceManager,braintreeGooglePayConfigurationModel);
        verify(notificationService).notifyUser(widgetInstanceManager, GOOGLE_PAY_CONFIGURATION_DISABLED,
                NotificationEvent.Level.WARNING);
    }

    @Test
    public void shouldBeforeEditorAreaRenderWhenDropInIsEnabled(){
        when(braintreeGooglePayConfigurationModel.getPluginConfiguration()).thenReturn(pluginConfigurationModel);
        when(pluginConfigurationModel.getBraintreeGeneralConfiguration()).thenReturn(generalConfigurationModel);
        when(generalConfigurationModel.isDropIn()).thenReturn(true);
        unit.beforeEditorAreaRender(widgetInstanceManager,braintreeGooglePayConfigurationModel);
        verify(notificationService).notifyUser(widgetInstanceManager, GOOGLE_PAY_ACCOUNT_LIMITATION_DISABLED,
                NotificationEvent.Level.WARNING);
    }

}
