Scenario 1: 查看客戶詳情頁(含訂單歷史)
User Story: US-303: 客戶訂單歷史與統計
Given: 系統初始狀態
現有客戶資料
{
"id": "cust-001",
"customerNumber": "ABC-CUST-000001",
"name": "王小明",
"phone": "0912345678",
"tier": "vip",
"totalSpent": 8500,
"totalOrders": 12,
"lastOrderDate": "2025-10-31T10:00:00Z"
}
客戶訂單歷史(12 筆訂單)
[
{
"orderNumber": "ABC-20251031-0001",
"orderDate": "2025-10-31",
"totalAmount": 1200,
"status": "completed"
},
{
"orderNumber": "ABC-20251015-0005",
"orderDate": "2025-10-15",
"totalAmount": 800,
"status": "completed"
}
// ... 共 12 筆
]
When: 執行操作
API 請求 1: 獲取客戶詳情
GET /api/v1/customers/cust-001
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
API 請求 2: 獲取訂單歷史(最近 10 筆)
GET /api/v1/customers/cust-001/orders?limit=10&page=1
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
Then: 預期結果
1. 客戶詳情響應
{
"id": "cust-001",
"customerNumber": "ABC-CUST-000001",
"type": "individual",
"name": "王小明",
"phone": "0912345678",
"email": "wang@example.com",
"status": "active",
"tier": "vip",
"totalSpent": 8500,
"totalOrders": 12,
"averageOrderAmount": 708,
"lastOrderDate": "2025-10-31T10:00:00Z",
"createdAt": "2025-01-15T10:00:00Z"
}
2. 訂單歷史響應(最近 10 筆)
{
"orders": [
{
"id": "order-012",
"orderNumber": "ABC-20251031-0001",
"orderDate": "2025-10-31T10:00:00Z",
"totalAmount": 1200,
"status": "completed",
"deliveryDate": "2025-11-01"
},
{
"id": "order-011",
"orderNumber": "ABC-20251015-0005",
"orderDate": "2025-10-15T10:00:00Z",
"totalAmount": 800,
"status": "completed",
"deliveryDate": "2025-10-16"
}
// ... 共 10 筆
],
"pagination": {
"page": 1,
"limit": 10,
"totalPages": 2,
"totalItems": 12
}
}
3. 業務規則驗證
✅ 客戶等級計算
- 累計消費: $8,500
- 等級: VIP(>= $5,000)
✅ 平均訂單金額計算
- 累計消費: $8,500
- 已完成訂單數: 12
- 平均金額: $708($8,500 / 12)
✅ 訂單歷史顯示
- 預設顯示: 最近 10 筆
- 排序: 依訂單日期降序
- 狀態: 包含所有狀態(已完成/進行中/已取消)
驗證重點
- 客戶詳情正確顯示
- 客戶等級計算正確
- 平均訂單金額計算正確
- 訂單歷史列表正確(最近 10 筆)
- 分頁資訊正確