2020-12-01 09:43:46 +00:00
|
|
|
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"}
|
2021-01-11 10:32:51 +00:00
|
|
|
response1 := &MessengerResponse{}
|
|
|
|
response1.AddChat(chat1)
|
2020-12-01 09:43:46 +00:00
|
|
|
|
2021-01-11 10:32:51 +00:00
|
|
|
response2 := &MessengerResponse{}
|
|
|
|
response2.AddChats([]*Chat{modifiedChat1, chat2})
|
2020-12-01 09:43:46 +00:00
|
|
|
|
|
|
|
require.NoError(t, response1.Merge(response2))
|
|
|
|
|
2021-01-11 10:32:51 +00:00
|
|
|
require.Len(t, response1.Chats(), 2)
|
|
|
|
require.Equal(t, modifiedChat1, response1.chats[modifiedChat1.ID])
|
|
|
|
require.Equal(t, chat2, response1.chats[chat2.ID])
|
2020-12-01 09:43:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestMessengerResponseMergeMessages(t *testing.T) {
|
|
|
|
message1 := &common.Message{ID: "1"}
|
|
|
|
modifiedMessage1 := &common.Message{ID: "1", From: "name"}
|
|
|
|
message2 := &common.Message{ID: "3"}
|
2021-06-03 13:11:55 +00:00
|
|
|
response1 := &MessengerResponse{}
|
|
|
|
response1.AddMessage(message1)
|
2020-12-01 09:43:46 +00:00
|
|
|
|
2021-06-03 13:11:55 +00:00
|
|
|
response2 := &MessengerResponse{}
|
|
|
|
response2.AddMessage(modifiedMessage1)
|
|
|
|
response2.AddMessage(message2)
|
2020-12-01 09:43:46 +00:00
|
|
|
|
|
|
|
require.NoError(t, response1.Merge(response2))
|
|
|
|
|
2021-06-03 13:11:55 +00:00
|
|
|
require.Len(t, response1.Messages(), 2)
|
2021-06-25 08:30:18 +00:00
|
|
|
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])
|
|
|
|
}
|
|
|
|
|
2020-12-01 09:43:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestMessengerResponseMergeNotImplemented(t *testing.T) {
|
|
|
|
response1 := &MessengerResponse{}
|
|
|
|
|
|
|
|
response2 := &MessengerResponse{
|
2022-01-12 16:02:01 +00:00
|
|
|
Invitations: []*GroupChatInvitation{{}},
|
2020-12-01 09:43:46 +00:00
|
|
|
}
|
|
|
|
require.Error(t, response1.Merge(response2))
|
|
|
|
|
|
|
|
}
|