fix: Extract `PairDevices` func (#3857)
This commit is contained in:
parent
b4b0d26aa4
commit
2dd7968c8a
|
@ -2114,7 +2114,7 @@ func (s *MessengerCommunitiesSuite) TestSyncCommunitySettings() {
|
||||||
})
|
})
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
s.pairTwoDevices(alicesOtherDevice, s.alice, "their-name", "their-device-type")
|
PairDevices(&s.Suite, alicesOtherDevice, s.alice)
|
||||||
|
|
||||||
// Create a community
|
// Create a community
|
||||||
createCommunityReq := &requests.CreateCommunity{
|
createCommunityReq := &requests.CreateCommunity{
|
||||||
|
@ -2174,7 +2174,7 @@ func (s *MessengerCommunitiesSuite) TestSyncCommunitySettings_EditCommunity() {
|
||||||
})
|
})
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
s.pairTwoDevices(alicesOtherDevice, s.alice, "their-name", "their-device-type")
|
PairDevices(&s.Suite, alicesOtherDevice, s.alice)
|
||||||
|
|
||||||
// Create a community
|
// Create a community
|
||||||
createCommunityReq := &requests.CreateCommunity{
|
createCommunityReq := &requests.CreateCommunity{
|
||||||
|
@ -2274,7 +2274,7 @@ func (s *MessengerCommunitiesSuite) TestSyncCommunity() {
|
||||||
})
|
})
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
s.pairTwoDevices(alicesOtherDevice, s.alice, "their-name", "their-device-type")
|
PairDevices(&s.Suite, alicesOtherDevice, s.alice)
|
||||||
|
|
||||||
// Create a community
|
// Create a community
|
||||||
createCommunityReq := &requests.CreateCommunity{
|
createCommunityReq := &requests.CreateCommunity{
|
||||||
|
@ -2372,8 +2372,8 @@ func (s *MessengerCommunitiesSuite) TestSyncCommunity_RequestToJoin() {
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
// Pair alice's two devices
|
// Pair alice's two devices
|
||||||
s.pairTwoDevices(alicesOtherDevice, s.alice, im1.Name, im1.DeviceType)
|
PairDevices(&s.Suite, alicesOtherDevice, s.alice)
|
||||||
s.pairTwoDevices(s.alice, alicesOtherDevice, aim.Name, aim.DeviceType)
|
PairDevices(&s.Suite, s.alice, alicesOtherDevice)
|
||||||
|
|
||||||
// Check bob the admin has only one community
|
// Check bob the admin has only one community
|
||||||
tcs2, err := s.bob.communitiesManager.All()
|
tcs2, err := s.bob.communitiesManager.All()
|
||||||
|
@ -2564,36 +2564,6 @@ func (s *MessengerCommunitiesSuite) TestSyncCommunity_RequestToJoin() {
|
||||||
s.Equal(aRtj.State, bobRtj.State)
|
s.Equal(aRtj.State, bobRtj.State)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *MessengerCommunitiesSuite) pairTwoDevices(device1, device2 *Messenger, deviceName, deviceType string) {
|
|
||||||
// Send pairing data
|
|
||||||
response, err := device1.SendPairInstallation(context.Background(), nil)
|
|
||||||
s.Require().NoError(err)
|
|
||||||
s.Require().NotNil(response)
|
|
||||||
s.Len(response.Chats(), 1)
|
|
||||||
s.False(response.Chats()[0].Active)
|
|
||||||
|
|
||||||
// Wait for the message to reach its destination
|
|
||||||
response, err = WaitOnMessengerResponse(
|
|
||||||
device2,
|
|
||||||
func(r *MessengerResponse) bool {
|
|
||||||
for _, installation := range r.Installations {
|
|
||||||
if installation.ID == device1.installationID {
|
|
||||||
return installation.InstallationMetadata != nil && deviceName == installation.InstallationMetadata.Name && deviceType == installation.InstallationMetadata.DeviceType
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
|
|
||||||
},
|
|
||||||
"installation not received",
|
|
||||||
)
|
|
||||||
s.Require().NoError(err)
|
|
||||||
s.Require().NotNil(response)
|
|
||||||
|
|
||||||
// Ensure installation is enabled
|
|
||||||
err = device2.EnableInstallation(device1.installationID)
|
|
||||||
s.Require().NoError(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *MessengerCommunitiesSuite) TestSyncCommunity_Leave() {
|
func (s *MessengerCommunitiesSuite) TestSyncCommunity_Leave() {
|
||||||
// Set Alice's installation metadata
|
// Set Alice's installation metadata
|
||||||
aim := &multidevice.InstallationMetadata{
|
aim := &multidevice.InstallationMetadata{
|
||||||
|
@ -2614,8 +2584,8 @@ func (s *MessengerCommunitiesSuite) TestSyncCommunity_Leave() {
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
// Pair alice's two devices
|
// Pair alice's two devices
|
||||||
s.pairTwoDevices(alicesOtherDevice, s.alice, im1.Name, im1.DeviceType)
|
PairDevices(&s.Suite, alicesOtherDevice, s.alice)
|
||||||
s.pairTwoDevices(s.alice, alicesOtherDevice, aim.Name, aim.DeviceType)
|
PairDevices(&s.Suite, s.alice, alicesOtherDevice)
|
||||||
|
|
||||||
// Check bob the admin has only one community
|
// Check bob the admin has only one community
|
||||||
tcs2, err := s.bob.communitiesManager.All()
|
tcs2, err := s.bob.communitiesManager.All()
|
||||||
|
|
|
@ -729,8 +729,8 @@ func (s *MessengerContactRequestSuite) TestPairedDevicesRemoveContact() {
|
||||||
|
|
||||||
prepAliceMessengersForPairing(&s.Suite, alice1, alice2)
|
prepAliceMessengersForPairing(&s.Suite, alice1, alice2)
|
||||||
|
|
||||||
pairTwoDevices(&s.Suite, alice1, alice2)
|
PairDevices(&s.Suite, alice1, alice2)
|
||||||
pairTwoDevices(&s.Suite, alice2, alice1)
|
PairDevices(&s.Suite, alice2, alice1)
|
||||||
|
|
||||||
bob := s.newMessenger()
|
bob := s.newMessenger()
|
||||||
_, err = bob.Start()
|
_, err = bob.Start()
|
||||||
|
@ -1532,8 +1532,8 @@ func (s *MessengerContactRequestSuite) TestBlockedContactSyncing() {
|
||||||
// NOTE: This doesn't include initial data sync. Local pairing could be used.
|
// NOTE: This doesn't include initial data sync. Local pairing could be used.
|
||||||
s.logger.Info("pairing Alice-1 and Alice-2")
|
s.logger.Info("pairing Alice-1 and Alice-2")
|
||||||
prepAliceMessengersForPairing(&s.Suite, alice1, alice2)
|
prepAliceMessengersForPairing(&s.Suite, alice1, alice2)
|
||||||
pairTwoDevices(&s.Suite, alice1, alice2)
|
PairDevices(&s.Suite, alice1, alice2)
|
||||||
pairTwoDevices(&s.Suite, alice2, alice1)
|
PairDevices(&s.Suite, alice2, alice1)
|
||||||
s.logger.Info("pairing Alice-1 and Alice-2 finished")
|
s.logger.Info("pairing Alice-1 and Alice-2 finished")
|
||||||
|
|
||||||
// Loop cr-block-unblock. Some bugs happen at second iteration.
|
// Loop cr-block-unblock. Some bugs happen at second iteration.
|
||||||
|
|
|
@ -57,41 +57,6 @@ func (s *MessengerSyncAccountCustomizationColorSuite) TearDownTest() {
|
||||||
_ = s.logger.Sync()
|
_ = s.logger.Sync()
|
||||||
}
|
}
|
||||||
|
|
||||||
func pairDevices(s *suite.Suite, device1, device2 *Messenger) {
|
|
||||||
// Send pairing data
|
|
||||||
response, err := device1.SendPairInstallation(context.Background(), nil)
|
|
||||||
s.Require().NoError(err)
|
|
||||||
s.Require().NotNil(response)
|
|
||||||
s.Len(response.Chats(), 1)
|
|
||||||
s.False(response.Chats()[0].Active)
|
|
||||||
|
|
||||||
i, ok := device1.allInstallations.Load(device1.installationID)
|
|
||||||
s.Require().True(ok)
|
|
||||||
|
|
||||||
// Wait for the message to reach its destination
|
|
||||||
response, err = WaitOnMessengerResponse(
|
|
||||||
device2,
|
|
||||||
func(r *MessengerResponse) bool {
|
|
||||||
for _, installation := range r.Installations {
|
|
||||||
if installation.ID == device1.installationID {
|
|
||||||
return installation.InstallationMetadata != nil &&
|
|
||||||
i.InstallationMetadata.Name == installation.InstallationMetadata.Name &&
|
|
||||||
i.InstallationMetadata.DeviceType == installation.InstallationMetadata.DeviceType
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
|
|
||||||
},
|
|
||||||
"installation not received",
|
|
||||||
)
|
|
||||||
s.Require().NoError(err)
|
|
||||||
s.Require().NotNil(response)
|
|
||||||
|
|
||||||
// Ensure installation is enabled
|
|
||||||
err = device2.EnableInstallation(device1.installationID)
|
|
||||||
s.Require().NoError(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
func prepareAliceMessengersForPairing(s *suite.Suite, alice1, alice2 *Messenger) {
|
func prepareAliceMessengersForPairing(s *suite.Suite, alice1, alice2 *Messenger) {
|
||||||
// Set Alice's installation metadata
|
// Set Alice's installation metadata
|
||||||
aim := &multidevice.InstallationMetadata{
|
aim := &multidevice.InstallationMetadata{
|
||||||
|
@ -111,8 +76,8 @@ func prepareAliceMessengersForPairing(s *suite.Suite, alice1, alice2 *Messenger)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *MessengerSyncAccountCustomizationColorSuite) TestSyncCustomizationColor() {
|
func (s *MessengerSyncAccountCustomizationColorSuite) TestSyncCustomizationColor() {
|
||||||
pairDevices(&s.Suite, s.alice2, s.alice)
|
PairDevices(&s.Suite, s.alice2, s.alice)
|
||||||
pairDevices(&s.Suite, s.alice, s.alice2)
|
PairDevices(&s.Suite, s.alice, s.alice2)
|
||||||
|
|
||||||
s.Require().Equal(s.alice.account.KeyUID, s.alice2.account.KeyUID)
|
s.Require().Equal(s.alice.account.KeyUID, s.alice2.account.KeyUID)
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package protocol
|
package protocol
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"crypto/ecdsa"
|
"crypto/ecdsa"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
|
@ -181,41 +180,6 @@ func (s *MessengerSyncSettingsSuite) newMessenger() *Messenger {
|
||||||
return s.newMessengerWithKey(s.shh, privateKey)
|
return s.newMessengerWithKey(s.shh, privateKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
func pairTwoDevices(s *suite.Suite, device1, device2 *Messenger) {
|
|
||||||
// Send pairing data
|
|
||||||
response, err := device1.SendPairInstallation(context.Background(), nil)
|
|
||||||
s.Require().NoError(err)
|
|
||||||
s.Require().NotNil(response)
|
|
||||||
s.Len(response.Chats(), 1)
|
|
||||||
s.False(response.Chats()[0].Active)
|
|
||||||
|
|
||||||
i, ok := device1.allInstallations.Load(device1.installationID)
|
|
||||||
s.Require().True(ok)
|
|
||||||
|
|
||||||
// Wait for the message to reach its destination
|
|
||||||
response, err = WaitOnMessengerResponse(
|
|
||||||
device2,
|
|
||||||
func(r *MessengerResponse) bool {
|
|
||||||
for _, installation := range r.Installations {
|
|
||||||
if installation.ID == device1.installationID {
|
|
||||||
return installation.InstallationMetadata != nil &&
|
|
||||||
i.InstallationMetadata.Name == installation.InstallationMetadata.Name &&
|
|
||||||
i.InstallationMetadata.DeviceType == installation.InstallationMetadata.DeviceType
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
|
|
||||||
},
|
|
||||||
"installation not received",
|
|
||||||
)
|
|
||||||
s.Require().NoError(err)
|
|
||||||
s.Require().NotNil(response)
|
|
||||||
|
|
||||||
// Ensure installation is enabled
|
|
||||||
err = device2.EnableInstallation(device1.installationID)
|
|
||||||
s.Require().NoError(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
func prepAliceMessengersForPairing(s *suite.Suite, alice1, alice2 *Messenger) {
|
func prepAliceMessengersForPairing(s *suite.Suite, alice1, alice2 *Messenger) {
|
||||||
// Set Alice's installation metadata
|
// Set Alice's installation metadata
|
||||||
aim := &multidevice.InstallationMetadata{
|
aim := &multidevice.InstallationMetadata{
|
||||||
|
@ -236,8 +200,8 @@ func prepAliceMessengersForPairing(s *suite.Suite, alice1, alice2 *Messenger) {
|
||||||
|
|
||||||
func (s *MessengerSyncSettingsSuite) TestSyncSettings() {
|
func (s *MessengerSyncSettingsSuite) TestSyncSettings() {
|
||||||
// Pair alice's two devices
|
// Pair alice's two devices
|
||||||
pairTwoDevices(&s.Suite, s.alice2, s.alice)
|
PairDevices(&s.Suite, s.alice2, s.alice)
|
||||||
pairTwoDevices(&s.Suite, s.alice, s.alice2)
|
PairDevices(&s.Suite, s.alice, s.alice2)
|
||||||
|
|
||||||
// Check alice 1 settings values
|
// Check alice 1 settings values
|
||||||
as, err := s.alice.settings.GetSettings()
|
as, err := s.alice.settings.GetSettings()
|
||||||
|
@ -321,7 +285,7 @@ func (s *MessengerSyncSettingsSuite) TestSyncSettings_StickerPacks() {
|
||||||
s.Require().Nil(aos.StickersRecentStickers)
|
s.Require().Nil(aos.StickersRecentStickers)
|
||||||
|
|
||||||
// Pair devices. Allows alice to send to alicesOtherDevice
|
// Pair devices. Allows alice to send to alicesOtherDevice
|
||||||
pairTwoDevices(&s.Suite, s.alice2, s.alice)
|
PairDevices(&s.Suite, s.alice2, s.alice)
|
||||||
|
|
||||||
// Add sticker pack to alice device
|
// Add sticker pack to alice device
|
||||||
stickerPacks := make(stickers.StickerPackCollection)
|
stickerPacks := make(stickers.StickerPackCollection)
|
||||||
|
@ -376,7 +340,7 @@ func (s *MessengerSyncSettingsSuite) TestSyncSettings_PreferredName() {
|
||||||
s.Require().Nil(aos.PreferredName)
|
s.Require().Nil(aos.PreferredName)
|
||||||
|
|
||||||
// Pair devices. Allows alice to send to alicesOtherDevice
|
// Pair devices. Allows alice to send to alicesOtherDevice
|
||||||
pairTwoDevices(&s.Suite, s.alice2, s.alice)
|
PairDevices(&s.Suite, s.alice2, s.alice)
|
||||||
|
|
||||||
// Update Alice's PreferredName
|
// Update Alice's PreferredName
|
||||||
err = s.alice.settings.SaveSettingField(settings.PreferredName, pf2)
|
err = s.alice.settings.SaveSettingField(settings.PreferredName, pf2)
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
package protocol
|
package protocol
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/suite"
|
||||||
|
|
||||||
"github.com/status-im/status-go/protocol/common"
|
"github.com/status-im/status-go/protocol/common"
|
||||||
"github.com/status-im/status-go/protocol/protobuf"
|
"github.com/status-im/status-go/protocol/protobuf"
|
||||||
"github.com/status-im/status-go/protocol/tt"
|
"github.com/status-im/status-go/protocol/tt"
|
||||||
|
@ -34,3 +37,38 @@ func FindFirstByContentType(messages []*common.Message, contentType protobuf.Cha
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func PairDevices(s *suite.Suite, device1, device2 *Messenger) {
|
||||||
|
// Send pairing data
|
||||||
|
response, err := device1.SendPairInstallation(context.Background(), nil)
|
||||||
|
s.Require().NoError(err)
|
||||||
|
s.Require().NotNil(response)
|
||||||
|
s.Len(response.Chats(), 1)
|
||||||
|
s.False(response.Chats()[0].Active)
|
||||||
|
|
||||||
|
i, ok := device1.allInstallations.Load(device1.installationID)
|
||||||
|
s.Require().True(ok)
|
||||||
|
|
||||||
|
// Wait for the message to reach its destination
|
||||||
|
response, err = WaitOnMessengerResponse(
|
||||||
|
device2,
|
||||||
|
func(r *MessengerResponse) bool {
|
||||||
|
for _, installation := range r.Installations {
|
||||||
|
if installation.ID == device1.installationID {
|
||||||
|
return installation.InstallationMetadata != nil &&
|
||||||
|
i.InstallationMetadata.Name == installation.InstallationMetadata.Name &&
|
||||||
|
i.InstallationMetadata.DeviceType == installation.InstallationMetadata.DeviceType
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
|
||||||
|
},
|
||||||
|
"installation not received",
|
||||||
|
)
|
||||||
|
s.Require().NoError(err)
|
||||||
|
s.Require().NotNil(response)
|
||||||
|
|
||||||
|
// Ensure installation is enabled
|
||||||
|
err = device2.EnableInstallation(device1.installationID)
|
||||||
|
s.Require().NoError(err)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue