fix flaky test TestMarkMessagesSeenMarksNotificationsRead (#4781)
* fix flaky test TestMarkMessagesSeenMarksNotificationsRead * address review feedback
This commit is contained in:
parent
f650915a49
commit
01b3f8ace4
|
@ -2,7 +2,6 @@ package protocol
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
|
@ -376,16 +375,16 @@ func (s *MessengerActivityCenterMessageSuite) prepareCommunityChannelWithMention
|
||||||
"no messages",
|
"no messages",
|
||||||
)
|
)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
replyNotification := response.ActivityCenterNotifications()[0]
|
||||||
s.Require().False(response.ActivityCenterNotifications()[0].Read)
|
s.Require().False(response.ActivityCenterNotifications()[0].Read)
|
||||||
|
|
||||||
// There is an extra message with reply
|
// One message is the community message, the other is the reply to the community message
|
||||||
if response.Messages()[0].ID == response.ActivityCenterNotifications()[0].Message.ID {
|
s.Require().Len(response.Messages(), 2)
|
||||||
replyMessage = response.Messages()[0]
|
|
||||||
} else if response.Messages()[1].ID == response.ActivityCenterNotifications()[0].Message.ID {
|
replyMessage, ok := response.messages[replyNotification.Message.ID]
|
||||||
replyMessage = response.Messages()[1]
|
s.Require().True(ok)
|
||||||
} else {
|
s.Require().NotNil(replyMessage)
|
||||||
s.Error(errors.New("can't find corresponding message in the response"))
|
s.Require().Equal(replyMessage.ID, replyNotification.ID.String())
|
||||||
}
|
|
||||||
|
|
||||||
s.confirmMentionAndReplyNotificationsRead(alice, mentionMessage, replyMessage, false)
|
s.confirmMentionAndReplyNotificationsRead(alice, mentionMessage, replyMessage, false)
|
||||||
|
|
||||||
|
@ -412,9 +411,9 @@ func (s *MessengerActivityCenterMessageSuite) confirmMentionAndReplyNotification
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
s.Require().Len(notifResponse.Notifications, 1)
|
s.Require().Len(notifResponse.Notifications, 1)
|
||||||
s.Require().Equal(read, notifResponse.Notifications[0].Read)
|
s.Require().Equal(read, notifResponse.Notifications[0].Read)
|
||||||
|
s.Require().Equal(mentionMessage.ID, notifResponse.Notifications[0].ID.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
func (s *MessengerActivityCenterMessageSuite) TestMarkMessagesSeenMarksNotificationsRead() {
|
func (s *MessengerActivityCenterMessageSuite) TestMarkMessagesSeenMarksNotificationsRead() {
|
||||||
alice, _, mentionMessage, replyMessage, _ := s.prepareCommunityChannelWithMentionAndReply()
|
alice, _, mentionMessage, replyMessage, _ := s.prepareCommunityChannelWithMentionAndReply()
|
||||||
|
|
||||||
|
@ -427,7 +426,6 @@ func (s *MessengerActivityCenterMessageSuite) TestMarkMessagesSeenMarksNotificat
|
||||||
|
|
||||||
s.confirmMentionAndReplyNotificationsRead(alice, mentionMessage, replyMessage, true)
|
s.confirmMentionAndReplyNotificationsRead(alice, mentionMessage, replyMessage, true)
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
func (s *MessengerActivityCenterMessageSuite) TestMarkAllReadMarksNotificationsRead() {
|
func (s *MessengerActivityCenterMessageSuite) TestMarkAllReadMarksNotificationsRead() {
|
||||||
alice, _, mentionMessage, replyMessage, _ := s.prepareCommunityChannelWithMentionAndReply()
|
alice, _, mentionMessage, replyMessage, _ := s.prepareCommunityChannelWithMentionAndReply()
|
||||||
|
|
|
@ -687,6 +687,13 @@ func (r *MessengerResponse) DiscordMessageAttachments() []*protobuf.DiscordMessa
|
||||||
return attachments
|
return attachments
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Messages extracts the messages from the response and returns them as a slice.
|
||||||
|
// Since 'r.messages' is a map, the order of messages in the resulting slice is not
|
||||||
|
// guaranteed and can vary with each call to this method. This is inherent to Go's map
|
||||||
|
// iteration behavior, which does not define a sequence for the order of map elements.
|
||||||
|
// Consumers should not depend on the ordering of messages in the slice for any logic
|
||||||
|
// that requires consistent ordering, as map iteration order can change when keys are
|
||||||
|
// added or deleted. Consider sorting the slice after retrieval if a specific order is needed.
|
||||||
func (r *MessengerResponse) Messages() []*common.Message {
|
func (r *MessengerResponse) Messages() []*common.Message {
|
||||||
var ms []*common.Message
|
var ms []*common.Message
|
||||||
for _, m := range r.messages {
|
for _, m := range r.messages {
|
||||||
|
|
Loading…
Reference in New Issue