feat: complete remaining Go backend modules
This commit is contained in:
1 parent
cea2751dc5
commit
aef5a97165
145 files changed
+18376
-199
No files matched your search
@@ -0,0 +1,33 @@
|
||||
package postgres
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"git.nianxx.cn/wangxuming/NianAIGC/backend/internal/billing"
|
||||
)
|
||||
|
||||
func TestSeedBillingPriceRulesUsesOneIdempotentUpsert(t *testing.T) {
|
||||
q := &fakeQuerier{}
|
||||
db := NewDatabase(Config{Backend: BackendPostgres}, q)
|
||||
rules := []billing.PriceRule{{ID: "r", Provider: "seedance", Capability: "video.generate", ReqKey: "m", VariantKey: "resolution=720p", Unit: billing.UnitVideoSecond, StandardUnitPriceFen: 99, MarkupMultiplier: 1.2, Enabled: true}}
|
||||
if err := db.SeedBillingPriceRules(context.Background(), rules); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if q.sql != SeedBillingPriceRulesSQL || !strings.Contains(q.sql, "ON CONFLICT (provider, capability, COALESCE(req_key, ''), COALESCE(variant_key, ''), COALESCE(conditions, '{}'::jsonb)) DO UPDATE") {
|
||||
t.Fatalf("sql = %q", q.sql)
|
||||
}
|
||||
if len(q.args) != 1 {
|
||||
t.Fatalf("args = %#v", q.args)
|
||||
}
|
||||
var decoded []billing.PriceRule
|
||||
if err := json.Unmarshal(q.args[0].([]byte), &decoded); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !reflect.DeepEqual(decoded, rules) {
|
||||
t.Fatalf("payload = %#v", decoded)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user