71 lines
2.9 KiB
Go
71 lines
2.9 KiB
Go
package billing
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"testing"
|
|
)
|
|
|
|
func TestEvoLink25QuotesUseIndependentModelAndQualityPrices(t *testing.T) {
|
|
catalog := Catalog{Rules: DefaultBillingPriceRules()}
|
|
for _, model := range []string{"gpt-image-2.5-flare", "gpt-image-2.5-sunburst"} {
|
|
for _, test := range []struct {
|
|
quality string
|
|
cost, amount int64
|
|
}{{"low", 4, 5}, {"medium", 9, 11}, {"high", 35, 42}} {
|
|
t.Run(model+"/"+test.quality, func(t *testing.T) {
|
|
quote, err := catalog.Quote(QuoteInput{Provider: "evolink", Capability: "image.generate", ReqKey: model, Parameters: Parameters{"quality": test.quality}})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if quote.PriceRuleID != "base-evolink-"+model || quote.StandardUnitPriceFen != test.cost || quote.AmountFen != test.amount {
|
|
t.Fatalf("quote=%+v", quote)
|
|
}
|
|
})
|
|
}
|
|
for _, params := range []Parameters{{"quality": "xhigh"}, {"resolution": "2K"}, {"resolution": "4K"}} {
|
|
if _, err := catalog.Quote(QuoteInput{Provider: "evolink", Capability: "image.generate", ReqKey: model, Parameters: params}); !errors.Is(err, ErrParameterTier) {
|
|
t.Fatalf("unsupported params %v: %v", params, err)
|
|
}
|
|
}
|
|
}
|
|
legacy, err := catalog.Quote(QuoteInput{Provider: "evolink", Capability: "image.generate", ReqKey: "gpt-image-2"})
|
|
if err != nil || legacy.AmountFen != 41 {
|
|
t.Fatalf("legacy quote=%+v, err=%v", legacy, err)
|
|
}
|
|
}
|
|
|
|
func TestEvoLink25A4QuoteKeepsModelAndQuality(t *testing.T) {
|
|
store := "eStoreStub{rules: DefaultBillingPriceRules()}
|
|
quote, err := NewService(store, nil).Quote(context.Background(), QuoteCommand{
|
|
Provider: "evolink", Capability: "image.generate", ReqKey: "gpt-image-2.5-sunburst",
|
|
Payload: map[string]any{"settings": map[string]any{"width": 848.0, "height": 1200.0, "quality": "high", "imageCount": 1.0}},
|
|
})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if quote.AmountFen != 42 || quote.Parameters["aspectRatio"] != "70:99" {
|
|
t.Fatalf("quote=%+v", quote)
|
|
}
|
|
}
|
|
|
|
func TestEvoLink25QuotesAllSupportedAspectRatios(t *testing.T) {
|
|
store := "eStoreStub{rules: DefaultBillingPriceRules()}
|
|
for _, size := range []string{"1:2", "2:3", "5:4", "21:9", "848x1200"} {
|
|
quote, err := NewService(store, nil).Quote(context.Background(), QuoteCommand{
|
|
Provider: "evolink", Capability: "image.generate", ReqKey: "gpt-image-2.5-flare",
|
|
Payload: map[string]any{"settings": map[string]any{"size": size, "quality": "medium", "imageCount": 1.0}},
|
|
})
|
|
if err != nil || quote.AmountFen != 11 {
|
|
t.Fatalf("size=%s quote=%+v err=%v", size, quote, err)
|
|
}
|
|
}
|
|
quote, err := NewService(store, nil).Quote(context.Background(), QuoteCommand{
|
|
Provider: "evolink", Capability: "image.generate", ReqKey: "gpt-image-2.5-flare",
|
|
Payload: map[string]any{"settings": map[string]any{"width": 512.0, "height": 1024.0, "quality": "medium"}},
|
|
})
|
|
if err != nil || quote.AmountFen != 11 || quote.Parameters["aspectRatio"] != "512:1024" {
|
|
t.Fatalf("unlisted ratio quote=%+v err=%v", quote, err)
|
|
}
|
|
}
|