Fix flaky test

This commit is contained in:
Andrea Maria Piana 2021-10-06 11:08:35 +01:00
parent be0b94d051
commit c4aee37007
1 changed files with 21 additions and 12 deletions

View File

@ -331,9 +331,12 @@ func (s *MessengerCommunitiesSuite) TestJoinCommunity() {
if err != nil { if err != nil {
return err return err
} }
if len(response.Communities()) == 0 { if len(response.Communities()) != 1 {
return errors.New("community not received") return errors.New("community not received")
} }
if len(response.Communities()[0].Chats()) != 2 {
return errors.New("chats not created")
}
return nil return nil
}) })
@ -342,18 +345,24 @@ func (s *MessengerCommunitiesSuite) TestJoinCommunity() {
s.Require().NoError(err) s.Require().NoError(err)
s.Require().Len(communities, 2) s.Require().Len(communities, 2)
s.Require().Len(response.Communities(), 1) s.Require().Len(response.Communities(), 1)
s.Require().Len(response.Chats(), 1) s.Require().Len(response.Chats(), 2)
// The chat should be created // The chat should be created, we pick only the last chat
createdChat = response.Chats()[0] createdChats := response.Chats()
s.Require().Equal(community.IDString(), createdChat.CommunityID) var actualChat *Chat
s.Require().Equal(orgChat.Identity.DisplayName, createdChat.Name) if createdChats[0].Name == orgChat.Identity.DisplayName {
s.Require().Equal(orgChat.Identity.Emoji, createdChat.Emoji) actualChat = createdChats[0]
s.Require().NotEmpty(createdChat.ID) } else if createdChats[1].Name == orgChat.Identity.DisplayName {
s.Require().Equal(ChatTypeCommunityChat, createdChat.ChatType) actualChat = createdChats[1]
s.Require().True(createdChat.Active) }
s.Require().NotEmpty(createdChat.Timestamp) s.Require().Equal(community.IDString(), actualChat.CommunityID)
s.Require().True(strings.HasPrefix(createdChat.ID, community.IDString())) s.Require().Equal(orgChat.Identity.DisplayName, actualChat.Name)
s.Require().Equal(orgChat.Identity.Emoji, actualChat.Emoji)
s.Require().NotEmpty(actualChat.ID)
s.Require().Equal(ChatTypeCommunityChat, actualChat.ChatType)
s.Require().True(actualChat.Active)
s.Require().NotEmpty(actualChat.Timestamp)
s.Require().True(strings.HasPrefix(actualChat.ID, community.IDString()))
// We leave the org // We leave the org
response, err = s.alice.LeaveCommunity(community.ID()) response, err = s.alice.LeaveCommunity(community.ID())