Files
Ydisks-Xianyu-Helper/internal/browser/orders_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 <noreply@anthropic.com>
2026-06-30 21:41:03 +08:00

67 lines
1.7 KiB
Go

package browser
import (
"testing"
)
func TestOrderStatusMap(t *testing.T) {
cases := []struct {
code int
expect string
}{
{1, "processing"}, {2, "pending_ship"}, {3, "shipped"},
{4, "completed"}, {7, "refunding"}, {8, "cancelled"},
{9, "refunding"}, {10, "cancelled"}, {11, "completed"}, {12, "cancelled"},
}
for _, c := range cases {
if s, ok := orderStatusMap[c.code]; !ok || s != c.expect {
t.Errorf("orderStatusMap[%d] = %q, want %q", c.code, s, c.expect)
}
}
}
func TestParseAPIResponseStatusCode(t *testing.T) {
od := &OrderDetail{}
data := map[string]any{
"utArgs": map[string]any{"orderStatus": float64(2)},
}
parseAPIResponse(od, data)
if od.OrderStatus != "pending_ship" {
t.Errorf("got %q, want pending_ship", od.OrderStatus)
}
}
func TestParseAPIResponseAmountFromComponentData(t *testing.T) {
od := &OrderDetail{}
data := map[string]any{
"components": []any{
map[string]any{
"render": "orderInfoVO",
"data": map[string]any{
"priceInfo": map[string]any{
"amount": map[string]any{"value": "0.88"},
},
},
},
},
}
parseAPIResponse(od, data)
if od.Amount != "0.88" {
t.Fatalf("Amount=%q want 0.88", od.Amount)
}
}
func TestExtractPaidAmountFromText(t *testing.T) {
cases := map[string]string{
"商品标价\n¥99.00\n实付款 ¥0.88\n交易成功": "0.88",
"订单信息\n实付金额\n¥12.50\n订单编号": "12.50",
"合计\n6.00\n其他信息": "6.00",
"商品价格\n¥19.90\n没有付款标签": "",
}
for input, want := range cases {
if got := extractPaidAmountFromText(input); got != want {
t.Errorf("extractPaidAmountFromText(%q)=%q want %q", input, got, want)
}
}
}