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

@UnitTest
@RunWith(MockitoJUnitRunner.class)
public class BraintreeApplePayConfigurationLogicHandlerTest {
    private static final String APPLE_PAY_CONFIGURATION_DISABLED = "applePayConfigurationDisabled";
    @Mock
    private NotificationService notificationService;
    @Mock
    private ObjectFacade objectFacade;
    @Mock
    private WidgetInstanceManager widgetInstanceManager;
    @Mock
    private BraintreeApplePayConfigurationModel braintreeApplePayConfigurationModel;
    @InjectMocks
    private BraintreeApplePayConfigurationLogicHandler unit;
    @Test
    public void shouldPerformSaveWhenApplePayIsDisabled() throws Exception{
        when(braintreeApplePayConfigurationModel.isEnabled()).thenReturn(false);
        unit.performSave(widgetInstanceManager,braintreeApplePayConfigurationModel);
        verify(notificationService).notifyUser(widgetInstanceManager, APPLE_PAY_CONFIGURATION_DISABLED,
                NotificationEvent.Level.INFO);
    }

    @Test
    public void shouldntPerformSaveWhenApplePayIsEnable() throws Exception{
        when(braintreeApplePayConfigurationModel.isEnabled()).thenReturn(true);
        unit.performSave(widgetInstanceManager,braintreeApplePayConfigurationModel);
        verify(notificationService, never()).notifyUser(widgetInstanceManager, APPLE_PAY_CONFIGURATION_DISABLED,
                NotificationEvent.Level.INFO);
    }

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

    @Test
    public void shouldntBeforeEditorAreaWhenApplePayIsEnabled(){
        when(braintreeApplePayConfigurationModel.isEnabled()).thenReturn(true);
        unit.beforeEditorAreaRender(widgetInstanceManager,braintreeApplePayConfigurationModel);
        verify(notificationService, never()).notifyUser(widgetInstanceManager, APPLE_PAY_CONFIGURATION_DISABLED,
                NotificationEvent.Level.WARNING);
    }

}
