增加统一倍率调整按钮
This commit is contained in:
1 parent
be655b6569
commit
4195525dc7
23 files changed
+750
-16
No files matched your search
@@ -0,0 +1,32 @@
|
||||
package postgres
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"git.nianxx.cn/wangxuming/NianAIGC/backend/internal/billing"
|
||||
)
|
||||
|
||||
func TestUpdateBillingPriceRulesUsesSingleGuardedStatement(t *testing.T) {
|
||||
q := &fakeQuerier{}
|
||||
db := NewDatabase(Config{Backend: BackendPostgres}, q)
|
||||
patch := billing.BulkPricePatch{RuleIDs: []string{"first", "second"}, MarkupMultiplier: 1.75}
|
||||
if _, err := db.UpdateBillingPriceRules(context.Background(), patch); !errors.Is(err, billing.ErrPriceNotFound) {
|
||||
t.Fatalf("empty result error = %v", err)
|
||||
}
|
||||
if q.sql != UpdateBillingPriceRulesSQL || !reflect.DeepEqual(q.args, []any{patch.RuleIDs, patch.MarkupMultiplier}) {
|
||||
t.Fatalf("query = %q, args = %#v", q.sql, q.args)
|
||||
}
|
||||
for _, clause := range []string{"FOR UPDATE", "count(*) = cardinality($1::text[])", "AND (SELECT all_present FROM eligible)", "jsonb_set(tier.value", "UPDATE public.billing_price_rules"} {
|
||||
if !strings.Contains(q.sql, clause) {
|
||||
t.Fatalf("missing atomic bulk update clause %q", clause)
|
||||
}
|
||||
}
|
||||
q.sql = ""
|
||||
if _, err := db.UpdateBillingPriceRules(context.Background(), billing.BulkPricePatch{MarkupMultiplier: 2}); !errors.Is(err, billing.ErrPriceNotFound) || q.sql != "" {
|
||||
t.Fatalf("empty ID list issued a query: %q, %v", q.sql, err)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user