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.BraintreeACHConfigurationModel;
import de.hybris.platform.core.model.BraintreeGeneralConfigurationModel;
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.runners.MockitoJUnitRunner;

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

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

    private static final String ACH_ACCOUNT_LIMITATION_DISABLED = "achAccountLimitationDisabled";
    private static final String ACH_CONFIGURATION_DISABLED = "achConfigurationDisabled";
    @Mock
    private NotificationService notificationService;
    @Mock
    private ObjectFacade objectFacade;
    @Mock
    private WidgetInstanceManager widgetInstanceManager;
    @Mock
    private BraintreeACHConfigurationModel mockedBraintreeACHConfigurationModel;
    @Mock
    private BraintreeGeneralConfigurationModel generalConfigurationModel;
    @Mock
    private BraintreePluginConfigurationModel pluginConfigurationModel;
    @InjectMocks
    private BraintreeACHConfigurationLogicHandler unit;
    @Test
    public void shouldPerformSaveWhenAchIsDisabled() throws Exception{
       when(mockedBraintreeACHConfigurationModel.isEnabled()).thenReturn(false);
        unit.performSave(widgetInstanceManager,mockedBraintreeACHConfigurationModel);
        verify(notificationService).notifyUser(widgetInstanceManager, ACH_CONFIGURATION_DISABLED,
                NotificationEvent.Level.INFO);
    }

    @Test
    public void shouldBeforeEditorAreaRenderWhenAchIsDisabled(){
        when(mockedBraintreeACHConfigurationModel.isEnabled()).thenReturn(false);
        when(mockedBraintreeACHConfigurationModel.getPluginConfiguration()).thenReturn(pluginConfigurationModel);
        when(pluginConfigurationModel.getBraintreeGeneralConfiguration()).thenReturn(generalConfigurationModel);
        unit.beforeEditorAreaRender(widgetInstanceManager,mockedBraintreeACHConfigurationModel);
        verify(notificationService).notifyUser(widgetInstanceManager, ACH_CONFIGURATION_DISABLED,
                NotificationEvent.Level.WARNING);

    }

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

}
