增加上传接口
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
package listing
|
||||
|
||||
import "testing"
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestConsumableValueOnlyCountsChargedResources(t *testing.T) {
|
||||
value := consumableValue(map[string]any{
|
||||
@@ -74,3 +77,105 @@ func TestApplySellerListingPriceKeepsFallbackPrice(t *testing.T) {
|
||||
t.Fatalf("expected fallback price 238, got %.2f", item.Price)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseExternalUploadItemsAcceptsSingleObject(t *testing.T) {
|
||||
items, err := parseExternalUploadItems(json.RawMessage(validExternalUploadDataJSON()))
|
||||
if err != nil {
|
||||
t.Fatalf("expected single upload parsed, got %v", err)
|
||||
}
|
||||
if len(items) != 1 || items[0].LoginMethod != "QQ账号密码" {
|
||||
t.Fatalf("unexpected items: %#v", items)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseExternalUploadItemsReportsMissingFields(t *testing.T) {
|
||||
_, err := parseExternalUploadItems(json.RawMessage(`{"loginMethod":"QQ账号密码","currency":{"hafuCoin":197.1}}`))
|
||||
if err == nil {
|
||||
t.Fatal("expected validation error")
|
||||
}
|
||||
validationErr, ok := err.(UploadValidationError)
|
||||
if !ok {
|
||||
t.Fatalf("expected UploadValidationError, got %T", err)
|
||||
}
|
||||
expected := []string{"data.rank", "data.level", "data.currency.recycleRatio", "data.dailyConsumption"}
|
||||
for _, field := range expected {
|
||||
if !containsString(validationErr.Missing, field) {
|
||||
t.Fatalf("expected missing %s in %#v", field, validationErr.Missing)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestExternalAccountToCreateRequestMapsUploadFields(t *testing.T) {
|
||||
req := externalAccountToCreateRequest("客服1", 1772526103000, ExternalAccountData{
|
||||
LoginMethod: "QQ账号密码",
|
||||
Rank: "黑鹰",
|
||||
Level: 60,
|
||||
SafeSlots: 9,
|
||||
SecretKD: 1.6,
|
||||
DailyLossM: 7,
|
||||
Deposit: 400,
|
||||
BanRecord: "无",
|
||||
CommonRegion: "郑州",
|
||||
Currency: ExternalUploadCurrency{
|
||||
HafuCoin: 197.1,
|
||||
RecycleRatio: 43,
|
||||
RecycleRent: 458,
|
||||
},
|
||||
DailyConsumption: ExternalDailyConsumption{Stamina: 7, Weight: 7},
|
||||
Inventory: ExternalUploadInventory{
|
||||
AWMBullets: 45,
|
||||
Level6Helmets: 14,
|
||||
Level6Armor: 17,
|
||||
Skins: []string{"信条", "电锯惊魂"},
|
||||
},
|
||||
})
|
||||
|
||||
if req.ServerRegion != "QQ" {
|
||||
t.Fatalf("expected QQ server region, got %q", req.ServerRegion)
|
||||
}
|
||||
if req.HafCoinAmount != 197100000 {
|
||||
t.Fatalf("expected haf coin amount 197100000, got %d", req.HafCoinAmount)
|
||||
}
|
||||
if req.Price != 458 || req.DepositAmount != 400 {
|
||||
t.Fatalf("unexpected price/deposit %.2f/%.2f", req.Price, req.DepositAmount)
|
||||
}
|
||||
if req.AssetSummary["season_insurance"] != "3*3" {
|
||||
t.Fatalf("expected 3*3 insurance, got %#v", req.AssetSummary["season_insurance"])
|
||||
}
|
||||
if req.AssetSummary["daily_loss_m"] != float64(7) {
|
||||
t.Fatalf("expected daily loss 7, got %#v", req.AssetSummary["daily_loss_m"])
|
||||
}
|
||||
if req.AssetSummary["stamina_level"] != "7级" || req.AssetSummary["load_level"] != "7级" {
|
||||
t.Fatalf("unexpected stamina/load: %#v", req.AssetSummary)
|
||||
}
|
||||
groups := req.AssetSummary["skin_groups"].(map[string][]string)
|
||||
if len(groups["melee"]) != 2 {
|
||||
t.Fatalf("expected melee skins mapped, got %#v", groups)
|
||||
}
|
||||
if len(req.ScreenshotURLS) != 1 || req.ScreenshotURLS[0] != defaultUploadScreenshot {
|
||||
t.Fatalf("expected default screenshot, got %#v", req.ScreenshotURLS)
|
||||
}
|
||||
}
|
||||
|
||||
func validExternalUploadDataJSON() string {
|
||||
return `{
|
||||
"loginMethod":"QQ账号密码",
|
||||
"rank":"黑鹰",
|
||||
"level":60,
|
||||
"safeSlots":9,
|
||||
"secretKD":1.6,
|
||||
"dailyLossM":7,
|
||||
"deposit":400,
|
||||
"currency":{"hafuCoin":197.1,"recycleRatio":43,"recycleRent":458},
|
||||
"dailyConsumption":{"stamina":7,"weight":7}
|
||||
}`
|
||||
}
|
||||
|
||||
func containsString(values []string, target string) bool {
|
||||
for _, value := range values {
|
||||
if value == target {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user