fix(优惠券中心)

This commit is contained in:
2025-09-02 17:40:31 +08:00
parent 41a471de37
commit ee78b4030e
10 changed files with 2098 additions and 0 deletions
@@ -0,0 +1,240 @@
# 优惠券核销流程测试用例
## 测试目标
验证优惠券核销成功后,能够正确更新订单中心订单状态为"已支付"。
## 测试环境
- 优惠券中心服务:`coupon-center`
- 订单中心服务:`order-center`
- 数据库:MySQL
## 测试步骤
### 1. 准备测试数据
#### 1.1 创建订单中心订单
```sql
-- 在订单中心数据库中创建测试订单
INSERT INTO orders (
order_no, user_id, tourism_id, order_amount, order_status,
pay_type, code_id, device_sn, tenant_id, create_time, update_time
) VALUES (
'TEST_ORDER_001', 1, 1, '9990', 0, -- 0表示待支付
1, 'test-code-id', 'TEST_DEVICE_001', 'test-tenant',
NOW(), NOW()
);
```
#### 1.2 创建携程订单(不关联订单号)
```sql
-- 在优惠券中心数据库中创建携程订单
INSERT INTO t_ctrip_order (
ota_order_id, supplier_order_id, sequence_id, status,
total_amount, currency, create_time, update_time
) VALUES (
'ctriptest-test-001', 'SUPPLIER_test_001', 'test-sequence-001', 13, -- 13表示支付已确认
99.90, 'CNY', NOW(), NOW()
);
```
### 2. 测试场景
#### 场景1:核销时传入orderNo,建立关联关系
**请求:**
```bash
curl -X POST http://localhost:8002/api-coupon/api/order-detail/consume-simple \
-H "Content-Type: application/json" \
-d '{
"otaOrderId": "ctriptest-test-001",
"orderNo": "TEST_ORDER_001",
"itemId": "test-item-001",
"useQuantity": 1,
"remark": "测试核销"
}'
```
**预期结果:**
1. 核销成功,返回 `{"resp_code": 0, "resp_msg": "核销成功", "data": true}`
2. 携程订单状态更新为已使用(状态8)
3. 携程订单的 `order_no` 字段被设置为 `TEST_ORDER_001`
4. 订单中心订单状态更新为已支付(状态1)
5. 订单中心订单的 `pay_type` 字段被设置为优惠券支付(类型2)
**验证SQL:**
```sql
-- 验证携程订单状态和关联关系
SELECT ota_order_id, order_no, status FROM t_ctrip_order WHERE ota_order_id = 'ctriptest-test-001';
-- 验证订单中心订单状态
SELECT order_no, order_status, pay_type, pay_time FROM orders WHERE order_no = 'TEST_ORDER_001';
```
#### 场景2:核销时未传入orderNo
**请求:**
```bash
curl -X POST http://localhost:8002/api-coupon/api/order-detail/consume-simple \
-H "Content-Type: application/json" \
-d '{
"otaOrderId": "ctriptest-test-002",
"itemId": "test-item-002",
"useQuantity": 1,
"remark": "测试核销(无关联)"
}'
```
**预期结果:**
1. 核销成功,返回 `{"resp_code": 0, "resp_msg": "核销成功", "data": true}`
2. 携程订单状态更新为已使用(状态8)
3. 携程订单的 `order_no` 字段为空
4. 不会调用订单中心接口更新状态
5. 日志中显示:`携程订单未关联订单中心订单号,无法更新订单状态`
#### 场景3:核销已关联的订单
**请求:**
```bash
curl -X POST http://localhost:8002/api-coupon/api/order-detail/consume-simple \
-H "Content-Type: application/json" \
-d '{
"otaOrderId": "ctriptest-test-001",
"orderNo": "TEST_ORDER_002", -- 传入不同的订单号
"itemId": "test-item-003",
"useQuantity": 1,
"remark": "测试核销(已关联)"
}'
```
**预期结果:**
1. 核销成功
2. 日志中显示:`订单关联关系不匹配,数据库orderNo: TEST_ORDER_001, 前端orderNo: TEST_ORDER_002`
3. 不会更新关联关系,继续使用原有的 `TEST_ORDER_001`
4. 订单中心订单状态正常更新
### 3. 日志验证
#### 3.1 成功核销日志
```
简化核销订单,订单号: ctriptest-test-001, 商品ID: test-item-001, 数量: 1, 关联订单号: TEST_ORDER_001
建立订单关联关系,otaOrderId: ctriptest-test-001, orderNo: TEST_ORDER_001
开始执行核销订单,otaOrderId: ctriptest-test-001, itemId: test-item-001, useQuantity: 1
订单状态更新为已使用,otaOrderId: ctriptest-test-001, totalUseQuantity: 1
开始更新订单中心订单状态,orderNo: TEST_ORDER_001
订单中心订单状态更新成功,orderNo: TEST_ORDER_001
核销成功,订单号: ctriptest-test-001, 关联订单号: TEST_ORDER_001
```
#### 3.2 无关联订单日志
```
简化核销订单,订单号: ctriptest-test-002, 商品ID: test-item-002, 数量: 1, 关联订单号: null
开始执行核销订单,otaOrderId: ctriptest-test-002, itemId: test-item-002, useQuantity: 1
订单状态更新为已使用,otaOrderId: ctriptest-test-002, totalUseQuantity: 1
携程订单未关联订单中心订单号,无法更新订单状态,otaOrderId: ctriptest-test-002
核销成功,订单号: ctriptest-test-002, 关联订单号: null
```
### 4. 异常场景测试
#### 4.1 订单不存在
**请求:**
```bash
curl -X POST http://localhost:8002/api-coupon/api/order-detail/consume-simple \
-H "Content-Type: application/json" \
-d '{
"otaOrderId": "non-existent-order",
"itemId": "test-item-001",
"useQuantity": 1
}'
```
**预期结果:**
- 返回错误:`{"resp_code": -1, "resp_msg": "订单不存在"}`
#### 4.2 订单中心接口调用失败
**模拟场景:** 订单中心服务不可用
**预期结果:**
- 核销成功
- 日志显示:`订单中心订单状态更新失败,orderNo: TEST_ORDER_001, result: null`
- 不影响核销流程
#### 4.3 订单状态不正确
**模拟场景:** 订单中心订单状态不是待支付(状态0)
**预期结果:**
- 订单中心接口返回:`订单状态不正确,无法更新为已支付`
- 不影响核销流程
### 5. 性能测试
#### 5.1 并发核销测试
```bash
# 使用Apache Bench进行并发测试
ab -n 100 -c 10 -p test_data.json -T application/json \
http://localhost:8002/api-coupon/api/order-detail/consume-simple
```
**预期结果:**
- 所有请求成功处理
- 无数据竞争问题
- 订单状态正确更新
### 6. 数据一致性验证
#### 6.1 事务回滚测试
**模拟场景:** 在核销过程中发生异常
**预期结果:**
- 携程订单状态回滚
- 核销记录回滚
- 订单中心状态不更新
#### 6.2 幂等性测试
**操作:** 对同一订单多次核销
**预期结果:**
- 第一次核销成功
- 后续核销返回已核销状态
- 订单中心状态只更新一次
## 测试报告模板
### 测试结果汇总
| 测试场景 | 预期结果 | 实际结果 | 状态 |
|----------|----------|----------|------|
| 场景1:传入orderNo | 核销成功,状态更新 | | |
| 场景2:未传入orderNo | 核销成功,无状态更新 | | |
| 场景3:已关联订单 | 核销成功,使用原关联 | | |
| 异常场景1:订单不存在 | 返回错误 | | |
| 异常场景2:接口调用失败 | 核销成功,状态更新失败 | | |
| 异常场景3:状态不正确 | 核销成功,状态更新失败 | | |
| 性能测试:并发核销 | 100%成功率 | | |
| 数据一致性:事务回滚 | 数据回滚正确 | | |
| 数据一致性:幂等性 | 幂等性正确 | | |
### 问题记录
| 问题描述 | 严重程度 | 状态 | 备注 |
|----------|----------|------|------|
| | | | |
### 测试结论
- [ ] 所有测试场景通过
- [ ] 性能满足要求
- [ ] 数据一致性正确
- [ ] 异常处理完善
- [ ] 日志记录完整
## 部署验证清单
- [ ] 数据库表结构已更新(添加 `order_no` 字段)
- [ ] 优惠券中心服务已部署
- [ ] 订单中心服务已部署
- [ ] Feign客户端配置正确
- [ ] 日志级别配置正确
- [ ] 监控告警配置正确