|  | @@ -0,0 +1,154 @@
 | 
	
		
			
				|  |  | +package cn.newfeifan.mall.module.distri.service.orderpercentage;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +import org.junit.jupiter.api.Disabled;
 | 
	
		
			
				|  |  | +import org.junit.jupiter.api.Test;
 | 
	
		
			
				|  |  | +import org.springframework.boot.test.mock.mockito.MockBean;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +import javax.annotation.Resource;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +import cn.newfeifan.mall.framework.test.core.ut.BaseDbUnitTest;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +import cn.newfeifan.mall.module.distri.controller.admin.orderpercentage.vo.*;
 | 
	
		
			
				|  |  | +import cn.newfeifan.mall.module.distri.dal.dataobject.orderpercentage.OrderPercentageDO;
 | 
	
		
			
				|  |  | +import cn.newfeifan.mall.module.distri.dal.mysql.orderpercentage.OrderPercentageMapper;
 | 
	
		
			
				|  |  | +import cn.newfeifan.mall.framework.common.pojo.PageResult;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +import javax.annotation.Resource;
 | 
	
		
			
				|  |  | +import org.springframework.context.annotation.Import;
 | 
	
		
			
				|  |  | +import java.util.*;
 | 
	
		
			
				|  |  | +import java.time.LocalDateTime;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +import static cn.hutool.core.util.RandomUtil.*;
 | 
	
		
			
				|  |  | +import static cn.newfeifan.mall.module.distri.enums.ErrorCodeConstants.*;
 | 
	
		
			
				|  |  | +import static cn.newfeifan.mall.framework.test.core.util.AssertUtils.*;
 | 
	
		
			
				|  |  | +import static cn.newfeifan.mall.framework.test.core.util.RandomUtils.*;
 | 
	
		
			
				|  |  | +import static cn.newfeifan.mall.framework.common.util.date.LocalDateTimeUtils.*;
 | 
	
		
			
				|  |  | +import static cn.newfeifan.mall.framework.common.util.object.ObjectUtils.*;
 | 
	
		
			
				|  |  | +import static cn.newfeifan.mall.framework.common.util.date.DateUtils.*;
 | 
	
		
			
				|  |  | +import static org.junit.jupiter.api.Assertions.*;
 | 
	
		
			
				|  |  | +import static org.mockito.Mockito.*;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +/**
 | 
	
		
			
				|  |  | + * {@link OrderPercentageServiceImpl} 的单元测试类
 | 
	
		
			
				|  |  | + *
 | 
	
		
			
				|  |  | + * @author 非繁人
 | 
	
		
			
				|  |  | + */
 | 
	
		
			
				|  |  | +@Import(OrderPercentageServiceImpl.class)
 | 
	
		
			
				|  |  | +public class OrderPercentageServiceImplTest extends BaseDbUnitTest {
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    @Resource
 | 
	
		
			
				|  |  | +    private OrderPercentageServiceImpl orderPercentageService;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    @Resource
 | 
	
		
			
				|  |  | +    private OrderPercentageMapper orderPercentageMapper;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    @Test
 | 
	
		
			
				|  |  | +    public void testCreateOrderPercentage_success() {
 | 
	
		
			
				|  |  | +        // 准备参数
 | 
	
		
			
				|  |  | +        OrderPercentageSaveReqVO createReqVO = randomPojo(OrderPercentageSaveReqVO.class).setId(null);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        // 调用
 | 
	
		
			
				|  |  | +        Long orderPercentageId = orderPercentageService.createOrderPercentage(createReqVO);
 | 
	
		
			
				|  |  | +        // 断言
 | 
	
		
			
				|  |  | +        assertNotNull(orderPercentageId);
 | 
	
		
			
				|  |  | +        // 校验记录的属性是否正确
 | 
	
		
			
				|  |  | +        OrderPercentageDO orderPercentage = orderPercentageMapper.selectById(orderPercentageId);
 | 
	
		
			
				|  |  | +        assertPojoEquals(createReqVO, orderPercentage, "id");
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    @Test
 | 
	
		
			
				|  |  | +    public void testUpdateOrderPercentage_success() {
 | 
	
		
			
				|  |  | +        // mock 数据
 | 
	
		
			
				|  |  | +        OrderPercentageDO dbOrderPercentage = randomPojo(OrderPercentageDO.class);
 | 
	
		
			
				|  |  | +        orderPercentageMapper.insert(dbOrderPercentage);// @Sql: 先插入出一条存在的数据
 | 
	
		
			
				|  |  | +        // 准备参数
 | 
	
		
			
				|  |  | +        OrderPercentageSaveReqVO updateReqVO = randomPojo(OrderPercentageSaveReqVO.class, o -> {
 | 
	
		
			
				|  |  | +            o.setId(dbOrderPercentage.getId()); // 设置更新的 ID
 | 
	
		
			
				|  |  | +        });
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        // 调用
 | 
	
		
			
				|  |  | +        orderPercentageService.updateOrderPercentage(updateReqVO);
 | 
	
		
			
				|  |  | +        // 校验是否更新正确
 | 
	
		
			
				|  |  | +        OrderPercentageDO orderPercentage = orderPercentageMapper.selectById(updateReqVO.getId()); // 获取最新的
 | 
	
		
			
				|  |  | +        assertPojoEquals(updateReqVO, orderPercentage);
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    @Test
 | 
	
		
			
				|  |  | +    public void testUpdateOrderPercentage_notExists() {
 | 
	
		
			
				|  |  | +        // 准备参数
 | 
	
		
			
				|  |  | +        OrderPercentageSaveReqVO updateReqVO = randomPojo(OrderPercentageSaveReqVO.class);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        // 调用, 并断言异常
 | 
	
		
			
				|  |  | +        assertServiceException(() -> orderPercentageService.updateOrderPercentage(updateReqVO), ORDER_PERCENTAGE_NOT_EXISTS);
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    @Test
 | 
	
		
			
				|  |  | +    public void testDeleteOrderPercentage_success() {
 | 
	
		
			
				|  |  | +        // mock 数据
 | 
	
		
			
				|  |  | +        OrderPercentageDO dbOrderPercentage = randomPojo(OrderPercentageDO.class);
 | 
	
		
			
				|  |  | +        orderPercentageMapper.insert(dbOrderPercentage);// @Sql: 先插入出一条存在的数据
 | 
	
		
			
				|  |  | +        // 准备参数
 | 
	
		
			
				|  |  | +        Long id = dbOrderPercentage.getId();
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        // 调用
 | 
	
		
			
				|  |  | +        orderPercentageService.deleteOrderPercentage(id);
 | 
	
		
			
				|  |  | +       // 校验数据不存在了
 | 
	
		
			
				|  |  | +       assertNull(orderPercentageMapper.selectById(id));
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    @Test
 | 
	
		
			
				|  |  | +    public void testDeleteOrderPercentage_notExists() {
 | 
	
		
			
				|  |  | +        // 准备参数
 | 
	
		
			
				|  |  | +        Long id = randomLongId();
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        // 调用, 并断言异常
 | 
	
		
			
				|  |  | +        assertServiceException(() -> orderPercentageService.deleteOrderPercentage(id), ORDER_PERCENTAGE_NOT_EXISTS);
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    @Test
 | 
	
		
			
				|  |  | +    @Disabled  // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
 | 
	
		
			
				|  |  | +    public void testGetOrderPercentagePage() {
 | 
	
		
			
				|  |  | +       // mock 数据
 | 
	
		
			
				|  |  | +       OrderPercentageDO dbOrderPercentage = randomPojo(OrderPercentageDO.class, o -> { // 等会查询到
 | 
	
		
			
				|  |  | +           o.setGrossProfitPerc(null);
 | 
	
		
			
				|  |  | +           o.setGrossProfitUserQuotaPerc(null);
 | 
	
		
			
				|  |  | +           o.setGrossProfitAncestorQuotaPerc(null);
 | 
	
		
			
				|  |  | +           o.setGrossProfitBonusQuotaPerc(null);
 | 
	
		
			
				|  |  | +           o.setGrossProfitPlatformQuotaPerc(null);
 | 
	
		
			
				|  |  | +           o.setDivideIntoPerc(null);
 | 
	
		
			
				|  |  | +           o.setCreateTime(null);
 | 
	
		
			
				|  |  | +       });
 | 
	
		
			
				|  |  | +       orderPercentageMapper.insert(dbOrderPercentage);
 | 
	
		
			
				|  |  | +       // 测试 grossProfitPerc 不匹配
 | 
	
		
			
				|  |  | +       orderPercentageMapper.insert(cloneIgnoreId(dbOrderPercentage, o -> o.setGrossProfitPerc(null)));
 | 
	
		
			
				|  |  | +       // 测试 grossProfitUserQuotaPerc 不匹配
 | 
	
		
			
				|  |  | +       orderPercentageMapper.insert(cloneIgnoreId(dbOrderPercentage, o -> o.setGrossProfitUserQuotaPerc(null)));
 | 
	
		
			
				|  |  | +       // 测试 grossProfitAncestorQuotaPerc 不匹配
 | 
	
		
			
				|  |  | +       orderPercentageMapper.insert(cloneIgnoreId(dbOrderPercentage, o -> o.setGrossProfitAncestorQuotaPerc(null)));
 | 
	
		
			
				|  |  | +       // 测试 grossProfitBonusQuotaPerc 不匹配
 | 
	
		
			
				|  |  | +       orderPercentageMapper.insert(cloneIgnoreId(dbOrderPercentage, o -> o.setGrossProfitBonusQuotaPerc(null)));
 | 
	
		
			
				|  |  | +       // 测试 grossProfitPlatformQuotaPerc 不匹配
 | 
	
		
			
				|  |  | +       orderPercentageMapper.insert(cloneIgnoreId(dbOrderPercentage, o -> o.setGrossProfitPlatformQuotaPerc(null)));
 | 
	
		
			
				|  |  | +       // 测试 divideIntoPerc 不匹配
 | 
	
		
			
				|  |  | +       orderPercentageMapper.insert(cloneIgnoreId(dbOrderPercentage, o -> o.setDivideIntoPerc(null)));
 | 
	
		
			
				|  |  | +       // 测试 createTime 不匹配
 | 
	
		
			
				|  |  | +       orderPercentageMapper.insert(cloneIgnoreId(dbOrderPercentage, o -> o.setCreateTime(null)));
 | 
	
		
			
				|  |  | +       // 准备参数
 | 
	
		
			
				|  |  | +       OrderPercentagePageReqVO reqVO = new OrderPercentagePageReqVO();
 | 
	
		
			
				|  |  | +       reqVO.setGrossProfitPerc(null);
 | 
	
		
			
				|  |  | +       reqVO.setGrossProfitUserQuotaPerc(null);
 | 
	
		
			
				|  |  | +       reqVO.setGrossProfitAncestorQuotaPerc(null);
 | 
	
		
			
				|  |  | +       reqVO.setGrossProfitBonusQuotaPerc(null);
 | 
	
		
			
				|  |  | +       reqVO.setGrossProfitPlatformQuotaPerc(null);
 | 
	
		
			
				|  |  | +       reqVO.setDivideIntoPerc(null);
 | 
	
		
			
				|  |  | +       reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +       // 调用
 | 
	
		
			
				|  |  | +       PageResult<OrderPercentageDO> pageResult = orderPercentageService.getOrderPercentagePage(reqVO);
 | 
	
		
			
				|  |  | +       // 断言
 | 
	
		
			
				|  |  | +       assertEquals(1, pageResult.getTotal());
 | 
	
		
			
				|  |  | +       assertEquals(1, pageResult.getList().size());
 | 
	
		
			
				|  |  | +       assertPojoEquals(dbOrderPercentage, pageResult.getList().get(0));
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +}
 |