Expand tracker analytics and dashboard UX
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user