-
Notifications
You must be signed in to change notification settings - Fork 246
/
messenger_chat_context_test.go
78 lines (60 loc) · 2.56 KB
/
messenger_chat_context_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package protocol
import (
_ "github.com/mutecomm/go-sqlcipher/v4" // require go-sqlcipher that overrides default implementation
"github.com/status-im/status-go/eth-node/crypto"
"github.com/status-im/status-go/eth-node/types"
"github.com/status-im/status-go/images"
"github.com/status-im/status-go/multiaccounts/settings"
"github.com/status-im/status-go/protocol/protobuf"
)
func isImageWithNamePresent(imgs map[string]*protobuf.IdentityImage, name string) bool {
for k, v := range imgs {
if k == name && len(v.Payload) > 0 {
return true
}
}
return false
}
func (s *MessengerSuite) retrieveIdentityImages(alice, bob *Messenger, chat *Chat) map[string]*protobuf.IdentityImage {
s.Require().NoError(alice.settings.SaveSettingField(settings.DisplayName, "alice"))
identityImages := images.SampleIdentityImages()
identityImagesMap := make(map[string]images.IdentityImage)
for _, img := range identityImages {
img.KeyUID = s.m.account.KeyUID
identityImagesMap[img.Name] = img
}
err := s.m.multiAccounts.StoreIdentityImages(s.m.account.KeyUID, identityImages, true)
s.Require().NoError(err)
s.Require().NoError(alice.SaveChat(chat))
s.Require().NoError(bob.settings.SaveSettingField(settings.DisplayName, "bob"))
s.Require().NoError(bob.SaveChat(chat))
chatContext := GetChatContextFromChatType(chat.ChatType)
chatIdentity, err := alice.createChatIdentity(chatContext)
s.Require().NoError(err)
imgs := chatIdentity.Images
s.Require().NoError(err)
return imgs
}
func (s *MessengerSuite) TestTwoImagesAreAddedToChatIdentityForPrivateChat() {
alice := s.m
bob := s.newMessenger()
defer TearDownMessenger(&s.Suite, bob)
bobPkString := types.EncodeHex(crypto.FromECDSAPub(&bob.identity.PublicKey))
chat := CreateOneToOneChat(bobPkString, &bob.identity.PublicKey, alice.transport)
s.Require().Equal(privateChat, GetChatContextFromChatType(chat.ChatType))
imgs := s.retrieveIdentityImages(alice, bob, chat)
s.Require().Len(imgs, 2)
s.Require().Equal(true, isImageWithNamePresent(imgs, "thumbnail"))
s.Require().Equal(true, isImageWithNamePresent(imgs, "large"))
}
func (s *MessengerSuite) TestOneImageIsAddedToChatIdentityForPublicChat() {
alice := s.m
bob := s.newMessenger()
defer TearDownMessenger(&s.Suite, bob)
chat := CreatePublicChat("alic-and-bob-chat", &testTimeSource{})
s.Require().Equal(publicChat, GetChatContextFromChatType(chat.ChatType))
imgs := s.retrieveIdentityImages(alice, bob, chat)
s.Require().Len(imgs, 1)
s.Require().Equal(true, isImageWithNamePresent(imgs, "thumbnail"))
s.Require().Equal(false, isImageWithNamePresent(imgs, "large"))
}