feat(conversations): align custom attribute response
This commit is contained in:
@@ -746,7 +746,7 @@ func (h *ConversationHandler) UpdateCustomAttributes(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{"custom_attributes": conversation.CustomAttributes})
|
||||
c.JSON(http.StatusOK, gin.H{"custom_attributes": jsonObject(conversation.CustomAttributes)})
|
||||
}
|
||||
|
||||
// ListAttachments returns paginated message attachments for a conversation.
|
||||
|
||||
@@ -338,6 +338,28 @@ func (s *ConversationHandlerTestSuite) TestUpdateCustomAttributes_Success() {
|
||||
assert.NoError(s.T(), err)
|
||||
assert.NotContains(s.T(), rawResp, "id")
|
||||
assert.NotContains(s.T(), rawResp, "success")
|
||||
assert.NotContains(s.T(), rawResp, "payload")
|
||||
assert.NotContains(s.T(), rawResp, "meta")
|
||||
}
|
||||
|
||||
func (s *ConversationHandlerTestSuite) TestUpdateCustomAttributes_EmptyObjectReturnsChatwootShape() {
|
||||
body := map[string]interface{}{
|
||||
"custom_attributes": map[string]interface{}{},
|
||||
}
|
||||
bodyBytes, _ := json.Marshal(body)
|
||||
|
||||
w := httptest.NewRecorder()
|
||||
req, _ := http.NewRequest("POST", s.accountURL()+"/conversations/"+strconv.FormatUint(uint64(s.testConv.ID), 10)+"/custom_attributes", bytes.NewReader(bodyBytes))
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
s.router.ServeHTTP(w, req)
|
||||
|
||||
assert.Equal(s.T(), http.StatusOK, w.Code)
|
||||
|
||||
var rawResp map[string]interface{}
|
||||
err := json.Unmarshal(w.Body.Bytes(), &rawResp)
|
||||
assert.NoError(s.T(), err)
|
||||
assert.Equal(s.T(), map[string]interface{}{}, rawResp["custom_attributes"])
|
||||
assert.Len(s.T(), rawResp, 1)
|
||||
}
|
||||
|
||||
func (s *ConversationHandlerTestSuite) TestUpdateCustomAttributes_InvalidAccountID() {
|
||||
|
||||
Reference in New Issue
Block a user