feat(conversations): filter meta query source

This commit is contained in:
2026-06-07 03:04:15 +08:00
parent cdc0978476
commit a518a0de7e
5 changed files with 80 additions and 4 deletions
@@ -236,6 +236,31 @@ func (s *ConversationHandlerTestSuite) TestMeta_FiltersStatusAndIgnoresAssigneeT
assert.Equal(s.T(), int64(2), resp.Meta.AllCount)
}
func (s *ConversationHandlerTestSuite) TestMeta_QueryAndSourceIDFilters() {
contactInbox := &model.ContactInbox{ContactID: s.testConv.ContactID, InboxID: s.testConv.InboxID, SourceID: "widget-source"}
s.Require().NoError(s.db.Create(contactInbox).Error)
s.Require().NoError(s.db.Model(s.testConv).Updates(map[string]any{"contact_inbox_id": contactInbox.ID, "assignee_id": s.testUser.ID}).Error)
other := &model.Conversation{AccountID: s.testAccount.ID, InboxID: s.testConv.InboxID, ContactID: s.testConv.ContactID, Status: "open", ChannelType: "web_widget", Channel: "web_widget"}
s.Require().NoError(s.db.Create(other).Error)
s.Require().NoError(s.db.Create(&model.Message{AccountID: s.testAccount.ID, InboxID: s.testConv.InboxID, ConversationID: s.testConv.ID, Content: "needle from widget", MessageType: string(model.MessageTypeIncoming)}).Error)
s.Require().NoError(s.db.Create(&model.Message{AccountID: s.testAccount.ID, InboxID: s.testConv.InboxID, ConversationID: other.ID, Content: "needle from other", MessageType: string(model.MessageTypeIncoming)}).Error)
w := httptest.NewRecorder()
req, _ := http.NewRequest("GET", s.accountURL()+"/conversations/meta?q=needle&source_id=widget-source", nil)
s.router.ServeHTTP(w, req)
assert.Equal(s.T(), http.StatusOK, w.Code)
var resp struct {
Meta struct {
MineCount int64 `json:"mine_count"`
AllCount int64 `json:"all_count"`
} `json:"meta"`
}
s.Require().NoError(json.Unmarshal(w.Body.Bytes(), &resp))
assert.Equal(s.T(), int64(1), resp.Meta.AllCount)
assert.Equal(s.T(), int64(1), resp.Meta.MineCount)
}
func (s *ConversationHandlerTestSuite) TestMeta_InvalidAccountID() {
w := httptest.NewRecorder()
req, _ := http.NewRequest("GET", "/api/v1/accounts/invalid/conversations/meta", nil)