2023-07-04 13:48:52 +00:00
|
|
|
package protocol
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/suite"
|
|
|
|
|
2023-11-10 16:33:37 +00:00
|
|
|
"github.com/status-im/status-go/api/multiformat"
|
2023-07-04 13:48:52 +00:00
|
|
|
"github.com/status-im/status-go/eth-node/crypto"
|
|
|
|
"github.com/status-im/status-go/eth-node/types"
|
|
|
|
"github.com/status-im/status-go/protocol/communities"
|
|
|
|
"github.com/status-im/status-go/protocol/protobuf"
|
|
|
|
"github.com/status-im/status-go/protocol/requests"
|
|
|
|
"github.com/status-im/status-go/protocol/urls"
|
|
|
|
)
|
|
|
|
|
2023-11-10 15:00:03 +00:00
|
|
|
const (
|
|
|
|
userURL = "https://status.app/u#zQ3shwQPhRuDJSjVGVBnTjCdgXy5i9WQaeVPdGJD6yTarJQSj"
|
|
|
|
userURLWithData = "https://status.app/u/G10A4B0JdgwyRww90WXtnP1oNH1ZLQNM0yX0Ja9YyAMjrqSZIYINOHCbFhrnKRAcPGStPxCMJDSZlGCKzmZrJcimHY8BbcXlORrElv_BbQEegnMDPx1g9C5VVNl0fE4y#zQ3shwQPhRuDJSjVGVBnTjCdgXy5i9WQaeVPdGJD6yTarJQSj"
|
|
|
|
communityURL = "https://status.app/c#zQ3shYSHp7GoiXaauJMnDcjwU2yNjdzpXLosAWapPS4CFxc11"
|
|
|
|
communityURLWithData = "https://status.app/c/iyKACkQKB0Rvb2RsZXMSJ0NvbG9yaW5nIHRoZSB3b3JsZCB3aXRoIGpveSDigKIg4bSXIOKAohiYohsiByMxMzFEMkYqAwEhMwM=#zQ3shYSHp7GoiXaauJMnDcjwU2yNjdzpXLosAWapPS4CFxc11"
|
|
|
|
channelURL = "https://status.app/cc/003cdcd5-e065-48f9-b166-b1a94ac75a11#zQ3shYSHp7GoiXaauJMnDcjwU2yNjdzpXLosAWapPS4CFxc11"
|
|
|
|
channelURLWithData = "https://status.app/cc/G54AAKwObLdpiGjXnckYzRcOSq0QQAS_CURGfqVU42ceGHCObstUIknTTZDOKF3E8y2MSicncpO7fTskXnoACiPKeejvjtLTGWNxUhlT7fyQS7Jrr33UVHluxv_PLjV2ePGw5GQ33innzeK34pInIgUGs5RjdQifMVmURalxxQKwiuoY5zwIjixWWRHqjHM=#zQ3shYSHp7GoiXaauJMnDcjwU2yNjdzpXLosAWapPS4CFxc11"
|
|
|
|
)
|
|
|
|
|
2023-07-04 13:48:52 +00:00
|
|
|
func TestMessengerShareUrlsSuite(t *testing.T) {
|
|
|
|
suite.Run(t, new(MessengerShareUrlsSuite))
|
|
|
|
}
|
|
|
|
|
|
|
|
type MessengerShareUrlsSuite struct {
|
2023-07-13 10:28:34 +00:00
|
|
|
MessengerBaseTestSuite
|
2023-07-04 13:48:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *MessengerShareUrlsSuite) createCommunity() *communities.Community {
|
|
|
|
description := &requests.CreateCommunity{
|
2023-10-25 13:03:26 +00:00
|
|
|
Membership: protobuf.CommunityPermissions_AUTO_ACCEPT,
|
2023-07-04 13:48:52 +00:00
|
|
|
Name: "status",
|
|
|
|
Color: "#ffffff",
|
|
|
|
Description: "status community description",
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create an community chat
|
|
|
|
response, err := s.m.CreateCommunity(description, false)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().NotNil(response)
|
|
|
|
return response.Communities()[0]
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *MessengerShareUrlsSuite) createContact() (*Messenger, *Contact) {
|
|
|
|
theirMessenger := s.newMessenger()
|
|
|
|
_, err := theirMessenger.Start()
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
contactID := types.EncodeHex(crypto.FromECDSAPub(&theirMessenger.identity.PublicKey))
|
|
|
|
ensName := "blah.stateofus.eth"
|
|
|
|
|
|
|
|
s.Require().NoError(s.m.ENSVerified(contactID, ensName))
|
|
|
|
|
|
|
|
response, err := s.m.AddContact(context.Background(), &requests.AddContact{ID: contactID})
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().NotNil(response)
|
|
|
|
s.Require().Len(response.Contacts, 1)
|
|
|
|
|
|
|
|
contact := response.Contacts[0]
|
|
|
|
s.Require().Equal(ensName, contact.EnsName)
|
|
|
|
s.Require().True(contact.ENSVerified)
|
|
|
|
|
|
|
|
return theirMessenger, contact
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *MessengerShareUrlsSuite) createCommunityWithChannel() (*communities.Community, *protobuf.CommunityChat, string) {
|
|
|
|
community := s.createCommunity()
|
|
|
|
|
|
|
|
chat := &protobuf.CommunityChat{
|
|
|
|
Permissions: &protobuf.CommunityPermissions{
|
2023-10-25 13:03:26 +00:00
|
|
|
Access: protobuf.CommunityPermissions_AUTO_ACCEPT,
|
2023-07-04 13:48:52 +00:00
|
|
|
},
|
|
|
|
Identity: &protobuf.ChatIdentity{
|
|
|
|
DisplayName: "status-core",
|
|
|
|
Emoji: "😎",
|
|
|
|
Description: "status-core community chat",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
response, err := s.m.CreateCommunityChat(community.ID(), chat)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().NotNil(response)
|
|
|
|
s.Require().Len(response.Communities(), 1)
|
|
|
|
s.Require().Len(response.Chats(), 1)
|
|
|
|
|
|
|
|
community = response.Communities()[0]
|
|
|
|
s.Require().Len(community.Chats(), 1)
|
|
|
|
|
|
|
|
var channelID string
|
|
|
|
var channel *protobuf.CommunityChat
|
|
|
|
|
|
|
|
for key, value := range community.Chats() {
|
|
|
|
channelID = key
|
|
|
|
channel = value
|
|
|
|
break
|
|
|
|
}
|
|
|
|
s.Require().NotNil(channel)
|
|
|
|
return community, channel, channelID
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *MessengerShareUrlsSuite) TestDecodeEncodeDataURL() {
|
|
|
|
ts := [][]byte{
|
|
|
|
[]byte("test data 123"),
|
|
|
|
[]byte("test data 123test data 123test data 123test data 123test data 123"),
|
|
|
|
}
|
|
|
|
|
|
|
|
for i := range ts {
|
|
|
|
encodedData, err := urls.EncodeDataURL(ts[i])
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
decodedData, err := urls.DecodeDataURL(encodedData)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Equal(ts[i], decodedData)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *MessengerShareUrlsSuite) TestParseWrongUrls() {
|
2023-11-10 15:00:03 +00:00
|
|
|
const notStatusSharedURLError = "not a status shared url"
|
|
|
|
badURLs := map[string]string{
|
|
|
|
"https://status.appc/#zQ3shYSHp7GoiXaauJMnDcjwU2yNjdzpXLosAWapPS4CFxc11": notStatusSharedURLError,
|
|
|
|
"https://status.app/cc#zQ3shYSHp7GoiXaauJMnDcjwU2yNjdzpXLosAWapPS4CFxc11": notStatusSharedURLError,
|
|
|
|
"https://status.app/a#zQ3shYSHp7GoiXaauJMnDcjwU2yNjdzpXLosAWapPS4CFxc11": notStatusSharedURLError,
|
|
|
|
"https://status.im/u#zQ3shYSHp7GoiXaauJMnDcjwU2yNjdzpXLosAWapPS4CFxc11": notStatusSharedURLError,
|
2023-07-04 13:48:52 +00:00
|
|
|
"https://status.app/u/": "url should contain at least one `#` separator",
|
|
|
|
}
|
|
|
|
|
2023-11-10 15:00:03 +00:00
|
|
|
for url, expectedError := range badURLs {
|
2023-11-10 16:33:37 +00:00
|
|
|
urlData, err := ParseSharedURL(url)
|
2023-07-04 13:48:52 +00:00
|
|
|
s.Require().Error(err)
|
2023-11-10 15:00:03 +00:00
|
|
|
s.Require().Equal(err.Error(), expectedError)
|
2023-07-04 13:48:52 +00:00
|
|
|
s.Require().Nil(urlData)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-10 15:00:03 +00:00
|
|
|
func (s *MessengerShareUrlsSuite) TestIsStatusSharedUrl() {
|
|
|
|
testCases := []struct {
|
|
|
|
Name string
|
|
|
|
URL string
|
|
|
|
Result bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
Name: "Direct website link",
|
|
|
|
URL: "https://status.app",
|
|
|
|
Result: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "Website page link",
|
|
|
|
URL: "https://status.app/features/messenger",
|
|
|
|
Result: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
// starts with `/c`, but no `#` after
|
|
|
|
Name: "Website page link",
|
|
|
|
URL: "https://status.app/communities",
|
|
|
|
Result: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "User link",
|
|
|
|
URL: userURL,
|
|
|
|
Result: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "User link with data",
|
|
|
|
URL: userURLWithData,
|
|
|
|
Result: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "Community link",
|
|
|
|
URL: communityURL,
|
|
|
|
Result: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "Community link with data",
|
|
|
|
URL: communityURLWithData,
|
|
|
|
Result: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "Channel link",
|
|
|
|
URL: channelURL,
|
|
|
|
Result: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "Channel link with data",
|
|
|
|
URL: channelURLWithData,
|
|
|
|
Result: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range testCases {
|
|
|
|
s.Run(tc.Name, func() {
|
|
|
|
result := IsStatusSharedURL(tc.URL)
|
|
|
|
s.Require().Equal(tc.Result, result)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-04 13:48:52 +00:00
|
|
|
func (s *MessengerShareUrlsSuite) TestShareCommunityURLWithChatKey() {
|
|
|
|
community := s.createCommunity()
|
|
|
|
|
|
|
|
url, err := s.m.ShareCommunityURLWithChatKey(community.ID())
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
2023-11-10 16:33:37 +00:00
|
|
|
shortID, err := community.SerializedID()
|
2023-07-04 13:48:52 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
|
2023-11-10 16:33:37 +00:00
|
|
|
expectedURL := fmt.Sprintf("%s/c#%s", baseShareURL, shortID)
|
2023-07-04 13:48:52 +00:00
|
|
|
s.Require().Equal(expectedURL, url)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *MessengerShareUrlsSuite) TestParseCommunityURLWithChatKey() {
|
|
|
|
community := s.createCommunity()
|
|
|
|
|
2023-11-10 16:33:37 +00:00
|
|
|
shortID, err := community.SerializedID()
|
2023-07-04 13:48:52 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
|
2023-11-10 16:33:37 +00:00
|
|
|
url := fmt.Sprintf("%s/c#%s", baseShareURL, shortID)
|
2023-07-04 13:48:52 +00:00
|
|
|
|
2023-11-10 16:33:37 +00:00
|
|
|
urlData, err := ParseSharedURL(url)
|
2023-07-04 13:48:52 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().NotNil(urlData)
|
|
|
|
|
|
|
|
s.Require().NotNil(urlData.Community)
|
2023-11-10 16:33:37 +00:00
|
|
|
s.Require().Equal(community.IDString(), urlData.Community.CommunityID)
|
|
|
|
s.Require().Equal("", urlData.Community.DisplayName)
|
|
|
|
s.Require().Equal("", urlData.Community.Description)
|
|
|
|
s.Require().Equal(uint32(0), urlData.Community.MembersCount)
|
|
|
|
s.Require().Equal("", urlData.Community.Color)
|
|
|
|
s.Require().Equal([]uint32{}, urlData.Community.TagIndices)
|
2023-07-04 13:48:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *MessengerShareUrlsSuite) TestShareCommunityURLWithData() {
|
|
|
|
community := s.createCommunity()
|
|
|
|
|
|
|
|
url, err := s.m.ShareCommunityURLWithData(community.ID())
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
2023-07-26 12:14:06 +00:00
|
|
|
communityData, chatKey, err := s.m.prepareEncodedCommunityData(community)
|
2023-07-04 13:48:52 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
|
2023-07-26 12:14:06 +00:00
|
|
|
expectedURL := fmt.Sprintf("%s/c/%s#%s", baseShareURL, communityData, chatKey)
|
2023-07-04 13:48:52 +00:00
|
|
|
s.Require().Equal(expectedURL, url)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *MessengerShareUrlsSuite) TestParseCommunityURLWithData() {
|
2023-11-10 16:33:37 +00:00
|
|
|
urlData, err := ParseSharedURL(communityURLWithData)
|
2023-07-04 13:48:52 +00:00
|
|
|
s.Require().NoError(err)
|
2023-08-14 10:25:42 +00:00
|
|
|
s.Require().NotNil(urlData)
|
|
|
|
|
|
|
|
s.Require().NotNil(urlData.Community)
|
2023-10-13 12:25:34 +00:00
|
|
|
s.Require().Equal("0x02a3d2fdb9ac335917bf9d46b38d7496c00bbfadbaf832e8aa61d13ac2b4452084", urlData.Community.CommunityID)
|
2023-08-14 10:25:42 +00:00
|
|
|
s.Require().Equal("Doodles", urlData.Community.DisplayName)
|
|
|
|
s.Require().Equal("Coloring the world with joy • ᴗ •", urlData.Community.Description)
|
|
|
|
s.Require().Equal(uint32(446744), urlData.Community.MembersCount)
|
|
|
|
s.Require().Equal("#131D2F", urlData.Community.Color)
|
|
|
|
s.Require().Equal([]uint32{1, 33, 51}, urlData.Community.TagIndices)
|
|
|
|
}
|
2023-07-04 13:48:52 +00:00
|
|
|
|
2023-08-14 10:25:42 +00:00
|
|
|
func (s *MessengerShareUrlsSuite) TestShareAndParseCommunityURLWithData() {
|
|
|
|
community := s.createCommunity()
|
|
|
|
|
|
|
|
url, err := s.m.ShareCommunityURLWithData(community.ID())
|
|
|
|
s.Require().NoError(err)
|
2023-07-04 13:48:52 +00:00
|
|
|
|
2023-11-10 16:33:37 +00:00
|
|
|
urlData, err := ParseSharedURL(url)
|
2023-07-04 13:48:52 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
s.Require().Equal(community.Identity().DisplayName, urlData.Community.DisplayName)
|
|
|
|
s.Require().Equal(community.DescriptionText(), urlData.Community.Description)
|
|
|
|
s.Require().Equal(uint32(community.MembersCount()), urlData.Community.MembersCount)
|
|
|
|
s.Require().Equal(community.Identity().GetColor(), urlData.Community.Color)
|
|
|
|
s.Require().Equal(community.TagsIndices(), urlData.Community.TagIndices)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *MessengerShareUrlsSuite) TestShareCommunityChannelURLWithChatKey() {
|
|
|
|
community := s.createCommunity()
|
|
|
|
channelID := "003cdcd5-e065-48f9-b166-b1a94ac75a11"
|
|
|
|
|
|
|
|
request := &requests.CommunityChannelShareURL{
|
|
|
|
CommunityID: community.ID(),
|
|
|
|
ChannelID: channelID,
|
|
|
|
}
|
|
|
|
url, err := s.m.ShareCommunityChannelURLWithChatKey(request)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
2023-11-10 16:33:37 +00:00
|
|
|
shortID, err := community.SerializedID()
|
2023-07-04 13:48:52 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
|
2023-11-10 16:33:37 +00:00
|
|
|
expectedURL := fmt.Sprintf("%s/cc/%s#%s", baseShareURL, channelID, shortID)
|
2023-07-04 13:48:52 +00:00
|
|
|
s.Require().Equal(expectedURL, url)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *MessengerShareUrlsSuite) TestParseCommunityChannelURLWithChatKey() {
|
2023-11-10 16:33:37 +00:00
|
|
|
const channelUUID = "003cdcd5-e065-48f9-b166-b1a94ac75a11"
|
|
|
|
const communityID = "0x02a3d2fdb9ac335917bf9d46b38d7496c00bbfadbaf832e8aa61d13ac2b4452084"
|
2023-07-04 13:48:52 +00:00
|
|
|
|
2023-11-10 16:33:37 +00:00
|
|
|
urlData, err := ParseSharedURL(channelURL)
|
2023-07-04 13:48:52 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().NotNil(urlData)
|
|
|
|
|
|
|
|
s.Require().NotNil(urlData.Community)
|
2023-11-10 16:33:37 +00:00
|
|
|
s.Require().Equal(communityID, urlData.Community.CommunityID)
|
|
|
|
s.Require().Equal("", urlData.Community.DisplayName)
|
|
|
|
s.Require().Equal("", urlData.Community.Description)
|
|
|
|
s.Require().Equal(uint32(0), urlData.Community.MembersCount)
|
|
|
|
s.Require().Equal("", urlData.Community.Color)
|
|
|
|
s.Require().Equal([]uint32{}, urlData.Community.TagIndices)
|
2023-07-04 13:48:52 +00:00
|
|
|
|
|
|
|
s.Require().NotNil(urlData.Channel)
|
2023-11-10 16:33:37 +00:00
|
|
|
s.Require().Equal(channelUUID, urlData.Channel.ChannelUUID)
|
|
|
|
s.Require().Equal("", urlData.Channel.Emoji)
|
|
|
|
s.Require().Equal("", urlData.Channel.DisplayName)
|
|
|
|
s.Require().Equal("", urlData.Channel.Color)
|
2023-07-04 13:48:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *MessengerShareUrlsSuite) TestShareCommunityChannelURLWithData() {
|
|
|
|
community, channel, channelID := s.createCommunityWithChannel()
|
|
|
|
|
|
|
|
request := &requests.CommunityChannelShareURL{
|
|
|
|
CommunityID: community.ID(),
|
|
|
|
ChannelID: channelID,
|
|
|
|
}
|
|
|
|
url, err := s.m.ShareCommunityChannelURLWithData(request)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
2023-07-26 12:14:06 +00:00
|
|
|
communityChannelData, chatKey, err := s.m.prepareEncodedCommunityChannelData(community, channel, channelID)
|
2023-07-04 13:48:52 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
|
2023-07-26 12:14:06 +00:00
|
|
|
expectedURL := fmt.Sprintf("%s/cc/%s#%s", baseShareURL, communityChannelData, chatKey)
|
2023-07-04 13:48:52 +00:00
|
|
|
s.Require().Equal(expectedURL, url)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *MessengerShareUrlsSuite) TestParseCommunityChannelURLWithData() {
|
2023-11-10 16:33:37 +00:00
|
|
|
urlData, err := ParseSharedURL(channelURLWithData)
|
2023-07-04 13:48:52 +00:00
|
|
|
s.Require().NoError(err)
|
2023-08-14 10:25:42 +00:00
|
|
|
s.Require().NotNil(urlData)
|
2023-07-04 13:48:52 +00:00
|
|
|
|
2023-08-14 10:25:42 +00:00
|
|
|
s.Require().NotNil(urlData.Community)
|
|
|
|
s.Require().Equal("Doodles", urlData.Community.DisplayName)
|
|
|
|
|
|
|
|
s.Require().NotNil(urlData.Channel)
|
|
|
|
s.Require().Equal("🍿", urlData.Channel.Emoji)
|
|
|
|
s.Require().Equal("design", urlData.Channel.DisplayName)
|
|
|
|
s.Require().Equal("#131D2F", urlData.Channel.Color)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *MessengerShareUrlsSuite) TestShareAndParseCommunityChannelURLWithData() {
|
|
|
|
community, channel, channelID := s.createCommunityWithChannel()
|
|
|
|
|
|
|
|
request := &requests.CommunityChannelShareURL{
|
|
|
|
CommunityID: community.ID(),
|
|
|
|
ChannelID: channelID,
|
|
|
|
}
|
|
|
|
url, err := s.m.ShareCommunityChannelURLWithData(request)
|
|
|
|
s.Require().NoError(err)
|
2023-07-04 13:48:52 +00:00
|
|
|
|
2023-11-10 16:33:37 +00:00
|
|
|
urlData, err := ParseSharedURL(url)
|
2023-07-04 13:48:52 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
s.Require().Equal(community.Identity().DisplayName, urlData.Community.DisplayName)
|
|
|
|
s.Require().Equal(community.DescriptionText(), urlData.Community.Description)
|
|
|
|
s.Require().Equal(uint32(community.MembersCount()), urlData.Community.MembersCount)
|
|
|
|
s.Require().Equal(community.Identity().GetColor(), urlData.Community.Color)
|
|
|
|
s.Require().Equal(community.TagsIndices(), urlData.Community.TagIndices)
|
|
|
|
|
|
|
|
s.Require().NotNil(urlData.Channel)
|
|
|
|
s.Require().Equal(channel.Identity.Emoji, urlData.Channel.Emoji)
|
|
|
|
s.Require().Equal(channel.Identity.DisplayName, urlData.Channel.DisplayName)
|
|
|
|
s.Require().Equal(channel.Identity.Color, urlData.Channel.Color)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *MessengerShareUrlsSuite) TestShareUserURLWithChatKey() {
|
|
|
|
_, contact := s.createContact()
|
|
|
|
|
|
|
|
url, err := s.m.ShareUserURLWithChatKey(contact.ID)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
2023-11-10 16:33:37 +00:00
|
|
|
shortKey, err := multiformat.SerializeLegacyKey(contact.ID)
|
2023-07-04 13:48:52 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
expectedURL := fmt.Sprintf("%s/u#%s", baseShareURL, shortKey)
|
|
|
|
s.Require().Equal(expectedURL, url)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *MessengerShareUrlsSuite) TestParseUserURLWithChatKey() {
|
2023-11-10 16:33:37 +00:00
|
|
|
urlData, err := ParseSharedURL(userURL)
|
2023-07-04 13:48:52 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().NotNil(urlData)
|
|
|
|
|
|
|
|
s.Require().NotNil(urlData.Contact)
|
2023-11-10 16:33:37 +00:00
|
|
|
s.Require().Equal("", urlData.Contact.DisplayName)
|
|
|
|
s.Require().Equal("", urlData.Contact.Description)
|
2023-07-04 13:48:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *MessengerShareUrlsSuite) TestShareUserURLWithENS() {
|
|
|
|
_, contact := s.createContact()
|
|
|
|
|
|
|
|
url, err := s.m.ShareUserURLWithENS(contact.ID)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
expectedURL := fmt.Sprintf("%s/u#%s", baseShareURL, contact.EnsName)
|
|
|
|
s.Require().Equal(expectedURL, url)
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: ens in the next ticket
|
|
|
|
// func (s *MessengerShareUrlsSuite) TestParseUserURLWithENS() {
|
|
|
|
// _, contact := s.createContact()
|
|
|
|
|
|
|
|
// url := fmt.Sprintf("%s/u#%s", baseShareURL, contact.EnsName)
|
|
|
|
|
2023-11-10 16:33:37 +00:00
|
|
|
// urlData, err := ParseSharedURL(url)
|
2023-07-04 13:48:52 +00:00
|
|
|
// s.Require().NoError(err)
|
|
|
|
// s.Require().NotNil(urlData)
|
|
|
|
|
|
|
|
// s.Require().NotNil(urlData.Contact)
|
|
|
|
// s.Require().Equal(contact.DisplayName, urlData.Contact.DisplayName)
|
|
|
|
// s.Require().Equal(contact.Bio, urlData.Contact.DisplayName)
|
|
|
|
// }
|
|
|
|
|
2023-08-14 10:25:42 +00:00
|
|
|
func (s *MessengerShareUrlsSuite) TestParseUserURLWithData() {
|
2023-11-10 16:33:37 +00:00
|
|
|
urlData, err := ParseSharedURL(userURLWithData)
|
2023-08-14 10:25:42 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().NotNil(urlData)
|
|
|
|
|
|
|
|
s.Require().NotNil(urlData.Contact)
|
|
|
|
s.Require().Equal("Mark Cole", urlData.Contact.DisplayName)
|
|
|
|
s.Require().Equal("Visual designer @Status, cat lover, pizza enthusiast, yoga afficionada", urlData.Contact.Description)
|
|
|
|
s.Require().Equal("zQ3shwQPhRuDJSjVGVBnTjCdgXy5i9WQaeVPdGJD6yTarJQSj", urlData.Contact.PublicKey)
|
|
|
|
}
|
|
|
|
|
2023-07-04 13:48:52 +00:00
|
|
|
func (s *MessengerShareUrlsSuite) TestShareUserURLWithData() {
|
|
|
|
_, contact := s.createContact()
|
|
|
|
|
|
|
|
url, err := s.m.ShareUserURLWithData(contact.ID)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
2023-07-26 12:14:06 +00:00
|
|
|
userData, chatKey, err := s.m.prepareEncodedUserData(contact)
|
2023-07-04 13:48:52 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
|
2023-07-26 12:14:06 +00:00
|
|
|
expectedURL := fmt.Sprintf("%s/u/%s#%s", baseShareURL, userData, chatKey)
|
2023-07-04 13:48:52 +00:00
|
|
|
s.Require().Equal(expectedURL, url)
|
|
|
|
}
|
|
|
|
|
2023-08-14 10:25:42 +00:00
|
|
|
func (s *MessengerShareUrlsSuite) TestShareAndParseUserURLWithData() {
|
2023-07-04 13:48:52 +00:00
|
|
|
_, contact := s.createContact()
|
|
|
|
|
2023-11-10 16:33:37 +00:00
|
|
|
shortKey, err := multiformat.SerializeLegacyKey(contact.ID)
|
2023-07-04 13:48:52 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
|
2023-08-14 10:25:42 +00:00
|
|
|
url, err := s.m.ShareUserURLWithData(contact.ID)
|
|
|
|
s.Require().NoError(err)
|
2023-07-04 13:48:52 +00:00
|
|
|
|
2023-11-10 16:33:37 +00:00
|
|
|
urlData, err := ParseSharedURL(url)
|
2023-07-04 13:48:52 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
s.Require().NotNil(urlData.Contact)
|
|
|
|
s.Require().Equal(contact.DisplayName, urlData.Contact.DisplayName)
|
2023-08-14 10:25:42 +00:00
|
|
|
s.Require().Equal(shortKey, urlData.Contact.PublicKey)
|
2023-07-04 13:48:52 +00:00
|
|
|
}
|