关闭公开注册并优化仪表盘
This commit is contained in:
@@ -118,6 +118,64 @@ func TestFulfillmentCreateOrderDebitsWalletAndIsIdempotent(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestDashboardScopesPlatformAndMerchantData(t *testing.T) {
|
||||
db := newServiceTestDB(t)
|
||||
merchantA, productA := seedFulfillmentMerchant(t, db, "dashboard-a", 1000, 5, 100)
|
||||
merchantB, productB := seedFulfillmentMerchant(t, db, "dashboard-b", 2000, 5, 300)
|
||||
svc := NewFulfillmentService(db, nil)
|
||||
|
||||
if _, err := svc.CreateOrder(CreateFulfillmentOrderInput{
|
||||
MerchantID: merchantA,
|
||||
APIClientID: 31,
|
||||
ClientOrderNo: "dashboard-a-001",
|
||||
SKU: productA.SKU,
|
||||
}); err != nil {
|
||||
t.Fatalf("create order a: %v", err)
|
||||
}
|
||||
if _, err := svc.CreateOrder(CreateFulfillmentOrderInput{
|
||||
MerchantID: merchantB,
|
||||
APIClientID: 32,
|
||||
ClientOrderNo: "dashboard-b-001",
|
||||
SKU: productB.SKU,
|
||||
}); err != nil {
|
||||
t.Fatalf("create order b: %v", err)
|
||||
}
|
||||
|
||||
merchantStats, err := svc.Dashboard(merchantA, false)
|
||||
if err != nil {
|
||||
t.Fatalf("merchant dashboard: %v", err)
|
||||
}
|
||||
if merchantStats.Scope != "merchant" {
|
||||
t.Fatalf("expected merchant scope, got %s", merchantStats.Scope)
|
||||
}
|
||||
if merchantStats.ProductCount != 1 || merchantStats.ActiveProductCount != 1 {
|
||||
t.Fatalf("merchant product stats should only include current merchant, got %+v", merchantStats)
|
||||
}
|
||||
if merchantStats.OrderCount != 1 || merchantStats.PendingOrderCount != 1 || merchantStats.TotalSales != 100 {
|
||||
t.Fatalf("merchant order stats should only include current merchant, got %+v", merchantStats)
|
||||
}
|
||||
if merchantStats.WalletAvailableBalance != 900 {
|
||||
t.Fatalf("merchant wallet should only include current merchant, got %d", merchantStats.WalletAvailableBalance)
|
||||
}
|
||||
|
||||
platformStats, err := svc.Dashboard(merchantA, true)
|
||||
if err != nil {
|
||||
t.Fatalf("platform dashboard: %v", err)
|
||||
}
|
||||
if platformStats.Scope != "platform" {
|
||||
t.Fatalf("expected platform scope, got %s", platformStats.Scope)
|
||||
}
|
||||
if platformStats.OrderCount != 2 || platformStats.PendingOrderCount != 2 || platformStats.TotalSales != 400 {
|
||||
t.Fatalf("platform order stats should include all merchants, got %+v", platformStats)
|
||||
}
|
||||
if platformStats.WalletAvailableBalance < 2600 {
|
||||
t.Fatalf("platform wallet should include all merchant wallets, got %d", platformStats.WalletAvailableBalance)
|
||||
}
|
||||
if platformStats.ProductCount <= merchantStats.ProductCount {
|
||||
t.Fatalf("platform product stats should be broader than merchant stats, got platform=%d merchant=%d", platformStats.ProductCount, merchantStats.ProductCount)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFulfillmentCreateOrderAppliesMerchantFeeRate(t *testing.T) {
|
||||
db := newServiceTestDB(t)
|
||||
merchantID, product := seedFulfillmentMerchant(t, db, "merchant-fee-rate", 1000, 5, 200)
|
||||
|
||||
Reference in New Issue
Block a user