fix: 增强顺运宝同步完整性保护 (#58)

This commit is contained in:
chengma
2026-08-09 17:17:42 +08:00
parent 17b8f53113
commit 4b5cd13807
8 changed files with 448 additions and 77 deletions
+27 -1
View File
@@ -304,6 +304,7 @@ func TestClient_ListTotal和ListPage(t *testing.T) {
w.Write(envelopeBody(t, true, "ok", 1, nil))
case "/am/stock/list":
w.Write(envelopeBody(t, true, "ok", map[string]any{
"total": 1,
"list": []map[string]any{
{"id": 75104587, "code": "260728TB95MJTQ", "amtOrder": 61200},
},
@@ -321,15 +322,40 @@ func TestClient_ListTotal和ListPage(t *testing.T) {
t.Fatalf("总数应该是 1,实际 %d", total)
}
rows, err := c.ListPage(context.Background(), "2026-07-25", "2026-07-28", 0, 1, 20)
rows, pageTotal, err := c.ListPage(context.Background(), "2026-07-25", "2026-07-28", 0, 1, 20)
if err != nil {
t.Fatalf("list 失败: %v", err)
}
if pageTotal != 1 {
t.Fatalf("list 响应内 total 应该是 1,实际 %d", pageTotal)
}
if len(rows) != 1 || rows[0].ID != 75104587 || rows[0].Code != "260728TB95MJTQ" {
t.Fatalf("列表结果不对: %+v", rows)
}
}
func TestClient_ListPage要求合法Total(t *testing.T) {
for _, test := range []struct {
name string
data map[string]any
}{
{"缺少total", map[string]any{"list": []any{}}},
{"total类型错误", map[string]any{"list": []any{}, "total": "1"}},
{"total为负数", map[string]any{"list": []any{}, "total": -1}},
} {
t.Run(test.name, func(t *testing.T) {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Write(envelopeBody(t, true, "ok", test.data, nil))
}))
defer srv.Close()
client, _ := New(srv.URL)
if _, _, err := client.ListPage(context.Background(), "2026-08-09", "2026-08-09", 0, 1, 20); err == nil {
t.Fatal("非法 total 应返回错误")
}
})
}
}
func TestClient_DetailListByStock_一单多商品(t *testing.T) {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Query().Get("hist") != "0" {