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.BraintreePluginConfigurationModel;
import de.hybris.platform.core.model.BraintreeSRCConfigurationModel;
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 BraintreeSRCConfigurationLogicHandlerTest {
    private static final String SRC_CONFIGURATION_DISABLED = "srcConfigurationDisabled";
    private static final String SRC_ACCOUNT_LIMITATION_DISABLED = "srcAccountLimitationDisabled";
    @Mock
    private NotificationService notificationService;
    @Mock
    private ObjectFacade objectFacade;
    @Mock
    private WidgetInstanceManager widgetInstanceManager;
    @Mock
    private BraintreeSRCConfigurationModel braintreeSRCConfigurationModel;
    @Mock
    private BraintreeGeneralConfigurationModel generalConfigurationModel;
    @Mock
    private BraintreePluginConfigurationModel pluginConfigurationModel;
    @InjectMocks
    private BraintreeSRCConfigurationLogicHandler unit;
    @Test
    public void shouldPerformSaveWhenSrcIsDisabled() throws Exception{
        when(braintreeSRCConfigurationModel.isEnabled()).thenReturn(false);
        unit.performSave(widgetInstanceManager,braintreeSRCConfigurationModel);
        verify(notificationService).notifyUser(widgetInstanceManager, SRC_CONFIGURATION_DISABLED,
                NotificationEvent.Level.INFO);
    }

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

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

}
