status-go/protocol/messenger_response_test.go

78 lines
2.1 KiB
Go
Raw Normal View History

package protocol
import (
"testing"
"github.com/stretchr/testify/require"
"github.com/status-im/status-go/protocol/common"
"github.com/status-im/status-go/protocol/encryption/multidevice"
)
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)
2021-01-11 10:32:51 +00:00
response2 := &MessengerResponse{}
response2.AddChats([]*Chat{modifiedChat1, chat2})
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])
}
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)
2021-06-03 13:11:55 +00:00
response2 := &MessengerResponse{}
response2.AddMessage(modifiedMessage1)
response2.AddMessage(message2)
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])
}
}
func TestMessengerResponseMergeNotImplemented(t *testing.T) {
response1 := &MessengerResponse{}
response2 := &MessengerResponse{
Contacts: []*Contact{&Contact{}},
}
require.Error(t, response1.Merge(response2))
response2 = &MessengerResponse{
Installations: []*multidevice.Installation{&multidevice.Installation{}},
}
require.Error(t, response1.Merge(response2))
response2 = &MessengerResponse{
EmojiReactions: []*EmojiReaction{&EmojiReaction{}},
}
require.Error(t, response1.Merge(response2))
response2 = &MessengerResponse{
Invitations: []*GroupChatInvitation{&GroupChatInvitation{}},
}
require.Error(t, response1.Merge(response2))
}