mirror of
https://github.com/status-im/status-go.git
synced 2026-08-31 09:01:16 +00:00
Part of the Go project layout migration, item 27. Pure move plus import-path rewrite across 502 files. No API or behaviour change. `internal/` keeps the messaging application logic unimportable from outside the module, which is what the issue asks for -- status-go is consumed through the C-bindings in mobile/, not as a Go library. Things that had to follow the move, beyond the Go imports: - tools/generate-handlers/template.txt. messenger_handlers.go is generated, and the template hard-codes the imports it emits, so the generated file kept importing protocol/common and failed typecheck. - .gitignore. The ignore rule for that generated file was pinned to the old path; without moving it, a 1486-line generated file starts being tracked. - Makefile: the logosstorage and torrent test targets (both the archive packages and ./protocol itself), the archive README, migration-protocol. - scripts/run_unit_tests.sh, which names the protocol package explicitly to shard its tests. - scripts/cleanup_generated_files.sh and .golangci.yml. scripts/migration_check.sh also needed a fix that is not specific to this move: it validated every file the branch touched under a migration dir against the timestamp naming rule, and a directory rename makes every migration in it look newly added. It now excludes renames, so moving a migration is not mistaken for adding one. refs #7067
200 lines
6.3 KiB
Go
200 lines
6.3 KiB
Go
package pushnotificationserver
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/status-im/status-go/internal/crypto/types"
|
|
"github.com/status-im/status-go/internal/protocol/protobuf"
|
|
)
|
|
|
|
func TestPushNotificationRegistrationToGoRushRequest(t *testing.T) {
|
|
message1 := []byte("message-1")
|
|
message2 := []byte("message-2")
|
|
message3 := []byte("message-3")
|
|
hexMessage1 := types.EncodeHex(message1)
|
|
hexMessage2 := types.EncodeHex(message2)
|
|
hexMessage3 := types.EncodeHex(message3)
|
|
chatID := []byte("chat-id")
|
|
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,
|
|
Type: protobuf.PushNotification_MESSAGE,
|
|
PublicKey: publicKey1,
|
|
InstallationId: installationID1,
|
|
Message: message1,
|
|
},
|
|
Registration: &protobuf.PushNotificationRegistration{
|
|
DeviceToken: token1,
|
|
TokenType: protobuf.PushNotificationRegistration_APN_TOKEN,
|
|
},
|
|
},
|
|
{
|
|
Request: &protobuf.PushNotification{
|
|
ChatId: chatID,
|
|
Type: protobuf.PushNotification_MESSAGE,
|
|
PublicKey: publicKey1,
|
|
InstallationId: installationID2,
|
|
Message: message2,
|
|
},
|
|
Registration: &protobuf.PushNotificationRegistration{
|
|
DeviceToken: token2,
|
|
TokenType: protobuf.PushNotificationRegistration_FIREBASE_TOKEN,
|
|
},
|
|
},
|
|
{
|
|
Request: &protobuf.PushNotification{
|
|
ChatId: chatID,
|
|
Type: protobuf.PushNotification_MENTION,
|
|
PublicKey: publicKey2,
|
|
InstallationId: installationID3,
|
|
Message: message3,
|
|
},
|
|
Registration: &protobuf.PushNotificationRegistration{
|
|
DeviceToken: token3,
|
|
TokenType: protobuf.PushNotificationRegistration_FIREBASE_TOKEN,
|
|
},
|
|
},
|
|
{
|
|
Request: &protobuf.PushNotification{
|
|
ChatId: chatID,
|
|
Type: protobuf.PushNotification_CONTACT_REQUEST,
|
|
PublicKey: publicKey2,
|
|
InstallationId: installationID3,
|
|
Message: message3,
|
|
},
|
|
Registration: &protobuf.PushNotificationRegistration{
|
|
DeviceToken: token3,
|
|
TokenType: protobuf.PushNotificationRegistration_APN_TOKEN,
|
|
},
|
|
},
|
|
}
|
|
|
|
expectedRequests := &GoRushRequest{
|
|
Notifications: []*GoRushRequestNotification{
|
|
{
|
|
Tokens: []string{token1},
|
|
Platform: platform1,
|
|
Message: defaultNewMessageNotificationText,
|
|
ContentAvailable: true,
|
|
Sound: "default",
|
|
Priority: "high",
|
|
PushType: "alert",
|
|
Data: &GoRushRequestData{
|
|
EncryptedMessage: hexMessage1,
|
|
ChatID: types.EncodeHex(chatID),
|
|
PublicKey: types.EncodeHex(publicKey1),
|
|
DeepLink: deepLinkChats,
|
|
},
|
|
},
|
|
{
|
|
Tokens: []string{token2},
|
|
Platform: platform2,
|
|
Message: defaultNewMessageNotificationText,
|
|
Data: &GoRushRequestData{
|
|
EncryptedMessage: hexMessage2,
|
|
ChatID: types.EncodeHex(chatID),
|
|
PublicKey: types.EncodeHex(publicKey1),
|
|
},
|
|
},
|
|
{
|
|
Tokens: []string{token3},
|
|
Platform: platform3,
|
|
Message: defaultMentionNotificationText,
|
|
Data: &GoRushRequestData{
|
|
EncryptedMessage: hexMessage3,
|
|
ChatID: types.EncodeHex(chatID),
|
|
PublicKey: types.EncodeHex(publicKey2),
|
|
},
|
|
},
|
|
{
|
|
Tokens: []string{token3},
|
|
Platform: platform1,
|
|
Message: defaultContactRequestNotificationText,
|
|
ContentAvailable: true,
|
|
Sound: "default",
|
|
Priority: "high",
|
|
PushType: "alert",
|
|
Data: &GoRushRequestData{
|
|
EncryptedMessage: hexMessage3,
|
|
ChatID: types.EncodeHex(chatID),
|
|
PublicKey: types.EncodeHex(publicKey2),
|
|
DeepLink: deepLinkContactRequests,
|
|
},
|
|
},
|
|
},
|
|
}
|
|
actualRequests := PushNotificationRegistrationToGoRushRequest(requestAndRegistrations)
|
|
require.Equal(t, expectedRequests, actualRequests)
|
|
}
|
|
|
|
func TestGoRushRequestMakesAPNAlertWithSound(t *testing.T) {
|
|
req := PushNotificationRegistrationToGoRushRequest([]*RequestAndRegistration{{
|
|
Request: &protobuf.PushNotification{Type: protobuf.PushNotification_MESSAGE},
|
|
Registration: &protobuf.PushNotificationRegistration{
|
|
TokenType: protobuf.PushNotificationRegistration_APN_TOKEN,
|
|
DeviceToken: "tok",
|
|
ApnTopic: "im.status.ethereum",
|
|
},
|
|
}})
|
|
n := req.Notifications[0]
|
|
require.Equal(t, "default", n.Sound)
|
|
require.Equal(t, "high", n.Priority)
|
|
require.Equal(t, "alert", n.PushType)
|
|
require.True(t, n.ContentAvailable)
|
|
}
|
|
|
|
func TestGoRushRequestFirebaseUnaffected(t *testing.T) {
|
|
req := PushNotificationRegistrationToGoRushRequest([]*RequestAndRegistration{{
|
|
Request: &protobuf.PushNotification{Type: protobuf.PushNotification_MESSAGE},
|
|
Registration: &protobuf.PushNotificationRegistration{
|
|
TokenType: protobuf.PushNotificationRegistration_FIREBASE_TOKEN,
|
|
DeviceToken: "tok",
|
|
},
|
|
}})
|
|
n := req.Notifications[0]
|
|
require.Empty(t, n.Sound)
|
|
require.Empty(t, n.PushType)
|
|
require.Empty(t, n.Data.DeepLink)
|
|
}
|
|
|
|
func TestGoRushRequestDeepLinkByType(t *testing.T) {
|
|
cases := []struct {
|
|
name string
|
|
pushType protobuf.PushNotification_PushNotificationType
|
|
expected string
|
|
}{
|
|
{"message", protobuf.PushNotification_MESSAGE, deepLinkChats},
|
|
{"mention", protobuf.PushNotification_MENTION, deepLinkActivityCenter},
|
|
{"community request", protobuf.PushNotification_REQUEST_TO_JOIN_COMMUNITY, deepLinkActivityCenter},
|
|
{"contact request", protobuf.PushNotification_CONTACT_REQUEST, deepLinkContactRequests},
|
|
{"unknown", protobuf.PushNotification_UNKNOWN_PUSH_NOTIFICATION_TYPE, deepLinkActivityCenter},
|
|
}
|
|
for _, tc := range cases {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
req := PushNotificationRegistrationToGoRushRequest([]*RequestAndRegistration{{
|
|
Request: &protobuf.PushNotification{Type: tc.pushType},
|
|
Registration: &protobuf.PushNotificationRegistration{
|
|
TokenType: protobuf.PushNotificationRegistration_APN_TOKEN,
|
|
DeviceToken: "tok",
|
|
},
|
|
}})
|
|
require.Equal(t, tc.expected, req.Notifications[0].Data.DeepLink)
|
|
})
|
|
}
|
|
}
|