feat(reports): align v2 timeseries timezones
This commit is contained in:
@@ -179,8 +179,27 @@ func (s *AnalyticsHandlerTestSuite) TestIndex_TimeseriesWithData() {
|
||||
s.Equal(http.StatusOK, w.Code)
|
||||
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"])
|
||||
s.Len(data, 31)
|
||||
s.Equal(float64(1), data[14].(map[string]interface{})["value"])
|
||||
}
|
||||
|
||||
func (s *AnalyticsHandlerTestSuite) TestIndex_TimeseriesHonorsTimezoneOffset() {
|
||||
conv := model.Conversation{AccountID: s.accountID, InboxID: 1, ContactID: 1, Status: string(model.ConversationStatusOpen), ChannelType: "web_widget", Channel: "web_widget", Base: model.Base{CreatedAt: parseTime("2025-01-02T01:00:00Z")}}
|
||||
s.Require().NoError(s.db.Create(&conv).Error)
|
||||
|
||||
w := httptest.NewRecorder()
|
||||
req := httptest.NewRequest(http.MethodGet,
|
||||
"/api/v1/accounts/1/reports?metric=conversations_count&since=1735689600&until=1735862400&type=account&group_by=day&timezone_offset=-8", nil)
|
||||
s.router.ServeHTTP(w, req)
|
||||
s.Equal(http.StatusOK, w.Code)
|
||||
var data []map[string]interface{}
|
||||
s.NoError(json.Unmarshal(w.Body.Bytes(), &data))
|
||||
s.Len(data, 3)
|
||||
loc := time.FixedZone("report", -8*3600)
|
||||
s.Equal(float64(time.Date(2024, 12, 31, 0, 0, 0, 0, loc).Unix()), data[0]["timestamp"])
|
||||
s.Equal(float64(time.Date(2025, 1, 1, 0, 0, 0, 0, loc).Unix()), data[1]["timestamp"])
|
||||
s.Equal(float64(0), data[0]["value"])
|
||||
s.Equal(float64(1), data[1]["value"])
|
||||
}
|
||||
|
||||
// ========== AgentMetrics ==========
|
||||
|
||||
Reference in New Issue
Block a user