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

import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import com.ruoyi.web.modules.news.domain.FarmingNewsQuery;

@DisplayName("养殖资讯查询参数规范化")
class FarmingNewsQuerySupportTest
{
    @Test
    @DisplayName("分页默认值")
    void pageDefaults()
    {
        FarmingNewsQuery q = FarmingNewsQuerySupport.normalize(new FarmingNewsQuery());
        assertEquals(FarmingNewsRules.DEFAULT_PAGE_NUM, q.getPageNum());
        assertEquals(FarmingNewsRules.DEFAULT_PAGE_SIZE, q.getPageSize());
    }

    @Test
    @DisplayName("pageSize 上限 50")
    void pageSizeCap()
    {
        FarmingNewsQuery q = new FarmingNewsQuery();
        q.setPageSize(200);
        FarmingNewsQuery normalized = FarmingNewsQuerySupport.normalize(q);
        assertEquals(FarmingNewsRules.MAX_PAGE_SIZE, normalized.getPageSize());
    }

    @Test
    @DisplayName("非法页码回退默认")
    void invalidPageNum()
    {
        FarmingNewsQuery q = new FarmingNewsQuery();
        q.setPageNum(0);
        q.setPageSize(-1);
        FarmingNewsQuery normalized = FarmingNewsQuerySupport.normalize(q);
        assertEquals(FarmingNewsRules.DEFAULT_PAGE_NUM, normalized.getPageNum());
        assertEquals(FarmingNewsRules.DEFAULT_PAGE_SIZE, normalized.getPageSize());
    }
}
