This commit is contained in:
@@ -51,6 +51,52 @@ class WxCustomRandomOrderApiTest extends WxCustomOrderApiTestSupport {
|
||||
@org.springframework.beans.factory.annotation.Autowired
|
||||
private com.starry.admin.modules.order.service.IPlayOrderInfoService orderInfoService;
|
||||
|
||||
@Test
|
||||
void randomOrderFailsWhenBalanceInsufficient() throws Exception {
|
||||
SecurityUtils.setTenantId(ApiTestDataSeeder.DEFAULT_TENANT_ID);
|
||||
String remark = "API random insufficient " + IdUtils.getUuid();
|
||||
try {
|
||||
setCustomerBalance(BigDecimal.ZERO);
|
||||
String customerToken = wxTokenService.createWxUserToken(ApiTestDataSeeder.DEFAULT_CUSTOMER_ID);
|
||||
customUserInfoService.updateTokenById(ApiTestDataSeeder.DEFAULT_CUSTOMER_ID, customerToken);
|
||||
|
||||
ensureTenantContext();
|
||||
long beforeCount = playOrderInfoService.lambdaQuery()
|
||||
.eq(PlayOrderInfoEntity::getPurchaserBy, ApiTestDataSeeder.DEFAULT_CUSTOMER_ID)
|
||||
.eq(PlayOrderInfoEntity::getPlaceType, OrderConstant.PlaceType.RANDOM.getCode())
|
||||
.count();
|
||||
|
||||
String payload = "{" +
|
||||
"\"sex\":\"2\"," +
|
||||
"\"levelId\":\"" + ApiTestDataSeeder.DEFAULT_CLERK_LEVEL_ID + "\"," +
|
||||
"\"commodityId\":\"" + ApiTestDataSeeder.DEFAULT_COMMODITY_ID + "\"," +
|
||||
"\"commodityQuantity\":1," +
|
||||
"\"weiChatCode\":\"apitest-customer-wx\"," +
|
||||
"\"excludeHistory\":\"0\"," +
|
||||
"\"couponIds\":[]," +
|
||||
"\"remark\":\"" + remark + "\"" +
|
||||
"}";
|
||||
|
||||
mockMvc.perform(post("/wx/custom/order/random")
|
||||
.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)
|
||||
.eq(PlayOrderInfoEntity::getPlaceType, OrderConstant.PlaceType.RANDOM.getCode())
|
||||
.count();
|
||||
Assertions.assertThat(afterCount).isEqualTo(beforeCount);
|
||||
} finally {
|
||||
CustomSecurityContextHolder.remove();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
// 测试用例:客户带随机下单请求命中默认等级与服务,接口应返回成功文案,
|
||||
// 并新增一条处于待接单状态的随机订单,金额、商品信息与 remark 与提交参数保持一致。
|
||||
|
||||
Reference in New Issue
Block a user