feat: add billing and usage domain cores
This commit is contained in:
1 parent
48dd5d07c8
commit
5e60bb40e7
14 files changed
+931
No files matched your search
@@ -0,0 +1,29 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user