Align GoChat with Chatwoot frontend contracts

This commit is contained in:
2026-06-13 22:13:32 +08:00
parent 71abf58636
commit d884fdda0a
162 changed files with 9825 additions and 528 deletions
@@ -217,6 +217,40 @@ func (s *DraftMessageHandlerTestSuite) Test_ShowDraft_UsesDisplayIDRoute() {
assert.Equal(s.T(), "Display draft", resp["message"])
}
func (s *DraftMessageHandlerTestSuite) Test_CollectionDrafts_UseDisplayIDRoute() {
s.Require().NoError(s.db.Exec("DELETE FROM draft_messages").Error)
displayID := uint(92)
s.testConv.DisplayID = &displayID
s.Require().NoError(s.db.Save(s.testConv).Error)
body := map[string]interface{}{"content": "Display collection draft"}
b, _ := json.Marshal(body)
w := httptest.NewRecorder()
req, _ := http.NewRequest("POST", makeDraftCollectionURL(s.testAccount.ID, displayID), bytes.NewReader(b))
req.Header.Set("Content-Type", "application/json")
s.router.ServeHTTP(w, req)
assert.Equal(s.T(), http.StatusOK, w.Code)
var created map[string]interface{}
s.Require().NoError(json.Unmarshal(w.Body.Bytes(), &created))
data := created["data"].(map[string]interface{})
assert.Equal(s.T(), "Display collection draft", data["content"])
assert.Equal(s.T(), float64(s.testConv.ID), data["conversation_id"])
w = httptest.NewRecorder()
req, _ = http.NewRequest("GET", makeDraftCollectionURL(s.testAccount.ID, displayID), nil)
s.router.ServeHTTP(w, req)
assert.Equal(s.T(), http.StatusOK, w.Code)
var listed map[string]interface{}
s.Require().NoError(json.Unmarshal(w.Body.Bytes(), &listed))
items := listed["data"].([]interface{})
s.Require().Len(items, 1)
item := items[0].(map[string]interface{})
assert.Equal(s.T(), "Display collection draft", item["content"])
assert.Equal(s.T(), float64(s.testConv.ID), item["conversation_id"])
}
func (s *DraftMessageHandlerTestSuite) Test_ListDrafts() {
// First create a draft
body := map[string]interface{}{