Expand tracker analytics and dashboard UX
Test and publish / publish (push) Successful in 4m27s
Test and publish / test (push) Successful in 9m45s

This commit is contained in:
2026-10-23 20:16:50 +01:00
parent e0f8399ff7
commit 667091efb0
17 changed files with 1140 additions and 81 deletions
+26
View File
@@ -154,3 +154,29 @@ func TestLocation(t *testing.T) {
t.Errorf("unknown event: %d", code)
}
}
func TestSamplesReportsAndSettings(t *testing.T) {
srv, key := setup(t)
ts := time.Now().UTC().Add(-time.Hour).Truncate(time.Second)
body := `{"samples":[{"id":"s1","source":"watch","metric":"steps","ts":"` + ts.Format(time.RFC3339) + `","value":12,"unit":"count"}]}`
code, out := do(t, "POST", srv.URL+"/api/v1/samples", key, body)
if code != http.StatusOK || out["inserted"] != 1.0 {
t.Fatalf("sample ingest: %d %v", code, out)
}
code, out = do(t, "POST", srv.URL+"/api/v1/samples", key, body)
if code != http.StatusOK || out["inserted"] != 0.0 {
t.Fatalf("sample idempotency: %d %v", code, out)
}
code, out = do(t, "GET", srv.URL+"/api/v1/summary/range?from="+ts.Add(-time.Minute).Format(time.RFC3339)+"&to="+ts.Add(time.Minute).Format(time.RFC3339), key, "")
if code != http.StatusOK || len(out["samples"].([]any)) != 1 {
t.Fatalf("range summary: %d %v", code, out)
}
code, out = do(t, "PUT", srv.URL+"/api/v1/notifications/config", "", `{"enabled":true,"ntfy_topic":"goals","retention_days":30}`)
if code != http.StatusOK || out["ntfy_topic"] != "goals" {
t.Fatalf("notification config: %d %v", code, out)
}
code, out = do(t, "POST", srv.URL+"/api/v1/reports", "", `{"period_start":"`+ts.Format(time.RFC3339)+`","period_end":"`+ts.Add(time.Hour).Format(time.RFC3339)+`","model":"test","body":"summary"}`)
if code != http.StatusCreated || out["id"] == nil {
t.Fatalf("report create: %d %v", code, out)
}
}