把卡密自动发货从 engine.DeliveryService 收敛到统一的 automation.Center: WS 事件/计划任务/手动触发统一为 Task,trigger_key 持久化防重,付款发货、 评价赠品、超时求评价共用一套规则+动作编排。新增 internal/automation 包、 db.AutomationRules repository、00007 迁移。 同步删除被取代的并行死系统: - engine.DeliveryService + delivery_test.go(已无引用) - db.DeliveryRules/DeliveryRule + 3 个 Match 方法(生产零调用) - card_handlers 的 /delivery-rules CRUD(前端早已只走 automation-rules) - engine.SystemMessage + extractSystemMessage(dispatch 不再单独路由 message["3"]) - store.DeliveryRules 字段、Cards.IncrementDeliveryTimes - 00008 迁移 DROP delivery_rules/delivery_rule_variants + email_verifications/ captcha_codes/ai_item_cache/risk_control_logs + publish 批次 3 个死列 - isAPIPath 清理 ~15 个未挂载的前缀,stub_handlers.go 内联删除 - vite.config 删 /delivery-rules proxy 其它:orders.Upsert 注释改为诚实描述(version 列不参与并发控制); dispatch.cleanupDedupLocked 用 sort.Slice 取代 O(n²) 选择排序; 删自定义 min 用内置;deliveryRuleItemOwned 改名 itemOwnedByUser。 Co-Authored-By: Claude Opus 4.8 <[email protected]>
76 lines
2.4 KiB
Go
76 lines
2.4 KiB
Go
package automation
|
|
|
|
import (
|
|
"encoding/json"
|
|
"testing"
|
|
)
|
|
|
|
func TestExtractTaskFromWS_BuyerReviewed(t *testing.T) {
|
|
raw := mustMap(t, `{
|
|
"1": {
|
|
"2": "62904549781@goofish",
|
|
"10": {
|
|
"redReminder": "有新交易评价",
|
|
"reminderContent": "[我完成了评价]",
|
|
"reminderTitle": "我完成了评价",
|
|
"senderUserId": "2222315258815",
|
|
"reminderUrl": "fleamarket://message_chat?itemId=1063217820795&peerUserId=2222315258815&sid=62904549781&messageId=abc&adv=no",
|
|
"extJson": "{\"updateKey\":\"62904549781:3310145690545023994:10:BUYER_RATE_SELLER:26\",\"contentType\":\"26\"}"
|
|
}
|
|
}
|
|
}`)
|
|
task := ExtractTaskFromWS("acc1", "cookie", raw)
|
|
if task == nil {
|
|
t.Fatal("评价卡片应解析为自动化事件")
|
|
}
|
|
if task.TriggerType != TriggerBuyerReviewed || task.OrderID != "3310145690545023994" ||
|
|
task.ChatID != "62904549781" || task.ItemID != "1063217820795" || task.BuyerID != "2222315258815" {
|
|
t.Fatalf("task=%+v", task)
|
|
}
|
|
}
|
|
|
|
func TestExtractTaskFromWS_ServiceReviewInvitationIgnored(t *testing.T) {
|
|
raw := mustMap(t, `{
|
|
"1": {
|
|
"2": "62854995941@goofish",
|
|
"10": {
|
|
"reminderContent": "为了给您提供更好的服务,诚邀您参与服务评价>>",
|
|
"reminderTitle": "闲小蜜发来一条新消息",
|
|
"senderUserId": "1400",
|
|
"extJson": "{\"messageId\":\"e5e96\"}"
|
|
}
|
|
}
|
|
}`)
|
|
if task := ExtractTaskFromWS("acc1", "cookie", raw); task != nil {
|
|
t.Fatalf("服务评价邀请不能触发买家评价赠品: %+v", task)
|
|
}
|
|
}
|
|
|
|
func TestExtractTaskFromWS_OrderPaid(t *testing.T) {
|
|
raw := mustMap(t, `{
|
|
"1": {
|
|
"2": "63107041124@goofish",
|
|
"10": {
|
|
"redReminder": "等待卖家发货",
|
|
"reminderContent": "[我已付款,等待你发货]",
|
|
"senderUserId": "2222315258815",
|
|
"reminderUrl": "fleamarket://message_chat?itemId=1063177864132&peerUserId=2222315258815&sid=63107041124"
|
|
},
|
|
"6": {"3": {"5": "{\"dxCard\":{\"item\":{\"main\":{\"targetUrl\":\"fleamarket://order_detail?id=3310145690545023994&role=seller\"}}}}"}}
|
|
}
|
|
}`)
|
|
task := ExtractTaskFromWS("acc1", "cookie", raw)
|
|
if task == nil || task.TriggerType != TriggerOrderPaid || task.OrderID != "3310145690545023994" {
|
|
t.Fatalf("task=%+v", task)
|
|
}
|
|
}
|
|
|
|
func mustMap(t *testing.T, s string) map[string]any {
|
|
t.Helper()
|
|
var m map[string]any
|
|
if err := json.Unmarshal([]byte(s), &m); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
return m
|
|
}
|