fix: 修复 TradeOrderUpdateServiceTest

This commit is contained in:
DevDengChao 2024-05-15 13:44:57 +08:00
parent c68f32cefe
commit 9c111acfbe
2 changed files with 203 additions and 122 deletions

View File

@ -1,33 +1,49 @@
package cn.iocoder.yudao.module.trade.service.order; 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.framework.test.core.ut.BaseDbUnitTest;
import cn.iocoder.yudao.module.member.api.address.MemberAddressApi; import cn.iocoder.yudao.module.member.api.address.MemberAddressApi;
import cn.iocoder.yudao.module.member.api.user.MemberUserApi; import cn.iocoder.yudao.module.member.api.user.MemberUserApi;
import cn.iocoder.yudao.module.pay.api.order.PayOrderApi; import cn.iocoder.yudao.module.pay.api.order.PayOrderApi;
import cn.iocoder.yudao.module.pay.api.order.dto.PayOrderRespDTO; import cn.iocoder.yudao.module.pay.api.order.dto.PayOrderRespDTO;
import cn.iocoder.yudao.module.pay.enums.order.PayOrderStatusEnum; import cn.iocoder.yudao.module.pay.enums.order.PayOrderStatusEnum;
import cn.iocoder.yudao.module.product.api.comment.ProductCommentApi;
import cn.iocoder.yudao.module.product.api.sku.ProductSkuApi; import cn.iocoder.yudao.module.product.api.sku.ProductSkuApi;
import cn.iocoder.yudao.module.product.api.spu.ProductSpuApi; import cn.iocoder.yudao.module.product.api.spu.ProductSpuApi;
import cn.iocoder.yudao.module.promotion.api.coupon.CouponApi; import cn.iocoder.yudao.module.promotion.api.coupon.CouponApi;
import cn.iocoder.yudao.module.system.api.notify.NotifyMessageSendApi;
import cn.iocoder.yudao.module.trade.controller.admin.delivery.vo.express.DeliveryExpressCreateReqVO;
import cn.iocoder.yudao.module.trade.controller.admin.order.vo.TradeOrderDeliveryReqVO; import cn.iocoder.yudao.module.trade.controller.admin.order.vo.TradeOrderDeliveryReqVO;
import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO; import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO;
import cn.iocoder.yudao.module.trade.dal.mysql.order.TradeOrderItemMapper; import cn.iocoder.yudao.module.trade.dal.mysql.order.TradeOrderItemMapper;
import cn.iocoder.yudao.module.trade.dal.mysql.order.TradeOrderMapper; import cn.iocoder.yudao.module.trade.dal.mysql.order.TradeOrderMapper;
import cn.iocoder.yudao.module.trade.dal.redis.no.TradeNoRedisDAO;
import cn.iocoder.yudao.module.trade.enums.delivery.DeliveryTypeEnum;
import cn.iocoder.yudao.module.trade.enums.order.TradeOrderRefundStatusEnum;
import cn.iocoder.yudao.module.trade.enums.order.TradeOrderStatusEnum; import cn.iocoder.yudao.module.trade.enums.order.TradeOrderStatusEnum;
import cn.iocoder.yudao.module.trade.framework.order.config.TradeOrderConfig; import cn.iocoder.yudao.module.trade.framework.order.config.TradeOrderConfig;
import cn.iocoder.yudao.module.trade.framework.order.config.TradeOrderProperties; import cn.iocoder.yudao.module.trade.framework.order.config.TradeOrderProperties;
import cn.iocoder.yudao.module.trade.service.cart.CartServiceImpl;
import cn.iocoder.yudao.module.trade.service.delivery.DeliveryExpressService;
import cn.iocoder.yudao.module.trade.service.delivery.DeliveryExpressServiceImpl;
import cn.iocoder.yudao.module.trade.service.message.TradeMessageServiceImpl;
import cn.iocoder.yudao.module.trade.service.order.handler.TradeOrderHandler;
import cn.iocoder.yudao.module.trade.service.price.TradePriceServiceImpl;
import cn.iocoder.yudao.module.trade.service.price.calculator.TradePriceCalculator;
import jakarta.annotation.Resource;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.context.annotation.Import; import org.springframework.context.annotation.Import;
import jakarta.annotation.Resource;
import java.time.Duration; import java.time.Duration;
import java.util.UUID;
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals;
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo; import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
@ -37,8 +53,10 @@ import static org.mockito.Mockito.when;
* @author LeeYan9 * @author LeeYan9
* @since 2022-09-07 * @since 2022-09-07
*/ */
@Disabled // TODO 芋艿后续 fix 补充的单测 @SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection")
@Import({TradeOrderUpdateServiceImpl.class, TradeOrderConfig.class}) @Import({TradeOrderUpdateServiceImpl.class, TradeOrderConfig.class, CartServiceImpl.class, TradePriceServiceImpl.class,
DeliveryExpressServiceImpl.class, TradeMessageServiceImpl.class
})
public class TradeOrderUpdateServiceTest extends BaseDbUnitTest { public class TradeOrderUpdateServiceTest extends BaseDbUnitTest {
@Resource @Resource
@ -55,7 +73,9 @@ public class TradeOrderUpdateServiceTest extends BaseDbUnitTest {
private ProductSpuApi productSpuApi; private ProductSpuApi productSpuApi;
@MockBean @MockBean
private ProductSkuApi productSkuApi; private ProductSkuApi productSkuApi;
// @MockBean @MockBean
private ProductCommentApi productCommentApi;
// @MockBean
// private PriceApi priceApi; // private PriceApi priceApi;
@MockBean @MockBean
private PayOrderApi payOrderApi; private PayOrderApi payOrderApi;
@ -66,11 +86,22 @@ public class TradeOrderUpdateServiceTest extends BaseDbUnitTest {
@MockBean @MockBean
private TradeOrderProperties tradeOrderProperties; private TradeOrderProperties tradeOrderProperties;
@MockBean
private TradeNoRedisDAO tradeNoRedisDAO;
@MockBean
private TradeOrderHandler tradeOrderHandler;
@MockBean
private TradePriceCalculator tradePriceCalculator;
@MockBean
private NotifyMessageSendApi notifyMessageSendApi;
@Autowired
private DeliveryExpressService deliveryExpressService;
@BeforeEach @BeforeEach
public void setUp() { public void setUp() {
when(tradeOrderProperties.getAppId()).thenReturn(888L); when(tradeOrderProperties.getAppId()).thenReturn(888L);
when(tradeOrderProperties.getPayExpireTime()).thenReturn(Duration.ofDays(1)); when(tradeOrderProperties.getPayExpireTime()).thenReturn(Duration.ofDays(1));
when(tradeNoRedisDAO.generate(anyString())).thenReturn(UUID.randomUUID().toString());
} }
// @Test // @Test
@ -259,11 +290,18 @@ public class TradeOrderUpdateServiceTest extends BaseDbUnitTest {
TradeOrderDO order = randomPojo(TradeOrderDO.class, o -> { TradeOrderDO order = randomPojo(TradeOrderDO.class, o -> {
o.setId(1L).setStatus(TradeOrderStatusEnum.UNDELIVERED.getStatus()); o.setId(1L).setStatus(TradeOrderStatusEnum.UNDELIVERED.getStatus());
o.setLogisticsId(null).setLogisticsNo(null).setDeliveryTime(null); o.setLogisticsId(null).setLogisticsNo(null).setDeliveryTime(null);
o.setRefundStatus(TradeOrderRefundStatusEnum.NONE.getStatus());
o.setDeliveryType(DeliveryTypeEnum.EXPRESS.getType());
}); });
tradeOrderMapper.insert(order); tradeOrderMapper.insert(order);
DeliveryExpressCreateReqVO expressCreateReqVO = new DeliveryExpressCreateReqVO();
expressCreateReqVO.setCode("code").setName("Name").setLogo("logo").setSort(0).setStatus(CommonStatusEnum.ENABLE.getStatus());
Long deliveryExpressId = deliveryExpressService.createDeliveryExpress(expressCreateReqVO);
// 准备参数 // 准备参数
TradeOrderDeliveryReqVO deliveryReqVO = new TradeOrderDeliveryReqVO().setId(1L) TradeOrderDeliveryReqVO deliveryReqVO = new TradeOrderDeliveryReqVO().setId(1L)
.setLogisticsId(10L).setLogisticsNo("100"); .setLogisticsId(deliveryExpressId).setLogisticsNo("100");
// mock 方法支付单 // mock 方法支付单
// 调用 // 调用

View File

@ -1,128 +1,155 @@
CREATE TABLE IF NOT EXISTS "trade_order" ( CREATE TABLE IF NOT EXISTS "trade_order"
"id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, (
"no" varchar NOT NULL, "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
"type" int NOT NULL, "no" varchar NOT NULL,
"terminal" int NOT NULL, "type" int NOT NULL,
"user_id" bigint NOT NULL, "terminal" int NOT NULL,
"user_ip" varchar NOT NULL, "user_id" bigint NOT NULL,
"user_remark" varchar, "user_ip" varchar NOT NULL,
"status" int NOT NULL, "user_remark" varchar,
"product_count" int NOT NULL, "status" int NOT NULL,
"cancel_type" int, "product_count" int NOT NULL,
"remark" varchar, "cancel_type" int,
"pay_status" bit NOT NULL, "remark" varchar,
"pay_time" datetime, "comment_status" boolean,
"finish_time" datetime, "brokerage_user_id" bigint,
"cancel_time" datetime, "pay_status" bit NOT NULL,
"original_price" int NOT NULL, "pay_time" datetime,
"order_price" int NOT NULL, "finish_time" datetime,
"discount_price" int NOT NULL, "cancel_time" datetime,
"delivery_price" int NOT NULL, "total_price" int NULL,
"adjust_price" int NOT NULL, "order_price" int NULL,
"pay_price" int NOT NULL, "discount_price" int NOT NULL,
"pay_order_id" bigint, "delivery_price" int NOT NULL,
"pay_channel_code" varchar, "adjust_price" int NOT NULL,
"delivery_template_id" bigint, "pay_price" int NOT NULL,
"logistics_id" bigint, "delivery_type" int NOT NULL,
"logistics_no" varchar, "pay_order_id" bigint,
"delivery_time" datetime, "pay_channel_code" varchar,
"receive_time" datetime, "delivery_template_id" bigint,
"receiver_name" varchar NOT NULL, "logistics_id" bigint,
"receiver_mobile" varchar NOT NULL, "logistics_no" varchar,
"receiver_area_id" int NOT NULL, "delivery_time" datetime,
"receiver_post_code" int, "receive_time" datetime,
"receiver_detail_address" varchar NOT NULL, "receiver_name" varchar NOT NULL,
"after_sale_status" int NOT NULL, "receiver_mobile" varchar NOT NULL,
"refund_price" int NOT NULL, "receiver_area_id" int NOT NULL,
"coupon_id" bigint NOT NULL, "receiver_post_code" int,
"coupon_price" int NOT NULL, "receiver_detail_address" varchar NOT NULL,
"point_price" int NOT NULL, "pick_up_store_id" long NULL,
"creator" varchar DEFAULT '', "pick_up_verify_code" varchar NULL,
"create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, "refund_status" int NULL,
"updater" varchar DEFAULT '', "refund_price" int NULL,
"update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, "after_sale_status" int NULL,
"deleted" bit NOT NULL DEFAULT FALSE, "coupon_id" bigint NOT NULL,
PRIMARY KEY ("id") "coupon_price" int NOT NULL,
"use_point" int NULL,
"point_price" int NOT NULL,
"give_point" int NULL,
"refund_point" int NULL,
"vip_price" int NULL,
"seckill_activity_id" long NULL,
"bargain_activity_id" long NULL,
"bargain_record_id" long NULL,
"combination_activity_id" long NULL,
"combination_head_id" long NULL,
"combination_record_id" long 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 '交易订单表'; ) COMMENT '交易订单表';
CREATE TABLE IF NOT EXISTS "trade_order_item" ( CREATE TABLE IF NOT EXISTS "trade_order_item"
"id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, (
"user_id" bigint NOT NULL, "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
"order_id" bigint NOT NULL, "user_id" bigint NOT NULL,
"spu_id" bigint NOT NULL, "order_id" bigint NOT NULL,
"spu_name" varchar NOT NULL, "cart_id" int NULL,
"sku_id" bigint NOT NULL, "spu_id" bigint NOT NULL,
"properties" varchar, "spu_name" varchar NOT NULL,
"pic_url" varchar, "sku_id" bigint NOT NULL,
"count" int NOT NULL, "properties" varchar,
"original_price" int NOT NULL, "pic_url" varchar,
"original_unit_price" int NOT NULL, "count" int NOT NULL,
"discount_price" int NOT NULL, "comment_status" boolean NULL,
"pay_price" int NOT NULL, "price" int NOT NULL,
"order_part_price" int NOT NULL, "discount_price" int NOT NULL,
"order_divide_price" int NOT NULL, "delivery_price" int NULL,
"after_sale_status" int NOT NULL, "adjust_price" int NULL,
"creator" varchar DEFAULT '', "pay_price" int NOT NULL,
"create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, "coupon_price" int NULL,
"updater" varchar DEFAULT '', "point_price" int NULL,
"update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, "use_point" int NULL,
"deleted" bit NOT NULL DEFAULT FALSE, "give_point" int NULL,
PRIMARY KEY ("id") "vip_price" int NULL,
"after_sale_id" long NULL,
"after_sale_status" 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 '交易订单明细表'; ) COMMENT '交易订单明细表';
CREATE TABLE IF NOT EXISTS "trade_after_sale" ( CREATE TABLE IF NOT EXISTS "trade_after_sale"
"id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, (
"no" varchar NOT NULL, "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
"status" int NOT NULL, "no" varchar NOT NULL,
"type" int NOT NULL, "status" int NOT NULL,
"way" int NOT NULL, "type" int NOT NULL,
"user_id" bigint NOT NULL, "way" int NOT NULL,
"apply_reason" varchar NOT NULL, "user_id" bigint NOT NULL,
"apply_reason" varchar NOT NULL,
"apply_description" varchar, "apply_description" varchar,
"apply_pic_urls" varchar, "apply_pic_urls" varchar,
"order_id" bigint NOT NULL, "order_id" bigint NOT NULL,
"order_no" varchar NOT NULL, "order_no" varchar NOT NULL,
"order_item_id" bigint NOT NULL, "order_item_id" bigint NOT NULL,
"spu_id" bigint NOT NULL, "spu_id" bigint NOT NULL,
"spu_name" varchar NOT NULL, "spu_name" varchar NOT NULL,
"sku_id" bigint NOT NULL, "sku_id" bigint NOT NULL,
"properties" varchar, "properties" varchar,
"pic_url" varchar, "pic_url" varchar,
"count" int NOT NULL, "count" int NOT NULL,
"audit_time" varchar, "audit_time" varchar,
"audit_user_id" bigint, "audit_user_id" bigint,
"audit_reason" varchar, "audit_reason" varchar,
"refund_price" int NOT NULL, "refund_price" int NOT NULL,
"pay_refund_id" bigint, "pay_refund_id" bigint,
"refund_time" varchar, "refund_time" varchar,
"logistics_id" bigint, "logistics_id" bigint,
"logistics_no" varchar, "logistics_no" varchar,
"delivery_time" varchar, "delivery_time" varchar,
"receive_time" varchar, "receive_time" varchar,
"receive_reason" varchar, "receive_reason" varchar,
"creator" varchar DEFAULT '', "creator" varchar DEFAULT '',
"create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updater" varchar DEFAULT '', "updater" varchar DEFAULT '',
"update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
"deleted" bit NOT NULL DEFAULT FALSE, "deleted" bit NOT NULL DEFAULT FALSE,
PRIMARY KEY ("id") PRIMARY KEY ("id")
) COMMENT '交易售后表'; ) COMMENT '交易售后表';
CREATE TABLE IF NOT EXISTS "trade_after_sale_log" ( CREATE TABLE IF NOT EXISTS "trade_after_sale_log"
"id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, (
"user_id" bigint NOT NULL, "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
"user_type" int NOT NULL, "user_id" bigint NOT NULL,
"after_sale_id" bigint NOT NULL, "user_type" int NOT NULL,
"order_id" bigint NOT NULL, "after_sale_id" bigint NOT NULL,
"order_item_id" bigint NOT NULL, "order_id" bigint NOT NULL,
"order_item_id" bigint NOT NULL,
"before_status" int, "before_status" int,
"after_status" int NOT NULL, "after_status" int NOT NULL,
"content" varchar NOT NULL, "content" varchar NOT NULL,
"creator" varchar DEFAULT '', "creator" varchar DEFAULT '',
"create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updater" varchar DEFAULT '', "updater" varchar DEFAULT '',
"update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
"deleted" bit NOT NULL DEFAULT FALSE, "deleted" bit NOT NULL DEFAULT FALSE,
PRIMARY KEY ("id") PRIMARY KEY ("id")
) COMMENT '交易售后日志'; ) COMMENT '交易售后日志';
@ -161,7 +188,7 @@ CREATE TABLE IF NOT EXISTS "trade_brokerage_record"
"updater" varchar DEFAULT '', "updater" varchar DEFAULT '',
"update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
"deleted" bit NOT NULL DEFAULT FALSE, "deleted" bit NOT NULL DEFAULT FALSE,
"tenant_id" bigint not null default '0', "tenant_id" bigint not null default '0',
PRIMARY KEY ("id") PRIMARY KEY ("id")
) COMMENT '佣金记录'; ) COMMENT '佣金记录';
CREATE TABLE IF NOT EXISTS "trade_brokerage_withdraw" CREATE TABLE IF NOT EXISTS "trade_brokerage_withdraw"
@ -186,6 +213,22 @@ CREATE TABLE IF NOT EXISTS "trade_brokerage_withdraw"
"updater" varchar DEFAULT '', "updater" varchar DEFAULT '',
"update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
"deleted" bit NOT NULL DEFAULT FALSE, "deleted" bit NOT NULL DEFAULT FALSE,
"tenant_id" bigint not null default '0', "tenant_id" bigint not null default '0',
PRIMARY KEY ("id")
) COMMENT '佣金提现';
CREATE TABLE IF NOT EXISTS "trade_delivery_express"
(
"id" int NOT NULL GENERATED BY DEFAULT AS IDENTITY,
"code" varchar NULL,
"name" varchar,
"logo" varchar NULL,
"sort" int NOT NULL,
"status" 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") PRIMARY KEY ("id")
) COMMENT '佣金提现'; ) COMMENT '佣金提现';