package com.mosquito.project.permission;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;

import java.util.Collections;

import static org.mockito.Mockito.*;

/**
 * 审批超时任务单元测试
 */
@ExtendWith(MockitoExtension.class)
class ApprovalTimeoutJobTest {

    @Mock
    private ApprovalRecordRepository recordRepository;

    @Mock
    private ApprovalFlowRepository flowRepository;

    @Mock
    private ApprovalFlowService approvalFlowService;

    @InjectMocks
    private ApprovalTimeoutJob approvalTimeoutJob;

    /**
     * 测试审批超时检测 - 无处理中的记录
     */
    @Test
    void testCheckApprovalTimeout_NoProcessingRecords() {
        when(recordRepository.findByStatus("PROCESSING"))
            .thenReturn(Collections.emptyList());

        approvalTimeoutJob.checkApprovalTimeout();

        verify(recordRepository).findByStatus("PROCESSING");
    }

    /**
     * 测试手动触发超时检测
     */
    @Test
    void testManualCheckTimeout() {
        when(recordRepository.findByStatus("PROCESSING"))
            .thenReturn(Collections.emptyList());

        approvalTimeoutJob.manualCheckTimeout();

        verify(recordRepository).findByStatus("PROCESSING");
    }
}
