summaryrefslogtreecommitdiff
path: root/internal/controlplane/usage_analytics_test.go
diff options
context:
space:
mode:
authorChia <Chia@93.nz>2026-08-06 09:29:41 +1200
committerChia <Chia@93.nz>2026-08-06 09:32:46 +1200
commit41e322c53d7b4b796eb377d0df9c29ecd10ba431 (patch)
treec730526150e55e39b822d5197e4a20318ecaa449 /internal/controlplane/usage_analytics_test.go
parenteadb2ffe85c43cf6fc741c9823cd28eedb4a844c (diff)
feat: complete commercial control plane, billing, auth, and model catalog
- add PostgreSQL control-plane persistence with Redis-degraded hot reload - implement prepaid balance, usage ledger, Stripe top-up and reconciliation - add registration, email verification, password reset, invitations and RBAC - support TOTP, Passkey MFA, device sessions, quotas and rate limits - add tenant billing profiles, audit logs and operational readiness checks - build authenticated admin console, Quickstart, Playground and usage analytics - add public model catalog with pricing, filtering and cost estimation - support OpenAI Responses providers and provider health failover - validate real upstream usage reporting and balance settlement
Diffstat (limited to 'internal/controlplane/usage_analytics_test.go')
-rw-r--r--internal/controlplane/usage_analytics_test.go34
1 files changed, 34 insertions, 0 deletions
diff --git a/internal/controlplane/usage_analytics_test.go b/internal/controlplane/usage_analytics_test.go
new file mode 100644
index 0000000..2372be6
--- /dev/null
+++ b/internal/controlplane/usage_analytics_test.go
@@ -0,0 +1,34 @@
+package controlplane
+
+import "testing"
+
+func TestChargeChange(t *testing.T) {
+ tests := []struct {
+ name string
+ current, previous int64
+ want *float64
+ }{
+ {name: "no activity", current: 0, previous: 0, want: nil},
+ {name: "new spend has no finite percentage", current: 25, previous: 0, want: nil},
+ {name: "increase", current: 125, previous: 25, want: floatPointer(400)},
+ {name: "decrease", current: 25, previous: 100, want: floatPointer(-75)},
+ }
+ for _, test := range tests {
+ t.Run(test.name, func(t *testing.T) {
+ got := chargeChange(test.current, test.previous)
+ if test.want == nil {
+ if got != nil {
+ t.Fatalf("chargeChange() = %v, want nil", *got)
+ }
+ return
+ }
+ if got == nil || *got != *test.want {
+ t.Fatalf("chargeChange() = %v, want %v", got, *test.want)
+ }
+ })
+ }
+}
+
+func floatPointer(value float64) *float64 {
+ return &value
+}