package com.gxwebsoft.shop;

import com.gxwebsoft.shop.service.ShopOrderService;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;

import javax.annotation.Resource;
import java.math.BigDecimal;

import static org.junit.jupiter.api.Assertions.*;

/**
 * 订单总金额统计测试
 *
 * @author 科技小王子
 * @since 2025-07-30
 */
@SpringBootTest
@ActiveProfiles("test")
public class OrderTotalTest {

    @Resource
    private ShopOrderService shopOrderService;

    @Test
    void testOrderTotal() {
        // 测试订单总金额统计
        BigDecimal total = shopOrderService.total();
        
        // 验证返回值不为null
        assertNotNull(total, "订单总金额不应该为null");
        
        // 验证返回值大于等于0
        assertTrue(total.compareTo(BigDecimal.ZERO) >= 0, "订单总金额应该大于等于0");
        
        System.out.println("订单总金额统计结果：" + total);
    }

    @Test
    void testOrderTotalPerformance() {
        // 测试性能
        long startTime = System.currentTimeMillis();
        
        BigDecimal total = shopOrderService.total();
        
        long endTime = System.currentTimeMillis();
        long duration = endTime - startTime;
        
        System.out.println("订单总金额统计耗时：" + duration + "ms");
        System.out.println("统计结果：" + total);
        
        // 验证查询时间在合理范围内（小于5秒）
        assertTrue(duration < 5000, "查询时间应该在5秒以内");
    }
}
