增加用户免押额度筛选

This commit is contained in:
yml2213
2026-06-27 09:12:15 +08:00
parent c30914b538
commit 378b7a0b79
6 changed files with 76 additions and 5 deletions
@@ -1,6 +1,12 @@
package adminuser
import "testing"
import (
"strings"
"testing"
"gorm.io/driver/sqlite"
"gorm.io/gorm"
)
func TestDepositFreeQuotaAmountCent(t *testing.T) {
tests := []struct {
@@ -28,3 +34,45 @@ func TestDepositFreeQuotaAmountCent(t *testing.T) {
})
}
}
func TestParseBoolQuery(t *testing.T) {
tests := []struct {
name string
value string
want bool
}{
{name: "true 开启", value: "true", want: true},
{name: "数字 1 开启", value: "1", want: true},
{name: "on 开启", value: "on", want: true},
{name: "空值关闭", value: "", want: false},
{name: "false 关闭", value: "false", want: false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := parseBoolQuery(tt.value); got != tt.want {
t.Fatalf("parseBoolQuery(%q) = %v, want %v", tt.value, got, tt.want)
}
})
}
}
func TestApplyUserFilterHasDepositFreeQuota(t *testing.T) {
db, err := gorm.Open(sqlite.Open(":memory:"), &gorm.Config{DryRun: true})
if err != nil {
t.Fatalf("打开测试数据库失败:%v", err)
}
stmt := applyUserFilter(db.Table("users AS u"), ListQuery{
Status: "active",
HasDepositFreeQuota: true,
}).Find(&[]struct{}{}).Statement
sql := stmt.SQL.String()
if !strings.Contains(sql, "u.deposit_free_quota_cent > 0") {
t.Fatalf("SQL 未包含免押额度过滤:%s", sql)
}
if len(stmt.Vars) != 1 || stmt.Vars[0] != "active" {
t.Fatalf("筛选变量不正确:%v", stmt.Vars)
}
}