Initial commit of Descrybe v2 without local scratch artifacts.
Drop one-shot tmp/axe scripts and agent i18n scratch so the Gitea tree is deployable.
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
package httpapi
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestAdminAnalyticsSummaryOnly(t *testing.T) {
|
||||
t.Parallel()
|
||||
cases := []struct {
|
||||
raw string
|
||||
want bool
|
||||
}{
|
||||
{"", false},
|
||||
{"summary=0", false},
|
||||
{"summary=1", true},
|
||||
{"summary=true", true},
|
||||
{"summary_only=yes", true},
|
||||
{"summary_only=no", false},
|
||||
}
|
||||
for _, c := range cases {
|
||||
req := httptest.NewRequest(http.MethodGet, "/api/admin/analytics?"+c.raw, nil)
|
||||
if got := adminAnalyticsSummaryOnly(req); got != c.want {
|
||||
t.Fatalf("%q: got %v want %v", c.raw, got, c.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestClampAdminAnalyticsDays(t *testing.T) {
|
||||
t.Parallel()
|
||||
cases := []struct {
|
||||
in, want int
|
||||
}{
|
||||
{0, adminAnalyticsMinDays},
|
||||
{3, adminAnalyticsMinDays},
|
||||
{7, 7},
|
||||
{30, 30},
|
||||
{90, 90},
|
||||
{120, adminAnalyticsMaxDays},
|
||||
}
|
||||
for _, c := range cases {
|
||||
if got := clampAdminAnalyticsDays(c.in); got != c.want {
|
||||
t.Fatalf("clamp(%d)=%d want %d", c.in, got, c.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestFillAdminDaySeries(t *testing.T) {
|
||||
t.Parallel()
|
||||
since := time.Date(2026, 8, 1, 0, 0, 0, 0, time.UTC)
|
||||
src := map[string]adminDayPoint{
|
||||
"2026-08-01": {Date: "2026-08-01", Tokens: 10, Products: 2},
|
||||
"2026-08-03": {Date: "2026-08-03", Tokens: 5, Products: 1},
|
||||
}
|
||||
out := fillAdminDaySeries(since, 3, src, func(p adminDayPoint) adminDayPoint {
|
||||
return adminDayPoint{Date: p.Date, Tokens: p.Tokens, Products: p.Products}
|
||||
})
|
||||
if len(out) != 3 {
|
||||
t.Fatalf("len=%d", len(out))
|
||||
}
|
||||
if out[0].Tokens != 10 || out[1].Tokens != 0 || out[2].Tokens != 5 {
|
||||
t.Fatalf("unexpected series: %+v", out)
|
||||
}
|
||||
if out[1].Date != "2026-08-02" {
|
||||
t.Fatalf("gap date=%s", out[1].Date)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user