feat: 展示任务PDD店铺和客户端名称 (#158)
This commit is contained in:
@@ -285,6 +285,76 @@ func TestListTasksView_无主任务客户端列显示占位符(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestListTasksView_显示PDD店铺和客户端名称并保留ID提示(t *testing.T) {
|
||||
db := newTestDB(t)
|
||||
now := model.NowISO()
|
||||
if _, err := db.Exec(`
|
||||
INSERT INTO pdd_products (goods_id, url, title, shop_name, collect_status, created_at, updated_at)
|
||||
VALUES ('737116531267', 'https://mobile.yangkeduo.com/goods.html?goods_id=737116531267',
|
||||
'测试商品', '测试旗舰店', 'collected', ?, ?)`, now, now); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := db.Exec(`
|
||||
INSERT INTO clients (client_id, name, last_seen_at, created_at, updated_at)
|
||||
VALUES ('client-001', '办公室手机', ?, ?, ?)`, now, now, now); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
insertTestTask(t, db, testTaskParams{
|
||||
taskID: "COL-SHOP", taskType: model.TaskCollect, status: model.TaskAssigned,
|
||||
pddGoodsID: "737116531267", assignedClient: "client-001",
|
||||
})
|
||||
|
||||
r, err := ListTasksView(db, repository.TaskFilter{}, 1)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(r.Rows) != 1 || r.Rows[0].PddShopText != "测试旗舰店" {
|
||||
t.Fatalf("列表应显示 PDD 店铺,实际 %+v", r.Rows)
|
||||
}
|
||||
if r.Rows[0].ClientText != "办公室手机" ||
|
||||
r.Rows[0].ClientTitle != "办公室手机(client-001)" {
|
||||
t.Errorf("客户端应显示名称并在提示保留 ID,实际 text=%q title=%q",
|
||||
r.Rows[0].ClientText, r.Rows[0].ClientTitle)
|
||||
}
|
||||
|
||||
if _, err := db.Exec(`UPDATE clients SET name='仓库手机' WHERE client_id='client-001'`); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
renamed, err := ListTasksView(db, repository.TaskFilter{}, 1)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if renamed.Rows[0].ClientText != "仓库手机" {
|
||||
t.Errorf("客户端重命名后列表应显示当前名称,实际 %q", renamed.Rows[0].ClientText)
|
||||
}
|
||||
|
||||
detail, err := GetTaskDetail(db, "COL-SHOP")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if detail.PddShopText != "测试旗舰店" || detail.ClientText != "仓库手机" ||
|
||||
detail.ClientIDText != "client-001" {
|
||||
t.Errorf("详情展示信息不完整:%+v", detail)
|
||||
}
|
||||
}
|
||||
|
||||
func TestListTasksView_关联缺失时店铺占位且客户端回退ID(t *testing.T) {
|
||||
db := newTestDB(t)
|
||||
insertTestTask(t, db, testTaskParams{
|
||||
taskID: "COL-FALLBACK", taskType: model.TaskCollect, status: model.TaskAssigned,
|
||||
pddGoodsID: "missing-product", assignedClient: "deleted-client",
|
||||
})
|
||||
|
||||
r, err := ListTasksView(db, repository.TaskFilter{}, 1)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if r.Rows[0].PddShopText != "—" || r.Rows[0].ClientText != "deleted-client" ||
|
||||
r.Rows[0].ClientTitle != "deleted-client" {
|
||||
t.Errorf("关联缺失回退错误:%+v", r.Rows[0])
|
||||
}
|
||||
}
|
||||
|
||||
// ── 统计跟随筛选 ──────────────────────────────────────
|
||||
|
||||
func TestListTasksView_统计跟随当前筛选(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user