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.BraintreeConnectWithPayPalConfigurationModel;
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.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

@UnitTest
@RunWith(MockitoJUnitRunner.class)
public class BraintreeConnectWithPayPalConfigurationLogicHandlerTest {
    private static final String PAY_PAL_CONFIGURATION_DISABLED = "connectWithPayPalConfigurationDisabled";
    @Mock
    private NotificationService notificationService;
    @Mock
    private ObjectFacade objectFacade;
    @Mock
    private WidgetInstanceManager widgetInstanceManager;
    @Mock
    private BraintreeConnectWithPayPalConfigurationModel braintreeConnectWithPayPalConfigurationModel;
    @InjectMocks
    private BraintreeConnectWithPayPalConfigurationLogicHandler unit;
    @Test
    public void shouldPerformSaveWhenConnectWithPayPalIsDisabled() throws Exception{
        when(braintreeConnectWithPayPalConfigurationModel.isEnable()).thenReturn(false);
        unit.performSave(widgetInstanceManager,braintreeConnectWithPayPalConfigurationModel);
        verify(notificationService).notifyUser(widgetInstanceManager, PAY_PAL_CONFIGURATION_DISABLED,
                NotificationEvent.Level.INFO);
    }

    @Test
    public void shouldntPerformSaveWhenConnectWithPayPalIsEnabled() throws Exception{
        when(braintreeConnectWithPayPalConfigurationModel.isEnable()).thenReturn(true);
        unit.performSave(widgetInstanceManager,braintreeConnectWithPayPalConfigurationModel);
        verify(notificationService, never()).notifyUser(widgetInstanceManager, PAY_PAL_CONFIGURATION_DISABLED,
                NotificationEvent.Level.INFO);
    }

    @Test
    public void shouldBeforeEditorAreaWhenApplePayIsDisabled(){
        when(braintreeConnectWithPayPalConfigurationModel.isEnable()).thenReturn(false);
        unit.beforeEditorAreaRender(widgetInstanceManager,braintreeConnectWithPayPalConfigurationModel);
        verify(notificationService).notifyUser(widgetInstanceManager, PAY_PAL_CONFIGURATION_DISABLED,
                NotificationEvent.Level.WARNING);
    }

    @Test
    public void shouldntBeforeEditorAreaWhenApplePayIsEnable(){
        when(braintreeConnectWithPayPalConfigurationModel.isEnable()).thenReturn(true);
        unit.beforeEditorAreaRender(widgetInstanceManager,braintreeConnectWithPayPalConfigurationModel);
        verify(notificationService, never()).notifyUser(widgetInstanceManager, PAY_PAL_CONFIGURATION_DISABLED,
                NotificationEvent.Level.WARNING);
    }

}
