automation 重构期间的配套修改: - browser:订单抓取/密码登录/二维码刷新/stealth 等适配新流程,删 search.go - db:cookies/orders_ext/extras/sessions/users/password/repository 等调整 - xianyu:mtop client、protocol(sign/decrypt/msgpack/cookies)、qrlogin、ws、ua - server:admin/analytics/auth/cookie/helpers/item/item_publish_batch handlers - frontend:App/Dashboard/ItemList/Rules/Sidebar/api/types,删 Keywords/TestPage - auth、notify、webui、go.mod 等 本次会话补充: - cmd/server、cmd/init-admin 改为 // Package main 开头的标准包文档 - .gitignore 加 internal/webui/static/assets/(hash 化构建产物不入库) - internal/webui/static/index.html 重新构建 全量 go build/vet/test + race + 前端 test/build 通过。 Co-Authored-By: Claude Opus 4.8 <[email protected]>
45 lines
1.4 KiB
Go
45 lines
1.4 KiB
Go
package ws
|
|
|
|
import (
|
|
"encoding/base64"
|
|
"testing"
|
|
)
|
|
|
|
func TestExtractSyncPayload(t *testing.T) {
|
|
msg := map[string]any{"body": map[string]any{"syncPushPackage": map[string]any{
|
|
"data": []any{map[string]any{"data": "payload"}},
|
|
}}}
|
|
if got, ok := extractSyncPayload(msg); !ok || got != "payload" {
|
|
t.Fatalf("extractSyncPayload() = %q, %v", got, ok)
|
|
}
|
|
for _, invalid := range []map[string]any{{}, {"body": map[string]any{}}, {"body": map[string]any{"syncPushPackage": map[string]any{"data": []any{}}}}} {
|
|
if _, ok := extractSyncPayload(invalid); ok {
|
|
t.Fatalf("invalid payload accepted: %#v", invalid)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestDecodeSyncDataJSONAndInvalid(t *testing.T) {
|
|
raw := base64.StdEncoding.EncodeToString([]byte(`{"event":"paid","count":2}`))
|
|
got, err := decodeSyncData(raw)
|
|
if err != nil || got["event"] != "paid" || got["count"] != float64(2) {
|
|
t.Fatalf("decodeSyncData() = %#v, %v", got, err)
|
|
}
|
|
if _, err := decodeSyncData("not-base64"); err == nil {
|
|
t.Fatal("invalid payload should fail")
|
|
}
|
|
}
|
|
|
|
func TestWSHelpers(t *testing.T) {
|
|
headers := map[string]any{"mid": "m1", "nil": nil}
|
|
if got := ackVal(headers, "mid", "fallback"); got != "m1" {
|
|
t.Fatalf("ackVal existing = %v", got)
|
|
}
|
|
if got := ackVal(headers, "nil", "fallback"); got != "fallback" {
|
|
t.Fatalf("ackVal nil = %v", got)
|
|
}
|
|
if got := stripGoofish(" 123@goofish "); got != "123" {
|
|
t.Fatalf("stripGoofish = %q", got)
|
|
}
|
|
}
|