You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
219 lines
8.7 KiB
219 lines
8.7 KiB
package com.ouxuan.oxface;
|
|
|
|
import org.junit.Test;
|
|
import static org.junit.Assert.*;
|
|
|
|
import com.google.gson.Gson;
|
|
import com.google.gson.JsonParser;
|
|
import com.google.gson.JsonObject;
|
|
import com.google.gson.JsonElement;
|
|
import com.ouxuan.oxface.network.api.PadApiService;
|
|
|
|
/**
|
|
* 订单核销结果测试
|
|
* 测试不同订单类型的数据解析和显示逻辑
|
|
*/
|
|
public class OrderVerificationResultTest {
|
|
|
|
private Gson gson = new Gson();
|
|
|
|
/**
|
|
* 测试次卡核销数据解析(order_type=1)
|
|
* info 字段为字符串类型
|
|
*/
|
|
@Test
|
|
public void testPeopleCardVerification() {
|
|
// 模拟次卡核销的服务器响应
|
|
String jsonResponse = "{\n" +
|
|
" \"code\": 0,\n" +
|
|
" \"data\": {\n" +
|
|
" \"avatar_url\": \"https://imgcdn.ouxuanzhineng.cn/upload/user_avatar_img/aa2c59a8922fdd00a9909156a7265d3d.jpeg\",\n" +
|
|
" \"nickname\": \"mingtao\",\n" +
|
|
" \"result\": {\n" +
|
|
" \"order_no\": \"RC20250910155115457419\",\n" +
|
|
" \"start_time\": \"2025-09-10 15:51:16\",\n" +
|
|
" \"end_time\": \"4763-08-07 15:51:16\",\n" +
|
|
" \"order_type\": 1,\n" +
|
|
" \"project\": \"20230727测试\",\n" +
|
|
" \"number\": 1,\n" +
|
|
" \"v_code\": [\"250910159819\"],\n" +
|
|
" \"info\": \"平时\",\n" +
|
|
" \"success\": 0,\n" +
|
|
" \"pv_usage_duration\": 1,\n" +
|
|
" \"many_enter\": false\n" +
|
|
" }\n" +
|
|
" },\n" +
|
|
" \"message\": \"\",\n" +
|
|
" \"extension\": \"extension_fixed\"\n" +
|
|
"}";
|
|
|
|
try {
|
|
PadApiService.VerifyOrderResponse response = gson.fromJson(jsonResponse, PadApiService.VerifyOrderResponse.class);
|
|
|
|
assertNotNull("响应不应该为空", response);
|
|
assertNotNull("结果不应该为空", response.getResult());
|
|
assertEquals("订单类型应该是1", 1, response.getResult().getOrderType());
|
|
assertEquals("订单号应该匹配", "RC20250910155115457419", response.getResult().getOrderNo());
|
|
|
|
// 验证info字段可以被正确解析为字符串
|
|
JsonElement infoElement = response.getResult().getInfo();
|
|
|
|
// 对于次卡类型,info应该是字符串
|
|
if (response.getResult().getOrderType() == 1 && infoElement != null && infoElement.isJsonPrimitive()) {
|
|
String bookingInfo = infoElement.getAsString();
|
|
assertEquals("预订信息应该是'平时'", "平时", bookingInfo);
|
|
|
|
// 测试辅助方法
|
|
assertEquals("平时", response.getResult().getInfoAsString());
|
|
}
|
|
|
|
System.out.println("次卡核销测试通过: " + response.getResult().getOrderNo());
|
|
|
|
} catch (Exception e) {
|
|
fail("次卡核销数据解析失败: " + e.getMessage());
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 测试年月卡核销数据解析(order_type=3)
|
|
* info 字段为对象类型
|
|
*/
|
|
@Test
|
|
public void testMonthlyCardVerification() {
|
|
// 模拟年月卡核销的服务器响应
|
|
String jsonResponse = "{\n" +
|
|
" \"code\": 0,\n" +
|
|
" \"data\": {\n" +
|
|
" \"avatar_url\": \"https://imgcdn.ouxuanzhineng.cn/upload/user_avatar_img/aa2c59a8922fdd00a9909156a7265d3d.jpeg\",\n" +
|
|
" \"nickname\": \"mingtao\",\n" +
|
|
" \"result\": {\n" +
|
|
" \"order_no\": \"MC20250908145253448493\",\n" +
|
|
" \"start_time\": \"2025-09-08 14:52:59\",\n" +
|
|
" \"end_time\": \"2025-10-08 14:52:59\",\n" +
|
|
" \"order_type\": 3,\n" +
|
|
" \"project\": \"可多次进出\",\n" +
|
|
" \"number\": 7,\n" +
|
|
" \"v_code\": [\"2509087910\"],\n" +
|
|
" \"info\": {\n" +
|
|
" \"card_no\": \"2509085314\",\n" +
|
|
" \"rest_number\": 5,\n" +
|
|
" \"status\": 1,\n" +
|
|
" \"verify_desc\": \"人脸验证(pad: 乐动退回pad(第6批)+pad_ab)\",\n" +
|
|
" \"verify_time\": \"2025-09-10 11:26:36\",\n" +
|
|
" \"verify_type\": 2\n" +
|
|
" },\n" +
|
|
" \"success\": 2,\n" +
|
|
" \"pv_usage_duration\": 0,\n" +
|
|
" \"many_enter\": false\n" +
|
|
" }\n" +
|
|
" },\n" +
|
|
" \"message\": \"\",\n" +
|
|
" \"extension\": \"过滤后端调试extension\"\n" +
|
|
"}";
|
|
|
|
try {
|
|
PadApiService.VerifyOrderResponse response = gson.fromJson(jsonResponse, PadApiService.VerifyOrderResponse.class);
|
|
|
|
assertNotNull("响应不应该为空", response);
|
|
assertNotNull("结果不应该为空", response.getResult());
|
|
assertEquals("订单类型应该是3", 3, response.getResult().getOrderType());
|
|
assertEquals("订单号应该匹配", "MC20250908145253448493", response.getResult().getOrderNo());
|
|
|
|
// 验证info字段可以被正确解析为对象
|
|
JsonElement infoElement = response.getResult().getInfo();
|
|
|
|
// 对于年月卡类型,info应该是对象
|
|
if (response.getResult().getOrderType() == 3 && infoElement != null && infoElement.isJsonObject()) {
|
|
JsonObject cardInfo = infoElement.getAsJsonObject();
|
|
|
|
assertTrue("应该包含card_no字段", cardInfo.has("card_no"));
|
|
assertTrue("应该包含verify_desc字段", cardInfo.has("verify_desc"));
|
|
assertTrue("应该包含verify_time字段", cardInfo.has("verify_time"));
|
|
|
|
assertEquals("卡号应该匹配", "2509085314", cardInfo.get("card_no").getAsString());
|
|
assertEquals("剩余次数应该是5", 5, cardInfo.get("rest_number").getAsInt());
|
|
|
|
// 测试辅助方法
|
|
assertEquals("2509085314", response.getResult().getCardNoFromInfo());
|
|
assertNotNull(response.getResult().getInfoAsJsonObject());
|
|
}
|
|
|
|
System.out.println("年月卡核销测试通过: " + response.getResult().getOrderNo());
|
|
|
|
} catch (Exception e) {
|
|
fail("年月卡核销数据解析失败: " + e.getMessage());
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 测试订单类型名称转换
|
|
*/
|
|
@Test
|
|
public void testOrderTypeNameConversion() {
|
|
assertEquals("场次", getOrderTypeName(0));
|
|
assertEquals("人次", getOrderTypeName(1));
|
|
assertEquals("年月卡", getOrderTypeName(3));
|
|
assertEquals("课程", getOrderTypeName(5));
|
|
assertEquals("orderType:99", getOrderTypeName(99));
|
|
}
|
|
|
|
/**
|
|
* 模拟OrderVerificationResultActivity中的getOrderTypeName方法
|
|
*/
|
|
private String getOrderTypeName(int orderType) {
|
|
switch (orderType) {
|
|
case 0:
|
|
return "场次";
|
|
case 1:
|
|
return "人次";
|
|
case 3:
|
|
return "年月卡";
|
|
case 5:
|
|
return "课程";
|
|
default:
|
|
return "orderType:" + orderType;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 测试验证码格式化
|
|
*/
|
|
@Test
|
|
public void testVerificationCodeFormatting() {
|
|
assertEquals("-", formatVerificationCode(null));
|
|
assertEquals("-", formatVerificationCode(""));
|
|
assertEquals("123456", formatVerificationCode("123456"));
|
|
assertEquals("250910159819", formatVerificationCode("250910159819"));
|
|
}
|
|
|
|
/**
|
|
* 模拟OrderVerificationResultActivity中的formatVerificationCode方法
|
|
*/
|
|
private String formatVerificationCode(String code) {
|
|
if (code == null || code.isEmpty()) {
|
|
return "-";
|
|
}
|
|
return code;
|
|
}
|
|
|
|
/**
|
|
* 测试使用时长格式化
|
|
*/
|
|
@Test
|
|
public void testUsageDurationFormatting() {
|
|
assertEquals("无限制", formatUsageDuration(0));
|
|
assertEquals("无限制", formatUsageDuration(-1));
|
|
assertEquals("1小时到期", formatUsageDuration(1));
|
|
assertEquals("24小时到期", formatUsageDuration(24));
|
|
}
|
|
|
|
/**
|
|
* 模拟OrderVerificationResultActivity中的formatUsageDuration方法
|
|
*/
|
|
private String formatUsageDuration(int duration) {
|
|
if (duration <= 0) {
|
|
return "无限制";
|
|
}
|
|
return duration + "小时到期";
|
|
}
|
|
}
|