77 lines
1.9 KiB
Go
77 lines
1.9 KiB
Go
package listing
|
|
|
|
import "testing"
|
|
|
|
func TestConsumableValueOnlyCountsChargedResources(t *testing.T) {
|
|
value := consumableValue(map[string]any{
|
|
"resources": []any{
|
|
map[string]any{"mode": "收费", "quantity": float64(5), "price": "0.1元/个"},
|
|
map[string]any{"mode": "赠送", "quantity": float64(3), "price": "0.6元/个"},
|
|
map[string]any{"mode": "收费", "quantity": float64(2), "price": "1元/2个"},
|
|
},
|
|
})
|
|
|
|
if value != 2 {
|
|
t.Fatalf("expected 2, got %.2f", value)
|
|
}
|
|
}
|
|
|
|
func TestValidateRequestRequiresDepositAboveConsumables(t *testing.T) {
|
|
req := CreateRequest{
|
|
Title: "测试账号",
|
|
ServerRegion: "烽火地带",
|
|
Price: 100,
|
|
DepositAmount: 2,
|
|
HafCoinAmount: 1000000,
|
|
ScreenshotURLS: []string{"https://example.com/a.png"},
|
|
AssetSummary: map[string]any{
|
|
"resources": []any{
|
|
map[string]any{"mode": "收费", "quantity": float64(2), "price": "1元/个"},
|
|
},
|
|
},
|
|
}
|
|
|
|
if err := validateRequest(req, publishRules{}); err != ErrDepositTooLow {
|
|
t.Fatalf("expected ErrDepositTooLow, got %v", err)
|
|
}
|
|
|
|
req.DepositAmount = 3
|
|
if err := validateRequest(req, publishRules{}); err != nil {
|
|
t.Fatalf("expected valid request, got %v", err)
|
|
}
|
|
}
|
|
|
|
func TestApplySellerListingPriceUsesSellerTotalPrice(t *testing.T) {
|
|
item := &ListingDTO{
|
|
Price: 238,
|
|
AssetSummary: map[string]any{
|
|
"price_breakdown": map[string]any{
|
|
"seller_total_price": 200,
|
|
},
|
|
},
|
|
}
|
|
|
|
applySellerListingPrice(item)
|
|
|
|
if item.Price != 200 {
|
|
t.Fatalf("expected seller price 200, got %.2f", item.Price)
|
|
}
|
|
}
|
|
|
|
func TestApplySellerListingPriceKeepsFallbackPrice(t *testing.T) {
|
|
item := &ListingDTO{
|
|
Price: 238,
|
|
AssetSummary: map[string]any{
|
|
"price_breakdown": map[string]any{
|
|
"seller_total_price": 0,
|
|
},
|
|
},
|
|
}
|
|
|
|
applySellerListingPrice(item)
|
|
|
|
if item.Price != 238 {
|
|
t.Fatalf("expected fallback price 238, got %.2f", item.Price)
|
|
}
|
|
}
|