feat(reports): align v2 report envelopes

This commit is contained in:
2026-06-06 23:01:46 +08:00
parent d48969f07f
commit 2d94ec9b53
7 changed files with 75 additions and 49 deletions
@@ -123,15 +123,14 @@ func (s *AnalyticsHandlerTestSuite) TestSummary_InvalidUntilFormat() {
func (s *AnalyticsHandlerTestSuite) TestSummary_EmptyData() {
w := httptest.NewRecorder()
req := httptest.NewRequest(http.MethodGet,
"/api/v1/accounts/1/reports/summary?since=2025-01-01T00:00:00Z&until=2025-01-31T00:00:00Z", nil)
"/api/v1/accounts/1/reports/summary?since=1735689600&until=1738281600", nil)
s.router.ServeHTTP(w, req)
s.Equal(http.StatusOK, w.Code)
var body map[string]interface{}
s.NoError(json.Unmarshal(w.Body.Bytes(), &body))
s.True(body["success"].(bool))
data := body["data"].(map[string]interface{})
s.NotNil(data["metrics"])
s.NotContains(body, "success")
s.NotNil(body["metrics"])
}
func (s *AnalyticsHandlerTestSuite) TestSummary_WithData() {
@@ -160,12 +159,11 @@ func (s *AnalyticsHandlerTestSuite) TestIndex_TimeseriesWithData() {
w := httptest.NewRecorder()
req := httptest.NewRequest(http.MethodGet,
"/api/v1/accounts/1/reports?metric=conversations_count&since=2025-01-01T00:00:00Z&until=2025-02-01T00:00:00Z&type=account&group_by=day", nil)
"/api/v1/accounts/1/reports?metric=conversations_count&since=1735689600&until=1738368000&type=account&group_by=day", nil)
s.router.ServeHTTP(w, req)
s.Equal(http.StatusOK, w.Code)
var body map[string]interface{}
s.NoError(json.Unmarshal(w.Body.Bytes(), &body))
data := body["data"].([]interface{})
var data []interface{}
s.NoError(json.Unmarshal(w.Body.Bytes(), &data))
s.Len(data, 1)
s.Equal(float64(1), data[0].(map[string]interface{})["value"])
}