feat(region_pricing): 扩展非 token 统一计费字段,支持语音按字符/秒计费
- 新增 region_pricing.pricing_mode / price_unit / flat_price 字段 - 新增 migration 016_region_pricing_non_token_units.sql - officialPricingRecord 新增 PricingMode/PriceUnit/FlatPrice 字段 - detectModality 新增 audio 模态检测(voice/audio/speech) - providerMetadata 新增 BAAI/ByteDance/China Mobile 元数据 - import_mobile_cloud_pricing.go: 解析语音计费表(CosyVoice/SenseVoice) - CosyVoice: 2元/万字符 → pricingMode=flat, priceUnit=10k_characters - SenseVoice: 0.0007元/秒 → pricingMode=flat, priceUnit=second - mobileCloudProviderName 新增 cosyvoice/sensevoice → Alibaba 映射 - cmd/server: modelResponse 新增 pricingMode/priceUnit/flatPrice,API 字段说明同步更新 - 新增 TestModelsHandlerReturnsFlatPricingFields 测试
This commit is contained in:
@@ -10,6 +10,55 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestModelsHandlerReturnsFlatPricingFields(t *testing.T) {
|
||||
mux := newMux(
|
||||
&sql.DB{},
|
||||
func(context.Context, *sql.DB) ([]modelResponse, error) {
|
||||
return []modelResponse{{
|
||||
ID: "mobile-cloud-huabei-huhehaote-cosyvoice",
|
||||
Name: "CosyVoice",
|
||||
Provider: "Alibaba",
|
||||
ProviderCN: "阿里云",
|
||||
Modality: "audio",
|
||||
PricingMode: "flat",
|
||||
PriceUnit: "10k_characters",
|
||||
FlatPrice: 2,
|
||||
Currency: "CNY",
|
||||
IsFree: false,
|
||||
DataConfidence: "official",
|
||||
}}, nil
|
||||
},
|
||||
func(context.Context, *sql.DB) ([]subscriptionPlanResponse, error) {
|
||||
return nil, nil
|
||||
},
|
||||
func(context.Context, *sql.DB) (*latestReportResponse, error) {
|
||||
return nil, sql.ErrNoRows
|
||||
},
|
||||
)
|
||||
|
||||
req := httptest.NewRequest(http.MethodGet, "/api/v1/models", nil)
|
||||
rec := httptest.NewRecorder()
|
||||
mux.ServeHTTP(rec, req)
|
||||
|
||||
if rec.Code != http.StatusOK {
|
||||
t.Fatalf("expected status 200, got %d", rec.Code)
|
||||
}
|
||||
|
||||
var payload struct {
|
||||
Data []modelResponse `json:"data"`
|
||||
}
|
||||
if err := json.Unmarshal(rec.Body.Bytes(), &payload); err != nil {
|
||||
t.Fatalf("unmarshal response: %v", err)
|
||||
}
|
||||
if len(payload.Data) != 1 {
|
||||
t.Fatalf("expected 1 model, got %d", len(payload.Data))
|
||||
}
|
||||
got := payload.Data[0]
|
||||
if got.PricingMode != "flat" || got.PriceUnit != "10k_characters" || got.FlatPrice != 2 {
|
||||
t.Fatalf("unexpected flat pricing payload: %+v", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSubscriptionPlansHandlerReturnsEnvelope(t *testing.T) {
|
||||
mux := newMux(
|
||||
&sql.DB{},
|
||||
|
||||
Reference in New Issue
Block a user