package com.ruoyi.web.modules.industryservice.support;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.Date;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

@DisplayName("IotSyncSupport")
class IotSyncSupportTest
{
    @Test
    @DisplayName("空表返回全量查询参数")
    void resolveSyncQuery_emptyTable()
    {
        IotSyncSupport.SyncQuery query = IotSyncSupport.resolveSyncQuery(
                0L, null, new Date(), new Date(9_999_999_999_999L));

        assertTrue(query.isFullSync());
        assertNull(query.getStartTime());
        assertNull(query.getEndTime());
        assertNull(query.getUpdatedAfter());
    }

    @Test
    @DisplayName("有数据返回增量查询参数")
    void resolveSyncQuery_incremental()
    {
        Date end = new Date(10_000_000L);
        Date max = new Date(9_000_000L);
        Date watermark = new Date(8_000_000L);
        IotSyncSupport.SyncQuery query = IotSyncSupport.resolveSyncQuery(5L, max, end, watermark);

        assertFalse(query.isFullSync());
        assertTrue(query.getStartTime().before(max));
        assertTrue(end.equals(query.getEndTime()));
        assertTrue(watermark.equals(query.getUpdatedAfter()));
    }
}
