Skip to content

Commit

Permalink
Updated e2e tests to include private chat context
Browse files Browse the repository at this point in the history
But at the moment private chat context isn't working, definitely something to do with not receiving the ContactCodeAdvertisement
  • Loading branch information
Samyoul committed Sep 1, 2021
1 parent 78b5b5a commit 09fbc16
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 87 deletions.
3 changes: 3 additions & 0 deletions protocol/messenger.go
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,8 @@ func (m *Messenger) publishContactCode() error {
return err
}

m.logger.Debug("attached chat identity", zap.Int("images len", len(contactCodeAdvertisement.ChatIdentity.Images)))

payload, err = proto.Marshal(contactCodeAdvertisement)
if err != nil {
return err
Expand All @@ -634,6 +636,7 @@ func (m *Messenger) publishContactCode() error {
if err != nil {
m.logger.Warn("failed to send a contact code", zap.Error(err))
}
m.logger.Debug("contact code sent")
return err
}

Expand Down
212 changes: 125 additions & 87 deletions protocol/messenger_Identity_image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,114 +206,152 @@ func (s *MessengerProfilePictureHandlerSuite) TestE2eSendingReceivingProfilePict
"bob": {true, false},
}

chatContexts := []chatContext {
publicChat,
//privateChat,
}

// TODO Set option for testing between private and public chat types
// private types need to send and received Contact Code message with attached chat identity
// private types send large and thumbnail image payloads

// TODO see if possible to push each test scenario into a go routine

