package com.ruoyi.web.modules.category.controller;

import static org.mockito.Mockito.when;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import java.util.Collections;
import org.junit.jupiter.api.BeforeEach;
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 org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import com.ruoyi.web.modules.category.service.IPlatformCategoryService;
import com.ruoyi.web.modules.category.vo.CategoryLevel2OptionVO;

@ExtendWith(MockitoExtension.class)
class SellerPlatformCategoryControllerTest
{
    @Mock
    private IPlatformCategoryService platformCategoryService;

    @InjectMocks
    private SellerPlatformCategoryController controller;

    private MockMvc mockMvc;

    @BeforeEach
    void setUp()
    {
        mockMvc = MockMvcBuilders.standaloneSetup(controller).build();
    }

    @Test
    void platformLevel2Options_returnsPlatformCategories() throws Exception
    {
        when(platformCategoryService.selectPlatformLevel2Options())
                .thenReturn(Collections.singletonList(new CategoryLevel2OptionVO(1002L, "肥料 > 复合肥", "复合肥")));

        mockMvc.perform(get("/agri/seller/category/platformLevel2Options"))
                .andExpect(status().isOk())
                .andExpect(jsonPath("$.code").value(200))
                .andExpect(jsonPath("$.data[0].label").value("肥料 > 复合肥"));
    }
}
