package com.cloudhandson.ddsbackoffice.service;

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

import com.cloudhandson.vpdbackoffice.service.DdsAuthorizationChangeNotifier;
import com.cloudhandson.vpdbackoffice.service.DdsAuthorizationSynchronizer;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;

class DdsMcpAuthorizationChangeListenerTest {

  @Test
  void bridgesACommittedAuthorizationChangeToOneBulkMcpPublish() {
    DdsMcpEndUserPublisher publisher = org.mockito.Mockito.mock(DdsMcpEndUserPublisher.class);
    when(publisher.publish()).thenReturn(new com.cloudhandson.ddsbackoffice.domain.DdsMcpEndUserPublishResult(3, 0, 0));
    DdsMcpAuthorizationChangeListener listener = new DdsMcpAuthorizationChangeListener(publisher);
    DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
    factory.registerSingleton("ddsSynchronizer", (DdsAuthorizationSynchronizer) listener);

    new DdsAuthorizationChangeNotifier(factory.getBeanProvider(DdsAuthorizationSynchronizer.class))
        .changed("PERMISSION_SAVED");

    verify(publisher).publish();
  }
}
