package com.ruoyi.web.modules.trading.service.impl;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;

import java.util.Collections;

import com.ruoyi.web.modules.trading.domain.BizSupplierSettlement;
import com.ruoyi.web.modules.trading.domain.BizTradeOrderLine;
import com.ruoyi.web.modules.trading.mapper.AppSupplierSettlementMapper;
import com.ruoyi.web.modules.trading.mapper.BizTradeOrderLineMapper;
import com.ruoyi.web.modules.trading.support.AppSupplierSessionSupport;
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;

@ExtendWith(MockitoExtension.class)
@DisplayName("AppSupplierSettlementServiceImpl")
class AppSupplierSettlementServiceImplTest
{
    @Mock
    private AppSupplierSessionSupport appSupplierSessionSupport;

    @Mock
    private AppSupplierSettlementMapper appSupplierSettlementMapper;

    @Mock
    private BizTradeOrderLineMapper bizTradeOrderLineMapper;

    @InjectMocks
    private AppSupplierSettlementServiceImpl service;

    @Test
    @DisplayName("待结算列表含订单明细")
    void selectPendingList()
    {
        when(appSupplierSessionSupport.requireSupplierId()).thenReturn(3L);
        BizSupplierSettlement row = new BizSupplierSettlement();
        row.setId(1L);
        row.setOrderId(10L);
        row.setSettlementStatus("0");
        when(appSupplierSettlementMapper.selectPendingSettlementList(3L))
                .thenReturn(Collections.singletonList(row));
        BizTradeOrderLine line = new BizTradeOrderLine();
        line.setOrderId(10L);
        line.setEarTag("E202");
        when(bizTradeOrderLineMapper.selectLineListByOrderIds(any()))
                .thenReturn(Collections.singletonList(line));

        BizSupplierSettlement got = service.selectPendingList().get(0);
        assertEquals("待结算", got.getSettlementStatusName());
        assertEquals(1, got.getLineList().size());
        assertEquals("E202", got.getLineList().get(0).getEarTag());
    }
}
