feat(crm): align shared attachment payloads
This commit is contained in:
@@ -68,6 +68,7 @@ func (s *ConversationHandlerTestSuite) SetupSuite() {
|
||||
&model.Conversation{},
|
||||
&model.ConversationParticipant{},
|
||||
&model.Message{},
|
||||
&model.Attachment{},
|
||||
&model.InboxMember{},
|
||||
&model.Tag{},
|
||||
&model.ConversationLabel{},
|
||||
@@ -134,6 +135,7 @@ func (s *ConversationHandlerTestSuite) TearDownSuite() {
|
||||
}
|
||||
|
||||
func (s *ConversationHandlerTestSuite) TearDownTest() {
|
||||
s.db.Exec("DELETE FROM attachments")
|
||||
s.db.Exec("DELETE FROM conversations")
|
||||
s.db.Exec("DELETE FROM contact_inboxes")
|
||||
s.db.Exec("DELETE FROM contacts")
|
||||
@@ -420,6 +422,31 @@ func (s *ConversationHandlerTestSuite) TestListAttachments_InvalidConversationID
|
||||
assert.Equal(s.T(), http.StatusBadRequest, w.Code)
|
||||
}
|
||||
|
||||
func (s *ConversationHandlerTestSuite) TestListAttachmentsReturnsChatwootPayload() {
|
||||
message := &model.Message{AccountID: s.testAccount.ID, InboxID: s.testConv.InboxID, ConversationID: s.testConv.ID, Content: "file", MessageType: "incoming", ContentType: "text", Status: "sent"}
|
||||
s.Require().NoError(s.db.Create(message).Error)
|
||||
attachment := &model.Attachment{AccountID: s.testAccount.ID, MessageID: message.ID, FileType: "file", FileURL: "https://cdn.example.com/report.pdf", FileName: "report.pdf", FileSize: 2048}
|
||||
s.Require().NoError(s.db.Create(attachment).Error)
|
||||
|
||||
w := httptest.NewRecorder()
|
||||
req, _ := http.NewRequest("GET", fmt.Sprintf("%s/conversations/%d/attachments", s.accountURL(), s.testConv.ID), nil)
|
||||
s.router.ServeHTTP(w, req)
|
||||
|
||||
assert.Equal(s.T(), http.StatusOK, w.Code, w.Body.String())
|
||||
var resp map[string]any
|
||||
assert.NoError(s.T(), json.Unmarshal(w.Body.Bytes(), &resp))
|
||||
assert.Equal(s.T(), float64(1), resp["meta"].(map[string]any)["total_count"])
|
||||
payload := resp["payload"].([]any)
|
||||
assert.Len(s.T(), payload, 1)
|
||||
item := payload[0].(map[string]any)
|
||||
assert.Equal(s.T(), float64(attachment.ID), item["id"])
|
||||
assert.Equal(s.T(), float64(message.ID), item["message_id"])
|
||||
assert.Equal(s.T(), "file", item["file_type"])
|
||||
assert.Equal(s.T(), "https://cdn.example.com/report.pdf", item["data_url"])
|
||||
assert.Equal(s.T(), "pdf", item["extension"])
|
||||
assert.Contains(s.T(), item, "created_at")
|
||||
}
|
||||
|
||||
func (s *ConversationHandlerTestSuite) TestToggleTyping_InvalidAccountID() {
|
||||
w := httptest.NewRecorder()
|
||||
req, _ := http.NewRequest("POST", "/api/v1/accounts/abc/conversations/1/toggle_typing", bytes.NewBufferString(`{"typing_status":"on"}`))
|
||||
|
||||
Reference in New Issue
Block a user