返回 DeepSeek-Reasonix
billing_test.go
根目录 / internal / config / billing_test.go
1 package config
2
3 import (
4 "testing"
5
6 "reasonix/internal/billing"
7 "reasonix/internal/provider"
8 )
9
10 func TestDisplayCurrencyIndependentOfListPrices(t *testing.T) {
11 c := Default()
12 flash, _ := c.Provider("deepseek-flash")
13 before := flash.Price.Output
14 if err := c.SetDisplayCurrency("CNY"); err != nil {
15 t.Fatal(err)
16 }
17 if flash.Price.Output != before {
18 t.Fatalf("list price mutated: %v -> %v", before, flash.Price.Output)
19 }
20 if got := c.ExplicitDisplayCurrency(); got != "CNY" {
21 t.Fatalf("display = %q", got)
22 }
23 if got := flash.ProviderBillingCurrency(); got != "USD" {
24 t.Fatalf("billing currency = %q, want USD", got)
25 }
26 }
27
28 func TestCustomPriceProtectedFromCatalog(t *testing.T) {
29 custom := billing.RateCard{CacheHit: 9, Input: 9, Output: 9, Currency: "USD"}
30 if _, ok := billing.MatchesCatalog("deepseek", "deepseek-v4-flash", custom); ok {
31 t.Fatal("custom price must not match official catalog")
32 }
33 }
34
35 func TestQuoteForUsageUsesSelectedDisplay(t *testing.T) {
36 price := deepSeekV4FlashPriceUSD()
37 q := QuoteForUsage(price, nil, "USD", "m", "executor", billing.BillingModePAYG, "")
38 if q.Complete {
39 t.Fatal("nil usage should be incomplete")
40 }
41 u := &provider.Usage{PromptTokens: 1_000_000, CompletionTokens: 0}
42 q = QuoteForUsage(price, u, "USD", "m", "executor", billing.BillingModePAYG, "")
43 if q.Original.Currency != "USD" || q.Selected == nil {
44 t.Fatalf("quote = %+v", q)
45 }
46 }
47
47 lines GO