feat(conversations): align destroy job

This commit is contained in:
2026-06-07 12:26:48 +08:00
parent bec65a86e4
commit 27f927327d
8 changed files with 152 additions and 7 deletions
@@ -212,7 +212,7 @@ func (h *ConversationHandler) Delete(c *gin.Context) {
Action: "destroy",
AuditedChanges: gin.H{"id": conversation.ID, "display_id": conversation.DisplayID},
})
response.NoContent(c)
c.Status(http.StatusOK)
}
// @Summary Assign an agent to a conversation
@@ -589,7 +589,8 @@ func (s *ConversationCrudTestSuite) TestDelete_Success() {
req, _ := http.NewRequest("DELETE", s.convURL(s.testConv.ID), nil)
s.router.ServeHTTP(w, req)
assert.Equal(s.T(), http.StatusNoContent, w.Code)
assert.Equal(s.T(), http.StatusOK, w.Code)
assert.Empty(s.T(), w.Body.String())
}
func (s *ConversationCrudTestSuite) TestDelete_InvalidAccountID() {
@@ -144,6 +144,7 @@ func (s *ConversationHandlerTestSuite) SetupSuite() {
conversations.GET("/:conversation_id/reporting_events", handler.ReportingEvents)
conversations.POST("/:conversation_id/toggle_typing", handler.ToggleTyping)
conversations.POST("/:conversation_id/update_last_seen", handler.UpdateLastSeen)
conversations.DELETE("/:conversation_id", handler.Delete)
}
}
}
@@ -448,6 +449,26 @@ func (s *ConversationHandlerTestSuite) TestTranscript_ConversationNotFound() {
assert.Equal(s.T(), http.StatusNotFound, w.Code)
}
func (s *ConversationHandlerTestSuite) TestDelete_SuccessReturnsChatwootHeadOK() {
w := httptest.NewRecorder()
req, _ := http.NewRequest(http.MethodDelete, s.accountURL()+"/conversations/"+strconv.FormatUint(uint64(s.testConv.ID), 10), nil)
s.router.ServeHTTP(w, req)
assert.Equal(s.T(), http.StatusOK, w.Code)
assert.Empty(s.T(), w.Body.String())
var deleted model.Conversation
assert.Error(s.T(), s.db.First(&deleted, s.testConv.ID).Error)
}
func (s *ConversationHandlerTestSuite) TestDelete_ConversationNotFound() {
w := httptest.NewRecorder()
req, _ := http.NewRequest(http.MethodDelete, s.accountURL()+"/conversations/9999", nil)
s.router.ServeHTTP(w, req)
assert.Equal(s.T(), http.StatusNotFound, w.Code)
}
// ========== UpdateCustomAttributes Handler Tests ==========
func (s *ConversationHandlerTestSuite) TestUpdateCustomAttributes_Success() {