增加文档
This commit is contained in:
@@ -67,8 +67,8 @@ func TestValidateCreateRequestRequiresShunchengSecretID(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestListUsesSuccessfulPaymentStats 验证配置页只统计成功支付,不把打开二维码或取消订单算作成交。
|
||||
func TestListUsesSuccessfulPaymentStats(t *testing.T) {
|
||||
// TestListFlagsPaymentReferences 验证列表只批量标记是否存在支付引用,不再聚合所有支付记录。
|
||||
func TestListFlagsPaymentReferences(t *testing.T) {
|
||||
db := database.NewTestDB()
|
||||
if err := database.AutoMigrateIfMissing(db, &model.PaymentMerchantConfig{}, &model.PaymentOrder{}); err != nil {
|
||||
t.Fatalf("migrate failed: %v", err)
|
||||
@@ -142,13 +142,46 @@ func TestListUsesSuccessfulPaymentStats(t *testing.T) {
|
||||
if total != 1 || len(items) != 1 {
|
||||
t.Fatalf("items/total = %d/%d, want 1/1", len(items), total)
|
||||
}
|
||||
if items[0].TotalTransactions != 1 || items[0].TotalAmountCent != 10130 {
|
||||
t.Fatalf("success stats = %d/%d, want 1/10130", items[0].TotalTransactions, items[0].TotalAmountCent)
|
||||
if !items[0].HasPaymentRecords {
|
||||
t.Fatal("has_payment_records should be true")
|
||||
}
|
||||
if items[0].ReferenceCount != 3 {
|
||||
t.Fatalf("reference_count = %d, want 3", items[0].ReferenceCount)
|
||||
}
|
||||
|
||||
func TestDeleteRejectsReferencedConfig(t *testing.T) {
|
||||
db := database.NewTestDB()
|
||||
if err := database.AutoMigrateIfMissing(db, &model.PaymentMerchantConfig{}, &model.PaymentOrder{}); err != nil {
|
||||
t.Fatalf("migrate failed: %v", err)
|
||||
}
|
||||
if items[0].LastUsedAt == nil {
|
||||
t.Fatal("last success pay time should not be nil")
|
||||
config := model.PaymentMerchantConfig{
|
||||
Name: "已有交易配置",
|
||||
Provider: "lakala",
|
||||
MerchantID: "M1",
|
||||
PayWay: "WXZF",
|
||||
Status: "active",
|
||||
Environment: "production",
|
||||
}
|
||||
if err := db.Create(&config).Error; err != nil {
|
||||
t.Fatalf("create config failed: %v", err)
|
||||
}
|
||||
payment := model.PaymentOrder{
|
||||
PaymentNo: "PAY-DELETE-GUARD",
|
||||
OrderID: 1,
|
||||
OrderNo: "ORD-DELETE-GUARD",
|
||||
UserID: 2,
|
||||
PaymentConfigID: config.ID,
|
||||
Provider: "lakala",
|
||||
MerchantID: "M1",
|
||||
ThirdOrderID: "PAY-DELETE-GUARD",
|
||||
PayWay: "WXZF",
|
||||
BizType: "order_pay",
|
||||
Status: "paid",
|
||||
}
|
||||
if err := db.Create(&payment).Error; err != nil {
|
||||
t.Fatalf("create payment failed: %v", err)
|
||||
}
|
||||
|
||||
repo := NewRepository(db, nil)
|
||||
if err := repo.Delete(t.Context(), config.ID, 0, AuditMeta{}); err != ErrCannotDeleteInUse {
|
||||
t.Fatalf("Delete() error = %v, want ErrCannotDeleteInUse", err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user