package postgres import ( "context" "reflect" "testing" "git.nianxx.cn/wangxuming/NianAIGC/backend/internal/billing" ) func TestBillingWalletPosterDelegatesToExistingDatabaseFunction(t *testing.T) { db := NewDatabase(Config{Backend: BackendPostgres}, &fakeQuerier{rows: [][]any{{"ledger-1", int64(75), int64(75), int64(100), int64(25), nil, nil, int64(-25)}}}) got, err := NewBillingWalletPoster(db).PostWalletEntry(context.Background(), billing.WalletPostParams{LedgerID: "ledger-1", OrganizationID: "org", AccountID: "a", JobID: "job", Kind: "charge", DeltaFen: -25, Currency: "CNY", IdempotencyKey: "job-charge:job", Description: "charge", Metadata: map[string]any{"x": 1}}) if err != nil || got.LedgerID != "ledger-1" || got.BalanceFen != 75 { t.Fatalf("got=%#v err=%v", got, err) } } func TestListBillingPriceRulesUsesExplicitColumns(t *testing.T) { q := &fakeQuerier{} db := NewDatabase(Config{Backend: BackendPostgres}, q) _, err := db.ListBillingPriceRules(context.Background(), false) if err != nil { t.Fatal(err) } if q.sql != ListBillingPriceRulesSQL || reflect.DeepEqual(q.args, []any{false}) == false { t.Fatalf("sql=%q args=%#v", q.sql, q.args) } }