package com.ruoyi.web.modules.store.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 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.Spy;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.web.modules.store.service.ISellerShopContextService;
import com.ruoyi.web.modules.store.vo.SellerContextVO;

@ExtendWith(MockitoExtension.class)
class SellerShopContextControllerTest
{
    private static final String SESSION_TOKEN = "session-token-abc";

    @Mock
    private ISellerShopContextService sellerShopContextService;

    @Spy
    @InjectMocks
    private SellerShopContextController controller;

    private MockMvc mockMvc;

    @BeforeEach
    void setUp() throws Exception
    {
        mockMvc = MockMvcBuilders.standaloneSetup(controller).build();
        LoginUser loginUser = new LoginUser();
        loginUser.setUserId(10L);
        loginUser.setToken(SESSION_TOKEN);
        org.mockito.Mockito.lenient().doReturn(loginUser).when(controller).getLoginUser();
    }

    @Test
    void getContext_returnsCurrentShopId() throws Exception
    {
        SellerContextVO vo = new SellerContextVO();
        vo.setShopId(201L);
        vo.setShopName("一号店");
        when(sellerShopContextService.selectContext(10L, SESSION_TOKEN)).thenReturn(vo);

        mockMvc.perform(get("/agri/seller/context"))
                .andExpect(status().isOk())
                .andExpect(jsonPath("$.data.shopId").value(201));
    }
}
