feat(wechat): 抽象通知发送器并完善自定义下单相关接口测试

This commit is contained in:
irving
2025-11-01 23:55:51 -04:00
parent 9f83103189
commit d01c8a4c6a
7 changed files with 172 additions and 15 deletions

View File

@@ -86,6 +86,16 @@ class WxCustomSpecifiedOrderApiTest extends WxCustomOrderApiTestSupport {
.one();
Assertions.assertThat(order).isNotNull();
PlayCouponDetailsEntity detailBeforeForceCancel = couponDetailsService.getById(couponDetailId);
Assertions.assertThat(detailBeforeForceCancel).isNotNull();
Assertions.assertThat(detailBeforeForceCancel.getUseState()).isEqualTo(CouponUseState.USED.getCode());
Assertions.assertThat(detailBeforeForceCancel.getUseTime()).isNotNull();
PlayCouponDetailsEntity detailBeforeCancel = couponDetailsService.getById(couponDetailId);
Assertions.assertThat(detailBeforeCancel).isNotNull();
Assertions.assertThat(detailBeforeCancel.getUseState()).isEqualTo(CouponUseState.USED.getCode());
Assertions.assertThat(detailBeforeCancel.getUseTime()).isNotNull();
String cancelPayload = "{" +
"\"orderId\":\"" + order.getId() + "\"," +
"\"refundReason\":\"测试取消\"," +
@@ -106,9 +116,11 @@ class WxCustomSpecifiedOrderApiTest extends WxCustomOrderApiTestSupport {
Assertions.assertThat(cancelled.getOrderStatus()).isEqualTo(OrderConstant.OrderStatus.CANCELLED.getCode());
PlayCouponDetailsEntity detail = couponDetailsService.getById(couponDetailId);
Assertions.assertThat(detail).isNotNull();
Assertions.assertThat(detail.getUseState())
.as("取消指定单后优惠券应恢复为未使用")
.isEqualTo(CouponUseState.UNUSED.getCode());
Assertions.assertThat(detail.getUseTime()).isNull();
} finally {
CustomSecurityContextHolder.remove();
}
@@ -172,6 +184,11 @@ class WxCustomSpecifiedOrderApiTest extends WxCustomOrderApiTestSupport {
Assertions.assertThat(order.getFinalAmount()).isEqualByComparingTo(expectedNet);
Assertions.assertThat(order.getDiscountAmount()).isEqualByComparingTo(discount);
PlayCouponDetailsEntity detailAfterOrder = couponDetailsService.getById(couponDetailId);
Assertions.assertThat(detailAfterOrder).isNotNull();
Assertions.assertThat(detailAfterOrder.getUseState()).isEqualTo(CouponUseState.USED.getCode());
Assertions.assertThat(detailAfterOrder.getUseTime()).isNotNull();
verify(wxCustomMpService).sendCreateOrderMessage(
eq(ApiTestDataSeeder.DEFAULT_TENANT_ID),
eq(ApiTestDataSeeder.DEFAULT_CLERK_OPEN_ID),
@@ -194,6 +211,10 @@ class WxCustomSpecifiedOrderApiTest extends WxCustomOrderApiTestSupport {
Assertions.assertThat(order.getEstimatedRevenue()).isEqualByComparingTo(expectedRevenue);
assertCouponUsed(couponDetailId);
PlayCouponDetailsEntity detailAfterComplete = couponDetailsService.getById(couponDetailId);
Assertions.assertThat(detailAfterComplete).isNotNull();
Assertions.assertThat(detailAfterComplete.getUseState()).isEqualTo(CouponUseState.USED.getCode());
Assertions.assertThat(detailAfterComplete.getUseTime()).isNotNull();
} finally {
CustomSecurityContextHolder.remove();
}
@@ -273,9 +294,11 @@ class WxCustomSpecifiedOrderApiTest extends WxCustomOrderApiTestSupport {
Assertions.assertThat(cancelled.getOrderStatus()).isEqualTo(OrderConstant.OrderStatus.CANCELLED.getCode());
PlayCouponDetailsEntity detail = couponDetailsService.getById(couponDetailId);
Assertions.assertThat(detail).isNotNull();
Assertions.assertThat(detail.getUseState())
.as("强制取消指定单后优惠券应恢复为未使用")
.isEqualTo(CouponUseState.UNUSED.getCode());
Assertions.assertThat(detail.getUseTime()).isNull();
} finally {
CustomSecurityContextHolder.remove();
}