Files
FlashSaleSystem/购物模块下单测试流程.md
2025-07-02 22:39:21 +08:00

251 lines
4.2 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 购物模块下单测试流程
本文档描述完整的购物车下单、支付、发货、确认收货流程的API测试步骤。
## 前置条件
1. 启动应用:`mvn spring-boot:run`
2. 应用访问地址http://localhost:8080
3. API文档地址http://localhost:8080/doc.html
4. 确保用户已登录并有有效session
## 完整下单流程测试
### 1. 添加商品到购物车
```bash
POST /api/cart/add
Content-Type: application/json
{
"productId": 1,
"quantity": 2
}
```
**响应示例:**
```json
{
"success": true,
"message": "商品添加到购物车成功",
"data": {
"userId": 1,
"items": [
{
"productId": 1,
"productName": "iPhone 15",
"productPrice": 5999.00,
"quantity": 2,
"subtotal": 11998.00,
"stock": 100
}
],
"totalPrice": 11998.00,
"totalQuantity": 2
}
}
```
### 2. 查看购物车
```bash
GET /api/cart
```
### 3. 购物车下单
```bash
POST /api/cart/checkout
Content-Type: application/json
{
"productIds": [1] // 可选,不传则下单所有商品
}
```
**响应示例:**
```json
{
"success": true,
"message": "下单成功,请及时支付",
"data": {
"id": 10,
"userId": 1,
"productId": 1,
"productName": "iPhone 15",
"quantity": 2,
"totalPrice": 11998.00,
"status": 1,
"statusDescription": "待支付",
"orderType": 1,
"orderTypeDescription": "普通订单",
"createdAt": "2025-07-02 21:45:00"
}
}
```
### 4. 模拟支付
```bash
POST /api/order/{orderId}/pay
Content-Type: application/json
{
"paymentMethod": "支付宝" // 可选:支付宝、微信、银行卡等
}
```
**响应示例:**
```json
{
"success": true,
"message": "支付成功",
"data": {
"id": 10,
"status": 2,
"statusDescription": "已支付",
"updatedAt": "2025-07-02 21:46:00"
},
"paymentMethod": "支付宝"
}
```
### 5. 模拟发货(商家操作)
```bash
POST /api/order/{orderId}/ship
```
**响应示例:**
```json
{
"success": true,
"message": "订单发货成功",
"data": {
"id": 10,
"status": 3,
"statusDescription": "已发货",
"updatedAt": "2025-07-02 21:47:00"
}
}
```
### 6. 确认收货(用户操作)
```bash
POST /api/order/{orderId}/confirm
```
**响应示例:**
```json
{
"success": true,
"message": "确认收货成功,订单已完成",
"data": {
"id": 10,
"status": 4,
"statusDescription": "已完成",
"updatedAt": "2025-07-02 21:48:00"
}
}
```
### 7. 查看订单详情
```bash
GET /api/order/{orderId}
```
### 8. 查看我的订单列表
```bash
POST /api/order/my-orders
Content-Type: application/json
{
"page": 0,
"size": 10,
"status": null // 可选1-待支付, 2-已支付, 3-已发货, 4-已完成, 5-已取消
}
```
## 订单状态流转
```
1. 待支付 (status=1)
↓ [用户支付]
2. 已支付 (status=2)
↓ [商家发货]
3. 已发货 (status=3)
↓ [用户确认收货]
4. 已完成 (status=4)
```
## 异常情况测试
### 1. 支付失败1%概率)
- 重新调用支付接口
- 或取消订单
### 2. 库存不足
```bash
POST /api/cart/add
{
"productId": 1,
"quantity": 999999 // 超过库存
}
```
### 3. 重复支付
- 对已支付订单再次支付,应返回错误
### 4. 状态不正确的操作
- 对待支付订单直接发货
- 对待发货订单直接确认收货
## 额外功能
### 取消订单
```bash
POST /api/order/{orderId}/cancel
```
### 批量购物车操作
```bash
POST /api/cart/batch-operation
{
"operation": "remove", // 或 "clear"
"productIds": [1, 2, 3]
}
```
### 检查购物车库存
```bash
GET /api/cart/check-stock
```
## 测试建议
1. **完整流程测试**按照1-6步骤完整测试一次下单流程
2. **并发测试**:多个用户同时下单同一商品测试库存控制
3. **异常测试**:测试各种异常情况的处理
4. **性能测试**使用JMeter等工具进行压力测试
## 注意事项
1. 所有需要用户认证的接口都需要先登录获取session
2. 支付接口有1秒的模拟延迟和1%的失败率
3. 购物车数据存储在Redis中有7天过期时间
4. 订单状态变更会自动记录时间戳