trade:创建订单接口的后端实现的单元测试 50%
parent
01d10b518c
commit
bc2aa78f70
@ -1,20 +0,0 @@
|
||||
package cn.iocoder.yudao.module.trade.convert.price;
|
||||
|
||||
import cn.iocoder.yudao.module.promotion.api.price.dto.PriceCalculateReqDTO;
|
||||
import cn.iocoder.yudao.module.trade.controller.app.order.vo.AppTradeOrderCreateReqVO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
import org.mapstruct.Mappings;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
@Mapper
|
||||
public interface PriceConvert {
|
||||
|
||||
PriceConvert INSTANCE = Mappers.getMapper(PriceConvert.class);
|
||||
|
||||
@Mappings(
|
||||
@Mapping(source = "userId" , target = "userId")
|
||||
)
|
||||
PriceCalculateReqDTO convert(AppTradeOrderCreateReqVO createReqVO, Long userId);
|
||||
|
||||
}
|
||||
@ -1,110 +0,0 @@
|
||||
package cn.iocoder.yudao.module.trade.service.order;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
||||
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
|
||||
import cn.iocoder.yudao.module.promotion.api.price.PriceApi;
|
||||
import cn.iocoder.yudao.module.promotion.api.price.dto.PriceCalculateRespDTO;
|
||||
import cn.iocoder.yudao.module.pay.api.order.PayOrderApi;
|
||||
import cn.iocoder.yudao.module.product.api.sku.ProductSkuApi;
|
||||
import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuRespDTO;
|
||||
import cn.iocoder.yudao.module.product.api.spu.ProductSpuApi;
|
||||
import cn.iocoder.yudao.module.product.api.spu.dto.SpuInfoRespDTO;
|
||||
import cn.iocoder.yudao.module.trade.controller.app.order.vo.AppTradeOrderCreateReqVO;
|
||||
import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO;
|
||||
import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderItemDO;
|
||||
import cn.iocoder.yudao.module.trade.dal.mysql.order.TradeOrderMapper;
|
||||
import cn.iocoder.yudao.module.trade.dal.mysql.orderitem.TradeOrderItemMapper;
|
||||
import cn.iocoder.yudao.module.trade.framework.order.config.TradeOrderConfig;
|
||||
import com.google.common.collect.Lists;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Collections;
|
||||
|
||||
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomInteger;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
// TODO @芋艿: 单测的 review; 最后搞;
|
||||
/**
|
||||
* @author LeeYan9
|
||||
* @since 2022-09-07
|
||||
*/
|
||||
@Import({TradeOrderServiceImpl.class, TradeOrderConfig.class})
|
||||
class TradeOrderServiceTest extends BaseDbUnitTest {
|
||||
|
||||
|
||||
@Resource
|
||||
TradeOrderService tradeOrderService;
|
||||
@Resource
|
||||
TradeOrderMapper tradeOrderMapper;
|
||||
@Resource
|
||||
TradeOrderItemMapper tradeOrderItemMapper;
|
||||
@MockBean
|
||||
ProductSpuApi productSpuApi;
|
||||
@MockBean
|
||||
ProductSkuApi productSkuApi;
|
||||
@MockBean
|
||||
PriceApi priceApi;
|
||||
@MockBean
|
||||
private PayOrderApi payOrderApi;
|
||||
|
||||
@Test
|
||||
void testCreateTradeOrder_success() {
|
||||
// mock 商品SPU数据
|
||||
SpuInfoRespDTO spuInfoRespDTO = randomPojo(SpuInfoRespDTO.class, spuInfo -> {
|
||||
spuInfo.setId(1L);
|
||||
spuInfo.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
||||
});
|
||||
when(productSpuApi.getSpuList(Collections.singleton(1L))).thenReturn(Lists.newArrayList(spuInfoRespDTO));
|
||||
// mock 商品SkU数据
|
||||
ProductSkuRespDTO skuInfoRespDTO = randomPojo(ProductSkuRespDTO.class, skuInfo -> {
|
||||
skuInfo.setId(1L);
|
||||
skuInfo.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
||||
skuInfo.setStock(randomInteger());
|
||||
skuInfo.setSpuId(1L);
|
||||
});
|
||||
when(productSkuApi.getSkuList(Collections.singleton(1L))).thenReturn(Lists.newArrayList(skuInfoRespDTO));
|
||||
// mock 价格信息
|
||||
PriceCalculateRespDTO calculateRespDTO = randomPojo(PriceCalculateRespDTO.class, priceCalculateRespDTO -> {
|
||||
PriceCalculateRespDTO.OrderItem item = priceCalculateRespDTO.getOrder().getItems().get(0);
|
||||
item.setSkuId(1L);
|
||||
item.setCount(2);
|
||||
priceCalculateRespDTO.getOrder().setItems(Collections.singletonList(item));
|
||||
});
|
||||
when(priceApi.calculatePrice(any())).thenReturn(calculateRespDTO);
|
||||
//mock 支付订单信息
|
||||
when(payOrderApi.createPayOrder(any())).thenReturn(1L);
|
||||
|
||||
// 准备请求数据
|
||||
AppTradeOrderCreateReqVO tradeOrderCreateReqVO = randomPojo(AppTradeOrderCreateReqVO.class, reqVO -> {
|
||||
AppTradeOrderCreateReqVO.Item item = randomPojo(AppTradeOrderCreateReqVO.Item.class, o -> {
|
||||
o.setSkuId(1L);
|
||||
o.setCount(2);
|
||||
});
|
||||
reqVO.setItems(Collections.singletonList(item));
|
||||
});
|
||||
// 创建交易订单,支付订单记录
|
||||
Long payOrderId = tradeOrderService.createTradeOrder(1L, "127.0.0.1", tradeOrderCreateReqVO);
|
||||
//断言交易订单
|
||||
TradeOrderDO tradeOrderDO = tradeOrderMapper.selectOne(TradeOrderDO::getUserId, 1L);
|
||||
assertNotNull(tradeOrderDO);
|
||||
//价格&用户
|
||||
assertEquals(calculateRespDTO.getOrder().getPayPrice(), tradeOrderDO.getPayPrice());
|
||||
assertEquals(1L, tradeOrderDO.getUserId());
|
||||
//断言交易订单项
|
||||
TradeOrderItemDO tradeOrderItemDO = tradeOrderItemMapper.selectOne(TradeOrderItemDO::getOrderId, tradeOrderDO.getId());
|
||||
assertNotNull(tradeOrderDO);
|
||||
//商品&用户
|
||||
assertEquals(skuInfoRespDTO.getId(), tradeOrderItemDO.getSkuId());
|
||||
assertEquals(1L, tradeOrderItemDO.getUserId());
|
||||
//价格
|
||||
assertEquals(calculateRespDTO.getOrder().getItems().get(0).getPresentPrice(), tradeOrderItemDO.getPresentPrice());
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,78 +0,0 @@
|
||||
/**todo cancelType 设置默认值 0?*/
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `trade_order`
|
||||
(
|
||||
`id` number NOT NULL GENERATED BY DEFAULT AS IDENTITY,
|
||||
`sn` varchar(32) NOT NULL,
|
||||
`type` int NOT NULL,
|
||||
`terminal` int NOT NULL,
|
||||
`user_id` bigint unsigned NOT NULL,
|
||||
`user_ip` varchar(30) NOT NULL,
|
||||
`user_remark` varchar(200),
|
||||
`status` int NOT NULL,
|
||||
`product_count` int NOT NULL,
|
||||
`cancel_type` int DEFAULT NULL,
|
||||
`remark` varchar(200),
|
||||
`payed` bit(1) NOT NULL DEFAULT FALSE,
|
||||
`pay_time` datetime DEFAULT NULL,
|
||||
`finish_time` datetime DEFAULT NULL,
|
||||
`cancel_time` datetime DEFAULT NULL,
|
||||
`sku_original_price` int NOT NULL DEFAULT '0',
|
||||
`sku_promotion_price` int NOT NULL DEFAULT '0',
|
||||
`order_promotion_price` int NOT NULL DEFAULT '0',
|
||||
`delivery_price` int NOT NULL DEFAULT '0',
|
||||
`pay_price` int DEFAULT '0',
|
||||
`pay_order_id` int DEFAULT NULL,
|
||||
`pay_channel` int DEFAULT NULL,
|
||||
`delivery_type` int NOT NULL DEFAULT '1',
|
||||
`actual_delivery_type` int NOT NULL DEFAULT '1',
|
||||
`delivery_template_id` int DEFAULT NULL,
|
||||
`express_no` int DEFAULT NULL,
|
||||
`delivery_status` bit(1) NOT NULL DEFAULT FALSE,
|
||||
`delivery_time` datetime DEFAULT NULL,
|
||||
`receive_time` datetime DEFAULT NULL,
|
||||
`receiver_name` varchar(20) DEFAULT NULL,
|
||||
`receiver_mobile` varchar(20) DEFAULT NULL,
|
||||
`receiver_area_id` int DEFAULT NULL,
|
||||
`receiver_post_code` int DEFAULT NULL,
|
||||
`receiver_detail_address` varchar(255) DEFAULT NULL,
|
||||
`refund_status` int NOT NULL DEFAULT '0',
|
||||
`refund_price` int NOT NULL DEFAULT '0',
|
||||
`coupon_id` bigint unsigned DEFAULT NULL,
|
||||
`creator` varchar(64) DEFAULT '',
|
||||
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
`updater` varchar(64) DEFAULT '',
|
||||
`update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
`deleted` bit(1) NOT NULL DEFAULT FALSE,
|
||||
PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `trade_order_item`
|
||||
(
|
||||
`id` number NOT NULL GENERATED BY DEFAULT AS IDENTITY,
|
||||
`user_id` bigint unsigned NOT NULL,
|
||||
`order_id` bigint unsigned NOT NULL,
|
||||
`spu_id` bigint unsigned NOT NULL,
|
||||
`sku_id` bigint unsigned NOT NULL,
|
||||
`properties` json DEFAULT NULL,
|
||||
`name` varchar(128) DEFAULT NULL,
|
||||
`pic_url` varchar(200) DEFAULT NULL,
|
||||
`count` int NOT NULL,
|
||||
`commented` bit(1) DEFAULT NULL,
|
||||
`original_price` int NOT NULL DEFAULT '0',
|
||||
`total_original_price` int NOT NULL DEFAULT '0',
|
||||
`total_promotion_price` int NOT NULL DEFAULT '0',
|
||||
`present_price` int NOT NULL DEFAULT '0',
|
||||
`total_present_price` int NOT NULL DEFAULT '0',
|
||||
`total_pay_price` int NOT NULL DEFAULT '0',
|
||||
`refund_status` int NOT NULL DEFAULT '0',
|
||||
`refund_total` int NOT NULL DEFAULT '0',
|
||||
`creator` varchar(64) DEFAULT '',
|
||||
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
`updater` varchar(64) DEFAULT '',
|
||||
`update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
`deleted` bit(1) DEFAULT FALSE,
|
||||
PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
@ -0,0 +1,72 @@
|
||||
CREATE TABLE IF NOT EXISTS "trade_order" (
|
||||
"id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
|
||||
"no" varchar NOT NULL,
|
||||
"type" int NOT NULL,
|
||||
"terminal" int NOT NULL,
|
||||
"user_id" bigint NOT NULL,
|
||||
"user_ip" varchar NOT NULL,
|
||||
"user_remark" varchar,
|
||||
"status" int NOT NULL,
|
||||
"product_count" int NOT NULL,
|
||||
"cancel_type" int,
|
||||
"remark" varchar,
|
||||
"payed" bit NOT NULL,
|
||||
"pay_time" datetime,
|
||||
"finish_time" datetime,
|
||||
"cancel_time" datetime,
|
||||
"original_price" int NOT NULL,
|
||||
"order_price" int NOT NULL,
|
||||
"discount_price" int NOT NULL,
|
||||
"delivery_price" int NOT NULL,
|
||||
"adjust_price" int NOT NULL,
|
||||
"pay_price" int NOT NULL,
|
||||
"pay_order_id" int,
|
||||
"pay_channel" int,
|
||||
"delivery_templateid" int,
|
||||
"express_no" int,
|
||||
"delivery_status" bit NOT NULL,
|
||||
"delivery_time" datetime,
|
||||
"receive_time" datetime,
|
||||
"receiver_name" varchar NOT NULL,
|
||||
"receiver_mobile" varchar NOT NULL,
|
||||
"receiver_area_id" int NOT NULL,
|
||||
"receiver_post_code" int,
|
||||
"receiver_detail_address" varchar NOT NULL,
|
||||
"refund_status" int NOT NULL,
|
||||
"refund_price" int NOT NULL,
|
||||
"coupon_id" bigint NOT NULL,
|
||||
"coupon_price" int NOT NULL,
|
||||
"point_price" int NOT NULL,
|
||||
"creator" varchar DEFAULT '',
|
||||
"create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updater" varchar DEFAULT '',
|
||||
"update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
"deleted" bit NOT NULL DEFAULT FALSE,
|
||||
PRIMARY KEY ("id")
|
||||
) COMMENT '交易订单表';
|
||||
|
||||
CREATE TABLE IF NOT EXISTS "trade_order_item" (
|
||||
"id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
|
||||
"user_id" bigint NOT NULL,
|
||||
"order_id" bigint NOT NULL,
|
||||
"spu_id" bigint NOT NULL,
|
||||
"sku_id" bigint NOT NULL,
|
||||
"properties" varchar,
|
||||
"name" varchar NOT NULL,
|
||||
"pic_url" varchar,
|
||||
"count" int NOT NULL,
|
||||
"original_price" int NOT NULL,
|
||||
"original_unit_price" int NOT NULL,
|
||||
"discount_price" int NOT NULL,
|
||||
"pay_price" int NOT NULL,
|
||||
"order_part_price" int NOT NULL,
|
||||
"order_divide_price" int NOT NULL,
|
||||
"refund_status" int NOT NULL,
|
||||
"refund_total" int NOT NULL,
|
||||
"creator" varchar DEFAULT '',
|
||||
"create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updater" varchar DEFAULT '',
|
||||
"update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
"deleted" bit NOT NULL DEFAULT FALSE,
|
||||
PRIMARY KEY ("id")
|
||||
) COMMENT '交易订单明细表';
|
||||
Loading…
Reference in New Issue