Commit 6795964b by DuJunLi

注入bean,增加查看训练营报名会员case,给学员报名训练营case,查看报名详情case,退单case

parent 150d7c46
......@@ -9,10 +9,11 @@ import com.xiaomai.enums.Terminal;
import com.xiaomai.utils.RandomStringUtil;
import com.xiaomai.utils.TimeUtils;
import com.xiaomai.utils.XMBaseTest;
import org.springframework.stereotype.Component;
import java.math.BigDecimal;
@Component("orderTools")
public class OrderTools extends XMBaseTest {
/**
......
......@@ -7,9 +7,10 @@ import com.xiaomai.enums.ApiModule;
import com.xiaomai.enums.RequestType;
import com.xiaomai.enums.Terminal;
import com.xiaomai.utils.XMBaseTest;
import org.springframework.stereotype.Component;
import java.util.List;
@Component("tools")
public class Tools extends XMBaseTest {
......
......@@ -33,6 +33,7 @@ public class SelectTargetTrainingCampAndGetInfo extends BaseCreateTrainingData {
public int traineeUpperLimit;
public int totalClassHour;
public String chiefCoachId="";
public Double price;
List<String> assistCoachIds;
@BeforeClass
......@@ -61,6 +62,7 @@ public class SelectTargetTrainingCampAndGetInfo extends BaseCreateTrainingData {
.fluentPut("traineeLowerLimit", group.getIntValue("traineeLowerLimit"))
.fluentPut("traineeUpperLimit", group.getIntValue("traineeUpperLimit"))
.fluentPut("totalClassHour", group.getIntValue("totalClassHour"))
.fluentPut("price",group.getDouble("price"))
.fluentPut("trainerList", group.getJSONArray("trainerList").toJavaList(JSONObject.class).stream()
.map(trainers -> {
return new JSONObject()
......@@ -79,6 +81,7 @@ public class SelectTargetTrainingCampAndGetInfo extends BaseCreateTrainingData {
traineeLowerLimit=campInfo.get(0).getIntValue("traineeLowerLimit");
traineeUpperLimit=campInfo.get(0).getIntValue("traineeUpperLimit");
totalClassHour=campInfo.get(0).getIntValue("totalClassHour");
price=campInfo.get(0).getDouble("price");
chiefCoachId = campInfo.get(0).getJSONArray("trainerList").toJavaList(JSONObject.class).stream().filter(e -> {
return "杜君丽".equals(e.getString("nickName"));
}).map(e -> e.getString("id")).findFirst().orElse(null);
......
package com.xiaomai.cases.polar.training;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xiaomai.cases.polar.finance.order.OrderTools;
import com.xiaomai.cases.polar.schedule.camp.SelectTargetTrainingCampAndGetInfo;
import com.xiaomai.enums.ApiModule;
import com.xiaomai.enums.LoginAccount;
import com.xiaomai.enums.RequestType;
import com.xiaomai.enums.Terminal;
import com.xiaomai.utils.RandomStringUtil;
import com.xiaomai.utils.TimeUtils;
import com.xiaomai.utils.XMJSONPath;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import com.xiaomai.cases.polar.member.Tools;
import javax.annotation.Resource;
/**
* @author adu
* data 2024/7/22 11:08
*/
public class TestDoSignCampOrder extends SelectTargetTrainingCampAndGetInfo {
@Resource(name = "trainingTools")
TrainingTools trainingTools;
@Resource(name = "tools")
Tools tools;
@Resource(name = "orderTools")
OrderTools orderTools;
String memberId = "";
String memberId2 = "";
String orderId = "";
@BeforeClass
public void beforeTest() {
setTestInfo(ApiModule.Polar_Training, "API_signOrderCamp", LoginAccount.ADU_PROD, Terminal.B, "adu");
super.beforeTest();
}
@Test(description = "训练营活动详情-报名会员-给会员报名")
public void testDoSignCampOrder() throws InterruptedException {
//搜索目标会员
String phone = "15558121569";
memberId = trainingTools.searchTargerMember(phone);
if (memberId.isEmpty()) {
memberId = tools.create("阿杜", phone).getString("result");
}
//给会员报名
trainingTools.doSignCampOrder(memberId, this.price, this.campId);
Thread.sleep(1000);
//报名成功后根据会员手机号,在报名会员列表搜索报名数据
trainingTools.getTrainingApplyRecordsList(this.campId, phone);
Assert.assertTrue(XMJSONPath.getJSONArrayByReadPath(dataApi.getApi_response(), "$.result").size() == 1, "给学员报名后,在报名列表没查询到数据");
Assert.assertEquals(XMJSONPath.getJSONArrayByReadPath(dataApi.getApi_response(), "$.result").getJSONObject(0).getString("state"), "PAID");
String memberCardId = XMJSONPath.getJSONArrayByReadPath(dataApi.getApi_response(), "$.result").getJSONObject(0).getString("memberCardId");
//查看报名详情
trainingTools.getTrainingAccountDetailById(memberCardId);
Assert.assertTrue(Integer.valueOf(XMJSONPath.readPath(dataApi.getApi_response(), "$.result.trainingCampInfo.totalClassHour")).equals(this.totalClassHour));
Assert.assertTrue(Double.valueOf(XMJSONPath.readPath(dataApi.getApi_response(), "$.result.trainingCampInfo.price")).equals(this.price));
Assert.assertEquals(XMJSONPath.readPath(dataApi.getApi_response(), "$.result.owner.phone"), phone);
Assert.assertEquals(XMJSONPath.readPath(dataApi.getApi_response(), "$.result.trainingCampId"), this.campId);
//删除训练营活动:删除失败
trainingTools.delTrainingFail(this.campId);
Assert.assertEquals(XMJSONPath.readPath(dataApi.getApi_response(),"$.code"),"TRAINING_CAMP_DELETE_FAILED");
Assert.assertEquals(XMJSONPath.readPath(dataApi.getApi_response(),"$.message"),"该训练营已有人报名,无法删除!");
//报名详情-训练营报名退款
trainingTools.refundCampOrder(memberId, this.price, memberCardId, this.totalClassHour);
Thread.sleep(1000);
//退单后再搜索报名记录check
trainingTools.getTrainingApplyRecordsList(this.campId, phone);
Assert.assertTrue(XMJSONPath.getJSONArrayByReadPath(dataApi.getApi_response(), "$.result").size() == 0, "给学员退单后,在报名列表中还能查询到数据");
Thread.sleep(1000);
//退单后再次给该学员报名,提示已经报过该训练营,就不能再报了
JSONObject body = new JSONObject();
body.put("operatorId", xmAppApi.getLoginInfo().getAdminId());
body.put("studioId", xmAppApi.getLoginInfo().getStudioId());
body.put("brandId", xmAppApi.getLoginInfo().getBrandId());
body.put("salesmanId", xmAppApi.getLoginInfo().getAdminId());
body.put("operationTime", TimeUtils.getCurrentTime());
body.put("objectId", RandomStringUtil.randomString(20));
body.put("memberId", memberId);
body.put("receivableAmount", this.price);
JSONObject campInfo = new JSONObject();
campInfo.put("campId", campId);
body.put("camp", campInfo);
JSONArray paymentWays = new JSONArray();
JSONObject payObject = new JSONObject();
payObject.put("amount", this.price);
payObject.put("paymentWay", "1");
payObject.put("voucherResourceIds", new JSONArray());
body.put("paymentWays", paymentWays);
xmAppApi.doRequest(RequestType.JSON, params, body.toString(), headers).assetsSuccess(false);
Assert.assertEquals(XMJSONPath.readPath(xmAppApi.getApi_response(), "$.message"), "签单失败,已报名该训练营无需重复操作");
}
@Test(description = "给学员报名训练营活动构造待支付订单",priority = 1)
public void testUnpaidOrder() throws InterruptedException {
//搜索目标会员
String phone = "15658063769";
memberId2 = trainingTools.searchTargerMember(phone);
if (memberId2.isEmpty()) {
memberId2 = tools.create("晨晨爸爸", phone).getString("result");
}
Thread.sleep(3000);
JSONObject body = new JSONObject();
body.put("operatorId", xmAppApi.getLoginInfo().getAdminId());
body.put("studioId", xmAppApi.getLoginInfo().getStudioId());
body.put("brandId", xmAppApi.getLoginInfo().getBrandId());
body.put("salesmanId", xmAppApi.getLoginInfo().getAdminId());
body.put("operationTime", TimeUtils.getCurrentTime());
body.put("objectId", RandomStringUtil.randomString(20));
body.put("memberId", memberId2);
body.put("receivableAmount", this.price);
JSONObject campInfo = new JSONObject();
campInfo.put("campId", this.campId);
body.put("camp", campInfo);
body.put("paymentWays", new JSONArray());//支付方式传空
xmAppApi.doRequest(RequestType.JSON, params, body.toString(), headers).assetsSuccess(true);
orderId = XMJSONPath.readPath(xmAppApi.getApi_response(), "$.result");
//报名成功后根据会员手机号,在报名会员列表搜索报名数据
trainingTools.getTrainingApplyRecordsList(this.campId, phone);
Assert.assertTrue(XMJSONPath.getJSONArrayByReadPath(dataApi.getApi_response(), "$.result").size() == 1, "给学员报名后,在报名列表没查询到数据");
//check订单 待支付状态
Assert.assertEquals(XMJSONPath.getJSONArrayByReadPath(dataApi.getApi_response(), "$.result").getJSONObject(0).getString("state"), "WAITING");
//操作取消订单
orderTools.cancel(orderId);
trainingTools.getTrainingApplyRecordsList(this.campId, phone);
Assert.assertTrue(XMJSONPath.getJSONArrayByReadPath(dataApi.getApi_response(), "$.result").size() == 0, "取消学员订单后,在报名列表中还能查询到数据");
}
@AfterClass(description = "删除此case创建的训练营活动-退单/取消订单后可以删除活动")
public void delData() {
if (!this.campId.isEmpty()) {
trainingTools.deleteTraining(this.campId);
}
}
}
\ No newline at end of file
package com.xiaomai.cases.polar.training;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xiaomai.cases.polar.finance.order.OrderTools;
import com.xiaomai.cases.polar.member.Tools;
import com.xiaomai.cases.polar.schedule.camp.SelectTargetTrainingCampAndGetInfo;
import com.xiaomai.enums.ApiModule;
import com.xiaomai.enums.LoginAccount;
import com.xiaomai.enums.RequestType;
import com.xiaomai.enums.Terminal;
import com.xiaomai.utils.RandomStringUtil;
import com.xiaomai.utils.TimeUtils;
import com.xiaomai.utils.XMJSONPath;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import javax.annotation.Resource;
/**
* 构造报名训练营活动-待支付,然后操作删除训练营活动(fail)-取消订单-再次报名训练营活动(success)
* @author adu
* data 2024/7/22 16:38
*/
public class TestSignWaitingCampOrder extends SelectTargetTrainingCampAndGetInfo {
@Resource(name = "trainingTools")
TrainingTools trainingTools;
@Resource(name = "tools")
Tools tools;
@Resource(name = "orderTools")
OrderTools orderTools;
String memberId = "";
String orderId = "";
@BeforeClass
public void beforeTest() {
setTestInfo(ApiModule.Polar_Training, "API_signOrderCamp", LoginAccount.ADU_PROD, Terminal.B, "adu");
super.beforeTest();
}
@Test(description = "给学员报名训练营活动构造待支付订单")
public void testUnpaidOrder() throws InterruptedException {
//搜索目标会员
String phone = "15658063769";
memberId = trainingTools.searchTargerMember(phone);
if (memberId.isEmpty()) {
memberId = tools.create("晨晨爸爸", phone).getString("result");
}
JSONObject body = new JSONObject();
body.put("operatorId", xmAppApi.getLoginInfo().getAdminId());
body.put("studioId", xmAppApi.getLoginInfo().getStudioId());
body.put("brandId", xmAppApi.getLoginInfo().getBrandId());
body.put("salesmanId", xmAppApi.getLoginInfo().getAdminId());
body.put("operationTime", TimeUtils.getCurrentTime());
body.put("objectId", RandomStringUtil.randomString(20));
body.put("memberId", memberId);
body.put("receivableAmount", this.price);
JSONObject campInfo = new JSONObject();
campInfo.put("campId", campId);
body.put("camp", campInfo);
body.put("paymentWays", new JSONArray());//支付方式传空
xmAppApi.doRequest(RequestType.JSON, params, body.toString(), headers).assetsSuccess(true);
orderId = XMJSONPath.readPath(xmAppApi.getApi_response(), "$.result");
//报名成功后根据会员手机号,在报名会员列表搜索报名数据
trainingTools.getTrainingApplyRecordsList(this.campId, phone);
Assert.assertTrue(XMJSONPath.getJSONArrayByReadPath(dataApi.getApi_response(), "$.result").size() == 1, "给学员报名后,在报名列表没查询到数据");
//check订单 待支付状态
Assert.assertEquals(XMJSONPath.getJSONArrayByReadPath(dataApi.getApi_response(), "$.result").getJSONObject(0).getString("state"), "WAITING");
//删除训练营活动:该训练营已有人报名,无法删除!
trainingTools.delTrainingFail(this.campId);
Assert.assertEquals(XMJSONPath.readPath(dataApi.getApi_response(), "$.code"), "TRAINING_CAMP_DELETE_FAILED");
Assert.assertEquals(XMJSONPath.readPath(dataApi.getApi_response(), "$.message"), "该训练营已有人报名,无法删除!");
//操作取消订单
orderTools.cancel(orderId);
Thread.sleep(3000);
//再次报名该训练营活动-报名成功
trainingTools.doSignCampOrder(memberId, this.price, this.campId);
//报名成功后根据会员手机号,在报名会员列表搜索报名数据
trainingTools.getTrainingApplyRecordsList(this.campId, phone);
Assert.assertTrue(XMJSONPath.getJSONArrayByReadPath(dataApi.getApi_response(), "$.result").size() == 1, "给学员报名后,在报名列表没查询到数据");
Assert.assertEquals(XMJSONPath.getJSONArrayByReadPath(dataApi.getApi_response(), "$.result").getJSONObject(0).getString("state"), "PAID");
}
}
\ No newline at end of file
package com.xiaomai.cases.polar.training;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xiaomai.client.DataUserInfo;
import com.xiaomai.enums.ApiModule;
import com.xiaomai.enums.RequestType;
import com.xiaomai.enums.Terminal;
import com.xiaomai.utils.CommUtil;
import com.xiaomai.utils.RandomStringUtil;
import com.xiaomai.utils.XMBaseTest;
import com.xiaomai.utils.XMJSONPath;
import com.xiaomai.utils.*;
import org.springframework.stereotype.Component;
import org.testng.Assert;
......@@ -187,6 +185,20 @@ public class TrainingTools extends XMBaseTest {
}
/**
* 训练营活动有报名订单时操作删除时会删除失败,就用这个方法
* @param id
*/
public void delTrainingFail(String id) {
setUP("API_deleteTraining");
JSONObject body = new JSONObject();
body.put("operatorId", dataApi.getLoginInfo().getAdminId());
body.put("studioId", dataApi.getLoginInfo().getStudioId());
body.put("brandId", dataApi.getLoginInfo().getBrandId());
body.put("id", id);
dataApi.doRequest(RequestType.JSON, dataparams, body.toString(), dataheadrs).assetsSuccess(false);
}
/**
* 根据训练营活动名称全局搜索
*
* @param title 活动名称
......@@ -266,5 +278,139 @@ public class TrainingTools extends XMBaseTest {
}
/**
* 训练营详情:查看 报名会员
* @param trainingCampId 训练营ID
* @param content 根据手机号/会员姓名搜索
*/
public void getTrainingApplyRecordsList(String trainingCampId,String content){
setUP("API_getTrainingApplyRecordsList");
JSONObject body = new JSONObject();
body.put("operatorId", dataApi.getLoginInfo().getAdminId());
body.put("studioId", dataApi.getLoginInfo().getStudioId());
body.put("brandId", dataApi.getLoginInfo().getBrandId());
body.put("trainingCampId", trainingCampId);
if (null!=content||!content.isEmpty()){
body.put("content", content);
}
dataApi.doRequest(RequestType.JSON, dataparams, body.toString(), dataheadrs).assetsSuccess(true);
}
/**
* B 端操作:在训练营活动详情-报名学员-给学员报名
* @param memberId 会员ID
* @param receivableAmount 支付金额
* @param campId 训练营活动ID
*/
public void doSignCampOrder(String memberId,Double receivableAmount,String campId){
setUP("API_signOrderCamp");
JSONObject body = new JSONObject();
body.put("operatorId", dataApi.getLoginInfo().getAdminId());
body.put("studioId", dataApi.getLoginInfo().getStudioId());
body.put("brandId", dataApi.getLoginInfo().getBrandId());
body.put("salesmanId",dataApi.getLoginInfo().getAdminId());
body.put("operationTime", TimeUtils.getCurrentTime());
body.put("objectId", RandomStringUtil.randomString(20));
body.put("memberId", memberId);
body.put("receivableAmount", receivableAmount);
JSONObject campInfo = new JSONObject();
campInfo.put("campId",campId);
body.put("camp",campInfo);
JSONArray paymentWays=new JSONArray();
JSONObject payObject=new JSONObject();
payObject.put("amount",receivableAmount);
payObject.put("paymentWay","1");
payObject.put("voucherResourceIds",new JSONArray());
paymentWays.add(payObject);
body.put("paymentWays",paymentWays);
dataApi.doRequest(RequestType.JSON, dataparams, body.toString(), dataheadrs).assetsSuccess(true);
}
/**
*查看训练营活动-报名会员-报名详情
* @param trainingAccountId 即memberCardId,从查看报名会员列表返回数据中获取对应学员的报名数据(memberCardId)
*/
public void getTrainingAccountDetailById(String trainingAccountId){
setUP("API_getTrainingAccountDetailById");
JSONObject body = new JSONObject();
body.put("operatorId", dataApi.getLoginInfo().getAdminId());
body.put("studioId", dataApi.getLoginInfo().getStudioId());
body.put("brandId", dataApi.getLoginInfo().getBrandId());
body.put("id",trainingAccountId);
dataApi.doRequest(RequestType.JSON, dataparams, body.toString(), dataheadrs).assetsSuccess(true);
}
/**
* 退单训练营活动报名详情-退款
* @param memberId 会员ID
* @param refundAmount 退出金额
* @param memberCampId 会员的训练营账户ID
* @param quantity 退出购买数量
*/
public void refundCampOrder(String memberId,Double refundAmount,String memberCampId,int quantity){
setUP("API_refundCampOrder");
JSONObject body = new JSONObject();
body.put("operatorId", dataApi.getLoginInfo().getAdminId());
body.put("studioId", dataApi.getLoginInfo().getStudioId());
body.put("brandId", dataApi.getLoginInfo().getBrandId());
body.put("operationTime", TimeUtils.getCurrentTime());
body.put("objectId", RandomStringUtil.randomString(20));
body.put("memberId", memberId);
body.put("receivableAmount", refundAmount);
//退单内容
JSONObject campInfo = new JSONObject();
campInfo.put("memberCampId",memberCampId);
campInfo.put("giftQuantity",0);
campInfo.put("quantity",quantity);
campInfo.put("refundAmount",refundAmount);
body.put("camp",campInfo);
//结算方式
JSONArray paymentWays=new JSONArray();
JSONObject payObject=new JSONObject();
payObject.put("amount",refundAmount);
payObject.put("paymentWay","1");
payObject.put("voucherResourceIds",new JSONArray());
paymentWays.add(payObject);
body.put("paymentWays",paymentWays);
dataApi.doRequest(RequestType.JSON, dataparams, body.toString(), dataheadrs).assetsSuccess(true);
}
/**
* 根据会员姓名/手机号搜索会员
* @param content 手机号/姓名
* @return 返回搜索的的目标数据第一条的会员ID
*/
public String searchTargerMember(String content){
dataApi.setApiModule(ApiModule.Polar_Clue)
.setApiName("API_searchMember")
.setTerminal(Terminal.B);
super.beforeDataRequest();
JSONObject body = new JSONObject();
body.put("operatorId", dataApi.getLoginInfo().getAdminId());
body.put("studioId", dataApi.getLoginInfo().getStudioId());
body.put("brandId", dataApi.getLoginInfo().getBrandId());
body.put("content",content);
body.put("searchType","COMMON");
body.put("current",0);
body.put("size",20);
dataApi.doRequest(RequestType.JSON, dataparams, body.toString(), dataheadrs).assetsSuccess(true);
int tatal= XMJSONPath.getJSONArrayByReadPath(dataApi.getApi_response(),"$.result.records").size();
if(tatal>0){
return XMJSONPath.getJSONArrayByReadPath(dataApi.getApi_response(),"$.result.records").getJSONObject(0).getString("id");
}
return "";
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment