package com.ruoyi.web.modules.account.service;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;
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 com.ruoyi.web.modules.account.mapper.BizMemberMapper;
import com.ruoyi.web.modules.account.service.impl.MemberConsumptionServiceImpl;

@ExtendWith(MockitoExtension.class)
class MemberConsumptionServiceImplTest
{
    @Mock
    private BizMemberMapper memberMapper;

    @InjectMocks
    private MemberConsumptionServiceImpl consumptionService;

    @Test
    void refreshConsumption_updatesMember()
    {
        Map<String, Object> stats = new HashMap<>();
        stats.put("orderCount", 3);
        stats.put("totalAmount", new BigDecimal("60.00"));
        when(memberMapper.selectConsumptionFromOrder(1L)).thenReturn(stats);

        consumptionService.refreshConsumption(1L);

        verify(memberMapper).updateConsumption(eq(1L), eq(3), any(BigDecimal.class));
    }
}
