package order import ( "testing" "hfb_sys/backend/internal/model" "gorm.io/datatypes" ) func TestReadOrderSnapshotCentPrefersCentField(t *testing.T) { raw := datatypes.JSON([]byte(`{ "asset_summary": { "price_breakdown": { "seller_total_price": 353.00, "seller_total_price_cent": 35301 } } }`)) if got := readSnapshotCent(raw, "seller_total_price"); got != 35301 { t.Fatalf("优先读取分字段失败: got %d, want 35301", got) } } func TestReadOrderSnapshotCentFallsBackToLegacyYuan(t *testing.T) { raw := datatypes.JSON([]byte(`{ "asset_summary": { "price_breakdown": { "consumable_price": 120.00 } } }`)) if got := readSnapshotCent(raw, "consumable_price"); got != 12000 { t.Fatalf("旧元字段回退失败: got %d, want 12000", got) } } func TestBuildOrderPricingUsesCentBreakdown(t *testing.T) { account := model.GameAccount{ AssetSummary: datatypes.JSON([]byte(`{ "asset_summary": { "price_breakdown": { "seller_total_price_cent": 35301, "platform_markup_amount_cent": 2999, "buyer_coin_base_price_cent": 26315, "consumable_price_cent": 12000, "seller_coin_base_price_cent": 23315 } } }`)), } pricing := buildOrderPricing(model.RentalListing{PriceCent: 38300}, account) if pricing.OwnerRentAmountCent != 35301 { t.Fatalf("OwnerRentAmountCent = %d, want 35301", pricing.OwnerRentAmountCent) } if pricing.PlatformFeeCent != 2999 { t.Fatalf("PlatformFeeCent = %d, want 2999", pricing.PlatformFeeCent) } if pricing.PureCoinAmountCent != 26315 { t.Fatalf("PureCoinAmountCent = %d, want 26315", pricing.PureCoinAmountCent) } if pricing.ExtraItemAmountCent != 11985 { t.Fatalf("ExtraItemAmountCent = %d, want 11985", pricing.ExtraItemAmountCent) } if pricing.OwnerPureCoinAmountCent != 23315 { t.Fatalf("OwnerPureCoinAmountCent = %d, want 23315", pricing.OwnerPureCoinAmountCent) } }