package com.ruoyi.web.modules.category.domain.vo;

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

import java.util.Collections;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import com.fasterxml.jackson.databind.ObjectMapper;

@DisplayName("资讯类别 VO JSON 字段名")
class InformationCategoryVoJsonTest
{
    private final ObjectMapper objectMapper = new ObjectMapper();

    @Test
    @DisplayName("children 接口项序列化为 code、name")
    void itemVo_usesEnglishKeys() throws Exception
    {
        String json = objectMapper.writeValueAsString(new InformationCategoryItemVo("001001", "繁育作业"));
        assertTrue(json.contains("\"code\":\"001001\""));
        assertTrue(json.contains("\"name\":\"繁育作业\""));
        assertFalse(json.contains("编号"));
        assertFalse(json.contains("名称"));
    }

    @Test
    @DisplayName("tree 节点序列化为 code、name、children")
    void treeVo_usesEnglishKeys() throws Exception
    {
        InformationCategoryTreeVo child = new InformationCategoryTreeVo();
        child.setCode("001001");
        child.setName("繁育作业");
        child.setCategoryType("1");
        child.setModuleId("01");
        InformationCategoryTreeVo root = new InformationCategoryTreeVo();
        root.setCode("001");
        root.setName("养殖标准");
        root.setModuleId("01");
        root.setChildren(Collections.singletonList(child));

        String json = objectMapper.writeValueAsString(root);
        assertTrue(json.contains("\"code\":\"001\""));
        assertTrue(json.contains("\"name\":\"养殖标准\""));
        assertTrue(json.contains("\"children\""));
        assertTrue(json.contains("\"categoryType\":\"1\""));
        assertTrue(json.contains("\"moduleId\":\"01\""));
        assertFalse(json.contains("编号"));
        assertFalse(json.contains("名称"));
    }
}