for sn, ss := range profilePicShowSettings {
for vn, vs := range profilePicViewSettings {
for _, ac := range isContactFor["alice"] {
for _, bc := range isContactFor["bob"] {
s.SetupTest()
s.logger.Info("testing with criteria:",
zap.String("profile picture Show Settings", sn),
zap.String("profile picture View Settings", vn),
zap.Bool("bob in Alice's Contacts", ac),
zap.Bool("alice in Bob's Contacts", bc),
)

expectPicture, err := resultExpected(ss, vs, ac, bc)
s.logger.Debug("expect to receive a profile pic?",
zap.Bool("result", expectPicture),
zap.Error(err))

// Store profile pictures
iis := s.generateAndStoreIdentityImages(s.alice)

err = s.alice.settings.SaveSetting("profile-pictures-show-to", ss)
s.NoError(err)
err = s.bob.settings.SaveSetting("profile-pictures-visibility", vs)
s.NoError(err)

if ac {
_, err = s.alice.AddContact(context.Background(), s.generateKeyUID(&s.bob.identity.PublicKey))
for _, cc := range chatContexts {
for sn, ss := range profilePicShowSettings {
for vn, vs := range profilePicViewSettings {
for _, ac := range isContactFor["alice"] {
for _, bc := range isContactFor["bob"] {
s.SetupTest()
s.logger.Info("testing with criteria:",
zap.String("chat context type", string(cc)),
zap.String("profile picture Show Settings", sn),
zap.String("profile picture View Settings", vn),
zap.Bool("bob in Alice's Contacts", ac),
zap.Bool("alice in Bob's Contacts", bc),
)

expectPicture, err := resultExpected(ss, vs, ac, bc)
s.logger.Debug("expect to receive a profile pic?",
zap.Bool("result", expectPicture),
zap.Error(err))

// Store profile pictures
iis := s.generateAndStoreIdentityImages(s.alice)

err = s.alice.settings.SaveSetting("profile-pictures-show-to", ss)
s.NoError(err)
}
if bc {
_, err = s.bob.AddContact(context.Background(), s.generateKeyUID(&s.alice.identity.PublicKey))
err = s.bob.settings.SaveSetting("profile-pictures-visibility", vs)
s.NoError(err)
}

// Alice opens creates a public chat
aChat := CreatePublicChat("status", s.alice.transport)
err = s.alice.SaveChat(aChat)
s.Require().NoError(err)

// Bob opens up the public chat and joins it
bChat := CreatePublicChat("status", s.alice.transport)
err = s.bob.SaveChat(bChat)
s.Require().NoError(err)
if ac {
_, err = s.alice.AddContact(context.Background(), s.generateKeyUID(&s.bob.identity.PublicKey))
s.NoError(err)
}
if bc {
_, err = s.bob.AddContact(context.Background(), s.generateKeyUID(&s.alice.identity.PublicKey))
s.NoError(err)
}

_, err = s.bob.Join(bChat)
s.Require().NoError(err)
// Create chats
var aChat *Chat
switch cc{
case publicChat:
// Alice opens creates a public chat
aChat = CreatePublicChat("status", s.alice.transport)
err = s.alice.SaveChat(aChat)
s.NoError(err)

// Bob opens up the public chat and joins it
bChat := CreatePublicChat("status", s.alice.transport)
err = s.bob.SaveChat(bChat)
s.NoError(err)

_, err = s.bob.Join(bChat)
s.NoError(err)
case privateChat:
aChat = CreateOneToOneChat(s.generateKeyUID(&s.aliceKey.PublicKey), &s.aliceKey.PublicKey, s.alice.transport)
err = s.alice.SaveChat(aChat)
s.NoError(err)

_, err = s.alice.Join(aChat)
s.NoError(err)

bChat := CreateOneToOneChat(s.generateKeyUID(&s.bobKey.PublicKey), &s.bobKey.PublicKey, s.bob.transport)
err = s.bob.SaveChat(bChat)
s.NoError(err)

_, err = s.bob.Join(bChat)
s.NoError(err)

err = s.alice.publishContactCode()
s.NoError(err)
default:
s.Failf("unexpected chat context type", "%s", string(cc))
}

// Alice sends a message to the public chat
message := buildTestMessage(*aChat)
response, err := s.alice.SendChatMessage(context.Background(), message)
s.NoError(err)
s.NotNil(response)
// Alice sends a message to the public chat
message := buildTestMessage(*aChat)
response, err := s.alice.SendChatMessage(context.Background(), message)
s.NoError(err)
s.NotNil(response)

// Poll bob to see if he got the chatIdentity
// Retrieve ChatIdentity
var contacts []*Contact
// Poll bob to see if he got the chatIdentity
// Retrieve ChatIdentity
var contacts []*Contact

options := func(b *backoff.ExponentialBackOff) {
b.MaxElapsedTime = 2 * time.Second
}
err = tt.RetryWithBackOff(func() error {

response, err = s.bob.RetrieveAll()
if err != nil {
return err
options := func(b *backoff.ExponentialBackOff) {
b.MaxElapsedTime = 2 * time.Second
}
err = tt.RetryWithBackOff(func() error {

response, err = s.bob.RetrieveAll()
if err != nil {
return err
}

contacts = response.Contacts

if len(contacts) > 0 && len(contacts[0].Images) > 0 {
s.logger.Debug("", zap.Any("contacts", contacts))
return nil
}

return errors.New("no new contacts with images received")
}, options)
if expectPicture {
s.NoError(err)
s.NotNil(contacts)
} else {
s.EqualError(err, "no new contacts with images received")
continue
}

contacts = response.Contacts

if len(contacts) > 0 && len(contacts[0].Images) > 0 {
s.logger.Debug("", zap.Any("contacts", contacts))
return nil
// Check if alice's contact data with profile picture is there
var contact *Contact
for _, c := range contacts {
if c.ID == s.generateKeyUID(&s.alice.identity.PublicKey) {
contact = c
}
}
s.NotNil(contact)

return errors.New("no new contacts with images received")
}, options)
if expectPicture {
s.NoError(err)
s.NotNil(contacts)
} else {
s.EqualError(err, "no new contacts with images received")
continue
}
// Check Alice's profile picture(s)
if cc == publicChat {
s.Len(contact.Images, 1)

// Check if alice's profile picture is there
var contact *Contact
for _, c := range contacts {
if c.ID == s.generateKeyUID(&s.alice.identity.PublicKey) {
contact = c
}
}
s.NotNil(contact)
s.Len(contact.Images, 1)
// Check if the result matches expectation
for _, ii := range iis {
if ii.Name == images.SmallDimName {
s.Equal(ii.Payload, contact.Images[images.SmallDimName].Payload)
}
}
} else {

// Check if the result matches expectation
for _, ii := range iis {
if ii.Name == images.SmallDimName {
s.Equal(ii.Payload, contact.Images[images.SmallDimName].Payload)
}
}

s.TearDownTest()
s.TearDownTest()
}
}
}
}
Expand Down

0 comments on commit 09fbc16

Please sign in to comment.