feat(conversations): align chatwoot message serializers

This commit is contained in:
2026-06-05 01:52:07 +08:00
parent c964d6c8fd
commit 9f89cbfe7c
12 changed files with 908 additions and 208 deletions
@@ -13,7 +13,6 @@ import (
"github.com/gin-gonic/gin"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
"gorm.io/datatypes"
"gorm.io/driver/sqlite"
"gorm.io/gorm"
"gorm.io/gorm/logger"
@@ -209,12 +208,12 @@ func (s *ConversationHandlerTestSuite) TestUnread_Success() {
assert.Equal(s.T(), http.StatusOK, w.Code)
var resp struct {
Success bool `json:"success"`
Data interface{} `json:"data"`
ID uint `json:"id"`
Status string `json:"status"`
}
err := json.Unmarshal(w.Body.Bytes(), &resp)
assert.NoError(s.T(), err)
assert.True(s.T(), resp.Success)
assert.Equal(s.T(), s.testConv.ID, resp.ID)
}
func (s *ConversationHandlerTestSuite) TestUnread_InvalidAccountID() {
@@ -330,16 +329,13 @@ func (s *ConversationHandlerTestSuite) TestUpdateCustomAttributes_Success() {
assert.Equal(s.T(), http.StatusOK, w.Code)
var resp struct {
Success bool `json:"success"`
Data struct {
ID uint `json:"id"`
CustomAttributes datatypes.JSON `json:"custom_attributes"`
} `json:"data"`
ID uint `json:"id"`
CustomAttributes map[string]interface{} `json:"custom_attributes"`
}
err := json.Unmarshal(w.Body.Bytes(), &resp)
assert.NoError(s.T(), err)
assert.True(s.T(), resp.Success)
assert.NotNil(s.T(), resp.Data.CustomAttributes)
assert.Equal(s.T(), s.testConv.ID, resp.ID)
assert.Equal(s.T(), "vip_customer", resp.CustomAttributes["priority_reason"])
}
func (s *ConversationHandlerTestSuite) TestUpdateCustomAttributes_InvalidAccountID() {
@@ -465,4 +461,4 @@ func (s *ConversationHandlerTestSuite) TestUpdateLastSeen_InvalidConversationID(
// Run the test suite
func TestConversationHandlerTestSuite(t *testing.T) {
suite.Run(t, new(ConversationHandlerTestSuite))
}
}