feat: 支持采购任务追溯并安全重新创建 (#186)
This commit is contained in:
@@ -44,7 +44,9 @@ type testTaskParams struct {
|
||||
taskType model.TaskType
|
||||
status model.TaskStatus
|
||||
assignedClient string
|
||||
sybID string
|
||||
orderNo string
|
||||
goodsID string
|
||||
pddGoodsID string
|
||||
pddOptions string
|
||||
quantity int
|
||||
@@ -61,13 +63,19 @@ func insertTestTask(t *testing.T, db *sql.DB, p testTaskParams) {
|
||||
t.Helper()
|
||||
now := model.NowISO()
|
||||
|
||||
var assigned, orderNo, pddGoodsID, pddOptions, errCode, errMsg, resultData, claimedAt, finishedAt any
|
||||
var assigned, sybID, orderNo, goodsID, pddGoodsID, pddOptions, errCode, errMsg, resultData, claimedAt, finishedAt any
|
||||
if p.assignedClient != "" {
|
||||
assigned = p.assignedClient
|
||||
}
|
||||
if p.orderNo != "" {
|
||||
orderNo = p.orderNo
|
||||
}
|
||||
if p.sybID != "" {
|
||||
sybID = p.sybID
|
||||
}
|
||||
if p.goodsID != "" {
|
||||
goodsID = p.goodsID
|
||||
}
|
||||
if p.pddGoodsID != "" {
|
||||
pddGoodsID = p.pddGoodsID
|
||||
}
|
||||
@@ -100,14 +108,14 @@ func insertTestTask(t *testing.T, db *sql.DB, p testTaskParams) {
|
||||
|
||||
_, err := db.Exec(`
|
||||
INSERT INTO tasks (task_id, task_type, status, assigned_client, claimed_at,
|
||||
order_no, pdd_goods_url, pdd_goods_id, pdd_options,
|
||||
syb_id, order_no, goods_id, pdd_goods_url, pdd_goods_id, pdd_options,
|
||||
quantity, max_price_cent,
|
||||
error_code, error_message, result_data, finished_at, created_by_user_id,
|
||||
created_at, updated_at)
|
||||
VALUES (?, ?, ?, ?, ?, ?, 'https://mobile.yangkeduo.com/goods.html?goods_id=1', ?, ?,
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, 'https://mobile.yangkeduo.com/goods.html?goods_id=1', ?, ?,
|
||||
?, ?, ?, ?, ?, ?, ?, ?, ?)`,
|
||||
p.taskID, string(p.taskType), string(p.status), assigned, claimedAt,
|
||||
orderNo, pddGoodsID, pddOptions,
|
||||
sybID, orderNo, goodsID, pddGoodsID, pddOptions,
|
||||
quantity, maxPrice,
|
||||
errCode, errMsg, resultData, finishedAt, nullableString(p.createdByUserID),
|
||||
now, now)
|
||||
@@ -425,8 +433,9 @@ func TestGetTaskDetail_采购任务显示专有字段(t *testing.T) {
|
||||
db := newTestDB(t)
|
||||
insertTestTask(t, db, testTaskParams{
|
||||
taskID: "PUR-1", taskType: model.TaskPurchase, status: model.TaskClaimed,
|
||||
orderNo: "SO-001", pddOptions: `{"color":"黑色","size":"M"}`,
|
||||
quantity: 2, maxPriceCent: 4200, assignedClient: "client-001",
|
||||
sybID: "SYB-001", orderNo: "SO-001", goodsID: "SHOPEE-001", pddGoodsID: "PDD-001",
|
||||
pddOptions: `{"color":"黑色","size":"M"}`,
|
||||
quantity: 2, maxPriceCent: 4200, assignedClient: "client-001",
|
||||
claimedAt: model.NowISO(),
|
||||
})
|
||||
|
||||
@@ -446,6 +455,40 @@ func TestGetTaskDetail_采购任务显示专有字段(t *testing.T) {
|
||||
if d.ClientText != "client-001" {
|
||||
t.Errorf("分配客户端 = %q, want client-001", d.ClientText)
|
||||
}
|
||||
if d.ShopeeOrderNo != "SO-001" || d.SybID != "SYB-001" ||
|
||||
d.ShopeeGoodsID != "SHOPEE-001" || d.PddGoodsID != "PDD-001" || !d.HasSybSource {
|
||||
t.Errorf("采购来源字段不完整: %+v", d)
|
||||
}
|
||||
if d.ViewSybURL != "/syb?open_syb_id=SYB-001&order_no=SO-001" || d.CanRecreatePurchase || d.RecreatePurchaseURL != "" {
|
||||
t.Errorf("执行中的采购任务只应允许查看来源: view=%q recreate=%t url=%q",
|
||||
d.ViewSybURL, d.CanRecreatePurchase, d.RecreatePurchaseURL)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetTaskDetail_只有失败和取消允许进入重新创建确认(t *testing.T) {
|
||||
db := newTestDB(t)
|
||||
statuses := []model.TaskStatus{
|
||||
model.TaskPending, model.TaskAssigned, model.TaskClaimed, model.TaskSucceeded,
|
||||
model.TaskManualReview, model.TaskFailed, model.TaskCancelled,
|
||||
}
|
||||
for _, status := range statuses {
|
||||
taskID := "PUR-" + string(status)
|
||||
insertTestTask(t, db, testTaskParams{
|
||||
taskID: taskID, taskType: model.TaskPurchase, status: status,
|
||||
sybID: "SYB A&B", orderNo: "ORDER/1", goodsID: "SHOPEE-1", pddGoodsID: "PDD-1",
|
||||
})
|
||||
detail, err := GetTaskDetail(db, taskID)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
want := status == model.TaskFailed || status == model.TaskCancelled
|
||||
if detail.CanRecreatePurchase != want {
|
||||
t.Errorf("状态 %s CanRecreatePurchase=%t,want %t", status, detail.CanRecreatePurchase, want)
|
||||
}
|
||||
if want && detail.RecreatePurchaseURL != "/syb?open_syb_id=SYB+A%26B&order_no=ORDER%2F1&purchase_intent=1" {
|
||||
t.Errorf("状态 %s 的深链接编码错误: %q", status, detail.RecreatePurchaseURL)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetTaskDetail_采购成功独立显示PDD核单结果(t *testing.T) {
|
||||
@@ -525,6 +568,9 @@ func TestGetTaskDetail_采集任务不带采购专有字段(t *testing.T) {
|
||||
if d.HasPddOrder || d.PddOrderResultText != "" {
|
||||
t.Error("采集任务不应生成 PDD 核单结果展示")
|
||||
}
|
||||
if d.HasSybSource || d.ShopeeOrderNo != "" || d.CanRecreatePurchase {
|
||||
t.Error("采集任务不应生成采购来源和重新创建入口")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetTaskDetail_有错误信息时显示(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user