Files
Ydisks-Xianyu-Helper/internal/xianyu/mtop/publish_test.go
T
ChristandClaude Opus 4.8 980de41b53 chore: 重构配套改动 + 包文档 + 构建产物清理
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]>
2026-06-30 21:41:03 +08:00

50 lines
1.7 KiB
Go

package mtop
import (
"errors"
"testing"
)
func TestPublishPayloadBuilders(t *testing.T) {
req := PublishItemRequest{PriceCents: 1234, OriginalPriceCents: 2000, PostageMode: "fixed", PostageCents: 800}
price := publishPriceDTO(req)
if price["priceInCent"] != "1234" || price["origPriceInCent"] != "2000" {
t.Fatalf("publishPriceDTO = %#v", price)
}
postage := postageDTO(req)
if postage["postPriceInCent"] != "800" || postage["templateId"] != "0" {
t.Fatalf("postageDTO = %#v", postage)
}
if got := postageDTO(PublishItemRequest{PostageMode: "free"}); got["canFreeShipping"] != true {
t.Fatalf("free postage = %#v", got)
}
if got := postageDTO(PublishItemRequest{PostageMode: "distance"}); got["templateId"] != "-100" {
t.Fatalf("distance postage = %#v", got)
}
}
func TestPublishParsingAndErrors(t *testing.T) {
if w, h := parsePix("800x600"); w != 800 || h != 600 {
t.Fatalf("parsePix = %d x %d", w, h)
}
if w, h := parsePix("bad"); w != 0 || h != 0 {
t.Fatalf("invalid parsePix = %d x %d", w, h)
}
if got := centsText(1234); got != "12.34" {
t.Fatalf("centsText = %q", got)
}
if got := findStringDeep(map[string]any{"outer": map[string]any{"itemId": "42"}}, "itemId"); got != "42" {
t.Fatalf("findStringDeep = %q", got)
}
err := classifyPublishError([]string{"FAIL_SYS_TOKEN_EXPIRED::令牌过期"}, map[string]any{})
var publishErr *PublishError
if !errors.As(err, &publishErr) || publishErr.Code != PublishErrorTokenExpired {
t.Fatalf("token error = %#v", err)
}
err = classifyPublishError([]string{"账号没有库存发布权限"}, map[string]any{})
if !errors.As(err, &publishErr) || publishErr.Code != PublishErrorStockPermissionMissing {
t.Fatalf("stock error = %#v", err)
}
}