Align GoChat with Chatwoot frontend contracts
This commit is contained in:
@@ -158,6 +158,45 @@ func (s *AuditHandlerTestSuite) TestList_AssociatedAccountScopeAndFixedPageSize(
|
||||
assert.Len(s.T(), body["audit_logs"].([]any), 1)
|
||||
}
|
||||
|
||||
func (s *AuditHandlerTestSuite) TestList_ChatwootPaginationMetaAndDescendingOrder() {
|
||||
r := gin.New()
|
||||
r.GET("/api/v1/accounts/:account_id/audit_logs", withAuditRole("administrator", s.handler.List))
|
||||
|
||||
associatedID := s.account.ID
|
||||
createdAt := time.Unix(1710000000, 0).UTC()
|
||||
for i := 0; i < 30; i++ {
|
||||
s.Require().NoError(s.db.Create(&model.Audit{
|
||||
AuditableType: "Conversation",
|
||||
AuditableID: uint(i + 1),
|
||||
Action: "update",
|
||||
AuditedChanges: json.RawMessage(`{}`),
|
||||
AssociatedType: "Account",
|
||||
AssociatedID: &associatedID,
|
||||
CreatedAt: createdAt.Add(time.Duration(i) * time.Minute),
|
||||
}).Error)
|
||||
}
|
||||
|
||||
w := httptest.NewRecorder()
|
||||
req, _ := http.NewRequest("GET", fmt.Sprintf("/api/v1/accounts/%d/audit_logs?page=2", s.account.ID), nil)
|
||||
r.ServeHTTP(w, req)
|
||||
|
||||
assert.Equal(s.T(), http.StatusOK, w.Code)
|
||||
var body map[string]any
|
||||
s.Require().NoError(json.Unmarshal(w.Body.Bytes(), &body))
|
||||
assert.Equal(s.T(), float64(25), body["per_page"])
|
||||
assert.Equal(s.T(), float64(2), body["current_page"])
|
||||
assert.Equal(s.T(), float64(30), body["total_entries"])
|
||||
|
||||
logs := body["audit_logs"].([]any)
|
||||
s.Require().Len(logs, 5)
|
||||
for index, item := range logs {
|
||||
log := item.(map[string]any)
|
||||
expectedAuditableID := float64(5 - index)
|
||||
assert.Equal(s.T(), expectedAuditableID, log["auditable_id"])
|
||||
assert.Equal(s.T(), float64(createdAt.Add(time.Duration(4-index)*time.Minute).Unix()), log["created_at"])
|
||||
}
|
||||
}
|
||||
|
||||
func (s *AuditHandlerTestSuite) TestList_UnauthorizedForAgent() {
|
||||
r := gin.New()
|
||||
r.GET("/api/v1/accounts/:account_id/audit_logs", withAuditRole("agent", s.handler.List))
|
||||
|
||||
Reference in New Issue
Block a user