feat: 固定创建真实采购任务 (#112)
This commit is contained in:
@@ -325,6 +325,36 @@ func TestClientAssignment_一人多客户端并按采购员隔离列表(t *testi
|
||||
}
|
||||
}
|
||||
|
||||
func TestListLivePurchaseClients_只返回可见在线且声明Live的客户端(t *testing.T) {
|
||||
db := newTestDB(t)
|
||||
admin, buyerA, _ := prepareClientAssignmentUsers(t, db)
|
||||
now := time.Now().UTC()
|
||||
clients := []model.Client{
|
||||
{ClientID: "live-online", Name: "真实在线", LastSeenAt: now.Format(model.TimeLayout), Capabilities: `{"purchase_mode":"live"}`},
|
||||
{ClientID: "dry-online", Name: "演练在线", LastSeenAt: now.Format(model.TimeLayout), Capabilities: `{"purchase_mode":"dry_run"}`},
|
||||
{ClientID: "live-offline", Name: "真实离线", LastSeenAt: now.Add(-time.Hour).Format(model.TimeLayout), Capabilities: `{"purchase_mode":"live"}`},
|
||||
}
|
||||
for _, client := range clients {
|
||||
if err := RegisterClient(db, client, true); err != nil {
|
||||
t.Fatalf("登记客户端失败: %v", err)
|
||||
}
|
||||
if _, _, err := AssignClient(db, admin, client.ClientID, buyerA.UserID, now); err != nil {
|
||||
t.Fatalf("绑定客户端失败: %v", err)
|
||||
}
|
||||
}
|
||||
if _, err := db.Exec(`UPDATE clients SET last_seen_at=? WHERE client_id=?`, now.Add(-time.Hour).Format(model.TimeLayout), "live-offline"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
rows, err := ListLivePurchaseClients(db, buyerA, time.Minute)
|
||||
if err != nil {
|
||||
t.Fatalf("读取真实采购客户端失败: %v", err)
|
||||
}
|
||||
if len(rows) != 1 || rows[0].ClientID != "live-online" {
|
||||
t.Fatalf("只应返回在线 live 客户端,实际 %+v", rows)
|
||||
}
|
||||
}
|
||||
|
||||
func TestClientAssignment_转交解绑保留审计且不改任务(t *testing.T) {
|
||||
db := newTestDB(t)
|
||||
admin, buyerA, buyerB := prepareClientAssignmentUsers(t, db)
|
||||
|
||||
Reference in New Issue
Block a user