package com.ruoyi.web.modules.trading.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.math.BigDecimal;
import java.util.Collections;

import com.github.pagehelper.Page;
import com.ruoyi.framework.web.exception.GlobalExceptionHandler;
import com.ruoyi.web.modules.trading.domain.BizSupplierSettlement;
import com.ruoyi.web.modules.trading.domain.BizTradeOrderLine;
import com.ruoyi.web.modules.trading.service.IAppSupplierSettlementService;
import org.junit.jupiter.api.DisplayName;
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;

@ExtendWith(MockitoExtension.class)
@DisplayName("供应商待结算单移动端 HTTP MockMvc")
class BizAppSupplierSettlementControllerApiTest
{
    @Mock
    private IAppSupplierSettlementService appSupplierSettlementService;

    @InjectMocks
    private BizAppSupplierSettlementController controller;

    @Test
    @DisplayName("GET /app/supplier/settlement/list")
    void list() throws Exception
    {
        MockMvc mockMvc = MockMvcBuilders.standaloneSetup(controller)
                .setControllerAdvice(new GlobalExceptionHandler())
                .build();

        BizSupplierSettlement row = new BizSupplierSettlement();
        row.setId(2L);
        row.setSettlementNo("JSD20260526001");
        row.setOrderNo("20260526001");
        row.setPayableAmount(new BigDecimal("36500"));
        BizTradeOrderLine line = new BizTradeOrderLine();
        line.setEarTag("E301");
        row.setLineList(Collections.singletonList(line));

        Page<BizSupplierSettlement> page = new Page<>();
        page.add(row);
        when(appSupplierSettlementService.selectPendingList()).thenReturn(page);

        mockMvc.perform(get("/app/supplier/settlement/list"))
                .andExpect(status().isOk())
                .andExpect(jsonPath("$.code").value(200))
                .andExpect(jsonPath("$.rows[0].settlementNo").value("JSD20260526001"))
                .andExpect(jsonPath("$.rows[0].lineList[0].earTag").value("E301"));
    }
}
