package com.yimeng.okr.event;

import com.yimeng.okr.entity.Notification;
import com.yimeng.okr.mapper.NotificationMapper;
import org.junit.jupiter.api.Test;
import org.springframework.dao.TransientDataAccessResourceException;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;

class NotificationEventListenerTest {

    @Test
    void retriesTransientSqliteWriteLock() {
        NotificationMapper mapper = mock(NotificationMapper.class);
        when(mapper.insert(any(Notification.class)))
                .thenThrow(new TransientDataAccessResourceException("SQLITE_LOCKED_SHAREDCACHE"))
                .thenReturn(1);

        NotificationEventListener listener = new NotificationEventListener(mapper);

        listener.handleNotification(new NotificationEvent(
                this, 7L, "SCORE_CONFIRM", "绩效结果已发布",
                "请查看并确认", "score", 12L));

        verify(mapper, times(2)).insert(any(Notification.class));
    }
}
