mirror of
https://github.com/status-im/status-go.git
synced 2025-01-09 14:16:21 +00:00
b69042e7d7
This commit fixes an issue where when accepting a contact request the other end would display an extra notification. It also changes WaitOnResponse to collect results. This should make tests less flaky, since sometimes messages are processed in different batches. Now we need to be though exact on what we expect from the response (i.e use == instead of >, otherwise the same behavior applies) This uncovered a couple of issues with messenger.Merge, so I have moved the struct to use a map based collection instead of an array.
62 lines
1.6 KiB
Go
62 lines
1.6 KiB
Go
package protocol
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/status-im/status-go/protocol/common"
|
|
)
|
|
|
|
func TestMessengerResponseMergeChats(t *testing.T) {
|
|
chat1 := &Chat{ID: "1"}
|
|
modifiedChat1 := &Chat{ID: "1", Name: "name"}
|
|
chat2 := &Chat{ID: "3"}
|
|
response1 := &MessengerResponse{}
|
|
response1.AddChat(chat1)
|
|
|
|
response2 := &MessengerResponse{}
|
|
response2.AddChats([]*Chat{modifiedChat1, chat2})
|
|
|
|
require.NoError(t, response1.Merge(response2))
|
|
|
|
require.Len(t, response1.Chats(), 2)
|
|
require.Equal(t, modifiedChat1, response1.chats[modifiedChat1.ID])
|
|
require.Equal(t, chat2, response1.chats[chat2.ID])
|
|
}
|
|
|
|
func TestMessengerResponseMergeMessages(t *testing.T) {
|
|
message1 := &common.Message{ID: "1"}
|
|
modifiedMessage1 := &common.Message{ID: "1", From: "name"}
|
|
message2 := &common.Message{ID: "3"}
|
|
response1 := &MessengerResponse{}
|
|
response1.AddMessage(message1)
|
|
|
|
response2 := &MessengerResponse{}
|
|
response2.AddMessage(modifiedMessage1)
|
|
response2.AddMessage(message2)
|
|
|
|
require.NoError(t, response1.Merge(response2))
|
|
|
|
require.Len(t, response1.Messages(), 2)
|
|
messages := response1.Messages()
|
|
if messages[0].ID == modifiedMessage1.ID {
|
|
require.Equal(t, modifiedMessage1, messages[0])
|
|
require.Equal(t, message2, messages[1])
|
|
} else {
|
|
require.Equal(t, modifiedMessage1, messages[1])
|
|
require.Equal(t, message2, messages[0])
|
|
}
|
|
|
|
}
|
|
|
|
func TestMessengerResponseMergeNotImplemented(t *testing.T) {
|
|
response1 := &MessengerResponse{}
|
|
|
|
response2 := &MessengerResponse{
|
|
Invitations: []*GroupChatInvitation{{}},
|
|
}
|
|
require.Error(t, response1.Merge(response2))
|
|
|
|
}
|