mirror of
https://gitee.com/hhyykk/ipms-sjy.git
synced 2025-08-10 16:21:52 +08:00
[新增][商品评价]管理后台分页查询
This commit is contained in:
@@ -1,16 +1,25 @@
|
||||
package cn.iocoder.yudao.module.product.service.comment;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
|
||||
import cn.iocoder.yudao.module.product.dal.dataobject.category.ProductCategoryDO;
|
||||
import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentPageReqVO;
|
||||
import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentRespVO;
|
||||
import cn.iocoder.yudao.module.product.convert.comment.ProductCommentConvert;
|
||||
import cn.iocoder.yudao.module.product.dal.dataobject.comment.ProductCommentDO;
|
||||
import cn.iocoder.yudao.module.product.dal.mysql.comment.ProductCommentMapper;
|
||||
import cn.iocoder.yudao.module.product.enums.comment.ProductCommentScoresEnum;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Date;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
/**
|
||||
* {@link ProductCommentServiceImpl} 的单元测试类
|
||||
@@ -23,6 +32,17 @@ public class ProductCommentServiceImplTest extends BaseDbUnitTest {
|
||||
@Resource
|
||||
private ProductCommentMapper productCommentMapper;
|
||||
|
||||
@Resource
|
||||
private ProductCommentServiceImpl productCommentService;
|
||||
|
||||
public String generateNo() {
|
||||
return DateUtil.format(new Date(), "yyyyMMddHHmmss") + RandomUtil.randomInt(100000, 999999);
|
||||
}
|
||||
|
||||
public Long generateId() {
|
||||
return RandomUtil.randomLong(100000, 999999);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateCommentAndGet_success() {
|
||||
// mock 测试
|
||||
@@ -35,5 +55,44 @@ public class ProductCommentServiceImplTest extends BaseDbUnitTest {
|
||||
assertPojoEquals(productComment, comment);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetCommentPage_success() {
|
||||
// 准备参数
|
||||
ProductCommentDO productComment = randomPojo(ProductCommentDO.class, o -> {
|
||||
o.setUserNickname("王二狗");
|
||||
o.setSpuName("感冒药");
|
||||
o.setScores(ProductCommentScoresEnum.FOUR.getScores());
|
||||
});
|
||||
productCommentMapper.insert(productComment);
|
||||
|
||||
Long orderId = productComment.getOrderId();
|
||||
Long spuId = productComment.getSpuId();
|
||||
|
||||
// 测试 userNickname 不匹配
|
||||
productCommentMapper.insert(cloneIgnoreId(productComment, o -> o.setUserNickname("王三")));
|
||||
// 测试 orderId 不匹配
|
||||
productCommentMapper.insert(cloneIgnoreId(productComment, o -> o.setOrderId(generateId())));
|
||||
// 测试 spuId 不匹配
|
||||
productCommentMapper.insert(cloneIgnoreId(productComment, o -> o.setSpuId(generateId())));
|
||||
// 测试 spuName 不匹配
|
||||
productCommentMapper.insert(cloneIgnoreId(productComment, o -> o.setSpuName("感康")));
|
||||
// 测试 scores 不匹配
|
||||
productCommentMapper.insert(cloneIgnoreId(productComment, o -> o.setScores(ProductCommentScoresEnum.ONE.getScores())));
|
||||
|
||||
// 调用
|
||||
ProductCommentPageReqVO productCommentPageReqVO = new ProductCommentPageReqVO();
|
||||
productCommentPageReqVO.setUserNickname("王二");
|
||||
productCommentPageReqVO.setOrderId(orderId);
|
||||
productCommentPageReqVO.setSpuId(spuId);
|
||||
productCommentPageReqVO.setSpuName("感冒药");
|
||||
productCommentPageReqVO.setScores(ProductCommentScoresEnum.FOUR.getScores());
|
||||
|
||||
PageResult<ProductCommentDO> commentPage = productCommentService.getCommentPage(productCommentPageReqVO);
|
||||
PageResult<ProductCommentRespVO> result = ProductCommentConvert.INSTANCE.convertPage(productCommentMapper.selectPage(productCommentPageReqVO));
|
||||
assertEquals(result.getTotal(), commentPage.getTotal());
|
||||
|
||||
PageResult<ProductCommentDO> all = productCommentService.getCommentPage(new ProductCommentPageReqVO());
|
||||
assertEquals(6, all.getTotal());
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -92,6 +92,7 @@ CREATE TABLE IF NOT EXISTS `product_comment` (
|
||||
`order_id` bigint NOT NULL COMMENT '交易订单编号',
|
||||
`order_item_id` bigint NOT NULL COMMENT '交易订单项编号',
|
||||
`spu_id` bigint NOT NULL COMMENT '商品SPU编号',
|
||||
`spu_name` varchar NOT NULL COMMENT '商品SPU名称',
|
||||
`sku_id` bigint NOT NULL COMMENT '商品SKU编号',
|
||||
`visible` bit(1) NOT NULL DEFAULT 1 COMMENT '是否可见 1:显示 0:隐藏',
|
||||
`scores` int NOT NULL COMMENT '评分星级 1-5分',
|
||||
|
Reference in New Issue
Block a user