package com.cf.imes.module.system.dal.redis.listener;

import com.cf.imes.framework.security.core.service.SecurityFrameworkService;
import org.junit.jupiter.api.Test;
import org.springframework.data.redis.connection.DefaultMessage;
import org.springframework.data.redis.connection.Message;

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;

/**
 * {@link SystemPermissionRefreshRedisListener} 的单元测试
 *
 * @author Gqr
 * @since 2025/12/15 10:23
 */
class SystemPermissionRefreshRedisListenerTest {
    @Test
    void onMessage_shouldInvalidateAllPermissionsCache() {
        // given
        SecurityFrameworkService securityFrameworkService = mock(SecurityFrameworkService.class);
        SystemPermissionRefreshRedisListener listener =
                new SystemPermissionRefreshRedisListener(securityFrameworkService);

        Message message = new DefaultMessage(
                "test".getBytes(),
                "test-channel".getBytes()
        );

        // when
        listener.onMessage(message, null);

        // then
        verify(securityFrameworkService, times(1)).invalidateAllPermissionsCache();
    }
}
