修复订单下单错误和余额扣款校验问题
Some checks failed
Build and Push Backend / docker (push) Failing after 5s

This commit is contained in:
irving
2025-11-03 10:02:03 -05:00
parent fe36332ef3
commit 83112b406a
14 changed files with 456 additions and 23 deletions

View File

@@ -39,6 +39,55 @@ class WxCustomSpecifiedOrderApiTest extends WxCustomOrderApiTestSupport {
@org.springframework.beans.factory.annotation.Autowired
private com.starry.admin.modules.weichat.service.WxTokenService clerkWxTokenService;
@Test
void specifiedOrderFailsWhenBalanceInsufficient() throws Exception {
SecurityUtils.setTenantId(ApiTestDataSeeder.DEFAULT_TENANT_ID);
String remark = "API specified insufficient " + IdUtils.getUuid();
try {
setCustomerBalance(BigDecimal.ZERO);
String customerToken = wxTokenService.createWxUserToken(ApiTestDataSeeder.DEFAULT_CUSTOMER_ID);
customUserInfoService.updateTokenById(ApiTestDataSeeder.DEFAULT_CUSTOMER_ID, customerToken);
ensureTenantContext();
com.starry.admin.modules.clerk.module.entity.PlayClerkUserInfoEntity clerk =
clerkUserInfoService.selectById(ApiTestDataSeeder.DEFAULT_CLERK_ID);
Assertions.assertThat(clerk.getLevelId())
.as("默认店员应绑定基础等级用于价格校验")
.isEqualTo(ApiTestDataSeeder.DEFAULT_CLERK_LEVEL_ID);
ensureTenantContext();
long beforeCount = playOrderInfoService.lambdaQuery()
.eq(PlayOrderInfoEntity::getPurchaserBy, ApiTestDataSeeder.DEFAULT_CUSTOMER_ID)
.count();
String payload = "{" +
"\"clerkId\":\"" + ApiTestDataSeeder.DEFAULT_CLERK_ID + "\"," +
"\"commodityId\":\"" + ApiTestDataSeeder.DEFAULT_COMMODITY_ID + "\"," +
"\"commodityQuantity\":1," +
"\"weiChatCode\":\"apitest-customer-wx\"," +
"\"couponIds\":[]," +
"\"remark\":\"" + remark + "\"" +
"}";
mockMvc.perform(post("/wx/custom/order/commodity")
.header(USER_HEADER, DEFAULT_USER)
.header(TENANT_HEADER, DEFAULT_TENANT)
.header(Constants.CUSTOM_USER_LOGIN_TOKEN, Constants.TOKEN_PREFIX + customerToken)
.contentType(MediaType.APPLICATION_JSON)
.content(payload))
.andExpect(status().isOk())
.andExpect(jsonPath("$.code").value(998));
ensureTenantContext();
long afterCount = playOrderInfoService.lambdaQuery()
.eq(PlayOrderInfoEntity::getPurchaserBy, ApiTestDataSeeder.DEFAULT_CUSTOMER_ID)
.count();
Assertions.assertThat(afterCount).isEqualTo(beforeCount);
} finally {
CustomSecurityContextHolder.remove();
}
}
@Test
// 测试用例:指定单取消后优惠券应恢复为未使用
void specifiedOrderCancellationReleasesCoupon() throws Exception {