Files
magpie/internal/gui/price_rate_test.go
T
yetone 41ed1c95bc gui, provider: the request log scrolls sideways from a bar at the window's foot and a request's detail opens with its status, duration and a View routing link (mintonight, #799); a provider has a price rate its costs are counted at (ITea312, #819) — #799: the request table, wider than the window, could only be scrolled sideways from the scrollbar at its very end, below 40+ rows, so it looked like it had none; and the "status detail" the reply pointed to wasn't to be found in the row's detail. A bar (#ledHScroll) now sits at the window's foot while the table is wider than its box, scrolling with it both ways; a row's detail begins with Status (Succeeded for log rows), Duration and Routing: View routing, which opens the request's route. #819: costs were counted only at the official (list or maker) price, or a price set per model with magpie model price; a relay billing 0.8 of it had to have each model priced by hand. The provider editor (key and signed-in alike) has a Price rate field (empty for 1; 0–1000, three decimals), saved as priceRate; EffectivePrice multiplies the list/maker price by it, and a price set for a model stays as set. Usage caches key on the providers file, so the counts follow. zh, ja, de strings. ledger-hscroll.test.cjs (fails on the old code) and provider-price-rate.test.cjs (WebKit, en and zh); usage-ledger, usage-ledger-detail (updated for the new rows), usage-ledger-content, usage-ledger-chart, routing-failed-open, purpose-filter, provider-concurrency and provider-levels-save pass on WebKit. TestPriceRateScalesListPrice, TestPriceRateOK, TestPriceRateOf. go vet, builds (darwin, GOOS=linux nogui, GOOS=windows) and go test -tags nogui -count=1 ./... under a temp HOME pass.
2026-10-05 02:03:10 +08:00

32 lines
708 B
Go

package gui
import (
"encoding/json"
"testing"
)
// A save's priceRate (#819): left out keeps the rate, null clears it, a
// number in range is taken and anything else is refused.
func TestPriceRateOf(t *testing.T) {
for _, c := range []struct {
raw string
r float64
keep bool
bad bool
}{
{"", 0, true, false},
{"null", 0, false, false},
{"0.8", 0.8, false, false},
{"1.5", 1.5, false, false},
{"0.1234", 0, false, true},
{"-1", 0, false, true},
{"1001", 0, false, true},
{`"x"`, 0, false, true},
} {
r, keep, err := priceRateOf(json.RawMessage(c.raw))
if (err != nil) != c.bad || r != c.r || keep != c.keep {
t.Errorf("%q: %v %v %v", c.raw, r, keep, err)
}
}
}