feat(conversations): align search sender names
This commit is contained in:
@@ -181,6 +181,7 @@ func (s *ConversationCrudTestSuite) TearDownTest() {
|
||||
s.db.Exec("DELETE FROM inboxes")
|
||||
s.db.Exec("DELETE FROM messages")
|
||||
s.db.Exec("DELETE FROM account_users")
|
||||
s.db.Exec("DELETE FROM users")
|
||||
s.db.Exec("DELETE FROM accounts")
|
||||
s.db.Exec("DELETE FROM teams")
|
||||
s.db.Exec("DELETE FROM team_members")
|
||||
@@ -897,10 +898,12 @@ func (s *ConversationCrudTestSuite) TestUpdateLabels_NotFound() {
|
||||
// ========== Search Handler Tests ==========
|
||||
|
||||
func (s *ConversationCrudTestSuite) TestSearch_Success() {
|
||||
s.Require().NoError(s.db.Create(&model.Message{AccountID: s.testAccount.ID, InboxID: s.testInbox.ID, ConversationID: s.testConv.ID, Content: "needle open", MessageType: string(model.MessageTypeIncoming)}).Error)
|
||||
s.Require().NoError(s.db.Create(&model.Message{AccountID: s.testAccount.ID, InboxID: s.testInbox.ID, ConversationID: s.testConv.ID, SenderID: &s.testContact.ID, SenderType: string(model.SenderTypeContact), Content: "needle open", MessageType: string(model.MessageTypeIncoming)}).Error)
|
||||
agent := &model.User{AccountID: s.testAccount.ID, Name: "Search Agent", Email: "search-agent-" + strconv.FormatUint(uint64(s.testAccount.ID), 10) + "@example.com", Password: "secret", Role: "agent"}
|
||||
s.Require().NoError(s.db.Create(agent).Error)
|
||||
resolved := &model.Conversation{AccountID: s.testAccount.ID, InboxID: s.testInbox.ID, ContactID: s.testContact.ID, Status: "resolved", ChannelType: "web_widget", Channel: "web_widget"}
|
||||
s.Require().NoError(s.db.Create(resolved).Error)
|
||||
s.Require().NoError(s.db.Create(&model.Message{AccountID: s.testAccount.ID, InboxID: s.testInbox.ID, ConversationID: resolved.ID, Content: "needle resolved", MessageType: string(model.MessageTypeOutgoing)}).Error)
|
||||
s.Require().NoError(s.db.Create(&model.Message{AccountID: s.testAccount.ID, InboxID: s.testInbox.ID, ConversationID: resolved.ID, SenderID: &agent.ID, SenderType: string(model.SenderTypeUser), Content: "needle resolved", MessageType: string(model.MessageTypeOutgoing)}).Error)
|
||||
|
||||
w := httptest.NewRecorder()
|
||||
req, _ := http.NewRequest("GET", s.accountURL()+"/conversations/search?q=needle&status=open", nil)
|
||||
@@ -936,6 +939,16 @@ func (s *ConversationCrudTestSuite) TestSearch_Success() {
|
||||
assert.Equal(s.T(), s.testInbox.Name, resp.Payload[0].Inbox["name"])
|
||||
assert.NotEmpty(s.T(), resp.Payload[0].Messages)
|
||||
assert.Equal(s.T(), float64(0), resp.Payload[0].Messages[0]["message_type"])
|
||||
senderNamesByContent := map[string]string{}
|
||||
for _, conversation := range resp.Payload {
|
||||
for _, message := range conversation.Messages {
|
||||
if senderName, ok := message["sender_name"].(string); ok {
|
||||
senderNamesByContent[message["content"].(string)] = senderName
|
||||
}
|
||||
}
|
||||
}
|
||||
assert.Equal(s.T(), s.testContact.Name, senderNamesByContent["needle open"])
|
||||
assert.Equal(s.T(), agent.Name, senderNamesByContent["needle resolved"])
|
||||
}
|
||||
|
||||
func (s *ConversationCrudTestSuite) TestSearch_InvalidAccountID() {
|
||||
|
||||
Reference in New Issue
Block a user