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.BraintreeVenmoConfigurationModel;
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 BraintreeVenmoConfigurationLogicHandlerTest {
    private static final String VENMO_CONFIGURATION_DISABLED = "venmoConfigurationDisabled";
    private static final String VENMO_ACCOUNT_LIMITATION_DISABLED = "venmoAccountLimitationDisabled";
    @Mock
    private NotificationService notificationService;
    @Mock
    private ObjectFacade objectFacade;
    @Mock
    private WidgetInstanceManager widgetInstanceManager;
    @Mock
    private BraintreeVenmoConfigurationModel braintreeVenmoConfigurationModel;
    @Mock
    private BraintreeGeneralConfigurationModel generalConfigurationModel;
    @Mock
    private BraintreePluginConfigurationModel pluginConfigurationModel;
    @InjectMocks
    private BraintreeVenmoConfigurationLogicHandler unit;
    @Test
    public void shouldPerformSaveWhenVenmoIsDisabled() throws Exception{
        when(braintreeVenmoConfigurationModel.isEnabled()).thenReturn(false);
        unit.performSave(widgetInstanceManager,braintreeVenmoConfigurationModel);
        verify(notificationService).notifyUser(widgetInstanceManager, VENMO_CONFIGURATION_DISABLED,
                NotificationEvent.Level.INFO);
    }

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

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

}
