2020-07-22 07:41:40 +00:00
|
|
|
package pushnotificationserver
|
2020-07-03 08:02:28 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
2020-08-26 05:54:00 +00:00
|
|
|
"github.com/status-im/status-go/eth-node/types"
|
2020-07-03 08:02:28 +00:00
|
|
|
"github.com/status-im/status-go/protocol/protobuf"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestPushNotificationRegistrationToGoRushRequest(t *testing.T) {
|
|
|
|
message1 := []byte("message-1")
|
|
|
|
message2 := []byte("message-2")
|
|
|
|
message3 := []byte("message-3")
|
2020-08-26 05:54:00 +00:00
|
|
|
hexMessage1 := types.EncodeHex(message1)
|
|
|
|
hexMessage2 := types.EncodeHex(message2)
|
|
|
|
hexMessage3 := types.EncodeHex(message3)
|
|
|
|
chatID := []byte("chat-id")
|
2020-07-03 08:02:28 +00:00
|
|
|
publicKey1 := []byte("public-key-1")
|
|
|
|
publicKey2 := []byte("public-key-2")
|
|
|
|
installationID1 := "installation-id-1"
|
|
|
|
installationID2 := "installation-id-2"
|
|
|
|
installationID3 := "installation-id-3"
|
|
|
|
var platform1 uint = 1
|
|
|
|
var platform2 uint = 2
|
|
|
|
var platform3 uint = 2
|
|
|
|
token1 := "token-1"
|
|
|
|
token2 := "token-2"
|
|
|
|
token3 := "token-3"
|
|
|
|
|
|
|
|
requestAndRegistrations := []*RequestAndRegistration{
|
|
|
|
{
|
|
|
|
Request: &protobuf.PushNotification{
|
|
|
|
ChatId: chatID,
|
2020-09-03 06:58:58 +00:00
|
|
|
Type: protobuf.PushNotification_MESSAGE,
|
2020-07-03 08:02:28 +00:00
|
|
|
PublicKey: publicKey1,
|
|
|
|
InstallationId: installationID1,
|
|
|
|
Message: message1,
|
|
|
|
},
|
|
|
|
Registration: &protobuf.PushNotificationRegistration{
|
2020-07-22 07:41:40 +00:00
|
|
|
DeviceToken: token1,
|
|
|
|
TokenType: protobuf.PushNotificationRegistration_APN_TOKEN,
|
2020-07-03 08:02:28 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Request: &protobuf.PushNotification{
|
|
|
|
ChatId: chatID,
|
2020-09-03 06:58:58 +00:00
|
|
|
Type: protobuf.PushNotification_MESSAGE,
|
2020-07-03 08:02:28 +00:00
|
|
|
PublicKey: publicKey1,
|
|
|
|
InstallationId: installationID2,
|
|
|
|
Message: message2,
|
|
|
|
},
|
|
|
|
Registration: &protobuf.PushNotificationRegistration{
|
2020-07-22 07:41:40 +00:00
|
|
|
DeviceToken: token2,
|
|
|
|
TokenType: protobuf.PushNotificationRegistration_FIREBASE_TOKEN,
|
2020-07-03 08:02:28 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Request: &protobuf.PushNotification{
|
|
|
|
ChatId: chatID,
|
2020-09-03 06:58:58 +00:00
|
|
|
Type: protobuf.PushNotification_MENTION,
|
2020-07-03 08:02:28 +00:00
|
|
|
PublicKey: publicKey2,
|
|
|
|
InstallationId: installationID3,
|
|
|
|
Message: message3,
|
|
|
|
},
|
|
|
|
Registration: &protobuf.PushNotificationRegistration{
|
2020-07-22 07:41:40 +00:00
|
|
|
DeviceToken: token3,
|
|
|
|
TokenType: protobuf.PushNotificationRegistration_FIREBASE_TOKEN,
|
2020-07-03 08:02:28 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
expectedRequests := &GoRushRequest{
|
|
|
|
Notifications: []*GoRushRequestNotification{
|
|
|
|
{
|
|
|
|
Tokens: []string{token1},
|
|
|
|
Platform: platform1,
|
2020-09-03 06:58:58 +00:00
|
|
|
Message: defaultNewMessageNotificationText,
|
2020-07-03 08:02:28 +00:00
|
|
|
Data: &GoRushRequestData{
|
|
|
|
EncryptedMessage: hexMessage1,
|
2020-08-26 05:54:00 +00:00
|
|
|
ChatID: types.EncodeHex(chatID),
|
|
|
|
PublicKey: types.EncodeHex(publicKey1),
|
2020-07-03 08:02:28 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Tokens: []string{token2},
|
|
|
|
Platform: platform2,
|
2020-09-03 06:58:58 +00:00
|
|
|
Message: defaultNewMessageNotificationText,
|
2020-07-03 08:02:28 +00:00
|
|
|
Data: &GoRushRequestData{
|
|
|
|
EncryptedMessage: hexMessage2,
|
2020-08-26 05:54:00 +00:00
|
|
|
ChatID: types.EncodeHex(chatID),
|
|
|
|
PublicKey: types.EncodeHex(publicKey1),
|
2020-07-03 08:02:28 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Tokens: []string{token3},
|
|
|
|
Platform: platform3,
|
2020-09-03 06:58:58 +00:00
|
|
|
Message: defaultMentionNotificationText,
|
2020-07-03 08:02:28 +00:00
|
|
|
Data: &GoRushRequestData{
|
|
|
|
EncryptedMessage: hexMessage3,
|
2020-08-26 05:54:00 +00:00
|
|
|
ChatID: types.EncodeHex(chatID),
|
|
|
|
PublicKey: types.EncodeHex(publicKey2),
|
2020-07-03 08:02:28 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
actualRequests := PushNotificationRegistrationToGoRushRequest(requestAndRegistrations)
|
|
|
|
require.Equal(t, expectedRequests, actualRequests)
|
|
|
|
}
|