From 0cbba46018d3879234d3940e8ee6f23dd99a1c5a Mon Sep 17 00:00:00 2001 From: Stephen Kiers Date: Mon, 12 Feb 2018 16:30:03 -0700 Subject: Fixes ICU-764 --- app/notification_test.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'app/notification_test.go') diff --git a/app/notification_test.go b/app/notification_test.go index 11f4df685..7f2a63ab9 100644 --- a/app/notification_test.go +++ b/app/notification_test.go @@ -109,6 +109,15 @@ func TestGetExplicitMentions(t *testing.T) { }, }, }, + "OnePersonAtEndOfSentence": { + Message: "this is a message for @user.", + Keywords: map[string][]string{"@user": {id1}}, + Expected: &ExplicitMentions{ + MentionedUserIds: map[string]bool{ + id1: true, + }, + }, + }, "OnePersonWithoutAtMention": { Message: "this is a message for @user", Keywords: map[string][]string{"this": {id1}}, @@ -179,6 +188,15 @@ func TestGetExplicitMentions(t *testing.T) { }, }, }, + "UserWithPeriodAtEndOfSentence": { + Message: "this is a message for user.period.", + Keywords: map[string][]string{"user.period": {id1}}, + Expected: &ExplicitMentions{ + MentionedUserIds: map[string]bool{ + id1: true, + }, + }, + }, "PotentialOutOfChannelUser": { Message: "this is an message for @potential and @user", Keywords: map[string][]string{"@user": {id1}}, -- cgit v1.2.3-1-g7c22 From bdf478c75bb41c00cdfd47bd7ae68c70a06886af Mon Sep 17 00:00:00 2001 From: Stephen Kiers Date: Mon, 12 Feb 2018 20:50:20 -0700 Subject: Added another test --- app/notification_test.go | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'app/notification_test.go') diff --git a/app/notification_test.go b/app/notification_test.go index 7f2a63ab9..61442c048 100644 --- a/app/notification_test.go +++ b/app/notification_test.go @@ -188,6 +188,15 @@ func TestGetExplicitMentions(t *testing.T) { }, }, }, + "AtUserWithPeriodAtEndOfSentence": { + Message: "this is a message for @user.period.", + Keywords: map[string][]string{"@user.period": {id1}}, + Expected: &ExplicitMentions{ + MentionedUserIds: map[string]bool{ + id1: true, + }, + }, + }, "UserWithPeriodAtEndOfSentence": { Message: "this is a message for user.period.", Keywords: map[string][]string{"user.period": {id1}}, -- cgit v1.2.3-1-g7c22 From c1b49f8b77e0e75afcc6cf4dc0f1c36569824151 Mon Sep 17 00:00:00 2001 From: Harrison Healey Date: Mon, 12 Feb 2018 11:50:41 -0500 Subject: ICU-753 Added unit tests for push notification contents --- app/notification_test.go | 211 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 211 insertions(+) (limited to 'app/notification_test.go') diff --git a/app/notification_test.go b/app/notification_test.go index 11f4df685..2b7b260c4 100644 --- a/app/notification_test.go +++ b/app/notification_test.go @@ -1166,3 +1166,214 @@ func TestGetNotificationEmailBodyGenericNotificationDirectChannel(t *testing.T) t.Fatal("Expected email text '" + teamURL + "'. Got " + body) } } + +func TestGetPushNotificationMessage(t *testing.T) { + th := Setup() + defer th.TearDown() + + for name, tc := range map[string]struct { + Message string + WasMentioned bool + HasFiles bool + Locale string + PushNotificationContents string + ChannelType string + + ExpectedMessage string + ExpectedCategory string + }{ + "full message, public channel, no mention": { + Message: "this is a message", + ChannelType: model.CHANNEL_OPEN, + ExpectedMessage: "user in channel: this is a message", + ExpectedCategory: model.CATEGORY_CAN_REPLY, + }, + "full message, public channel, mention": { + Message: "this is a message", + WasMentioned: true, + ChannelType: model.CHANNEL_OPEN, + ExpectedMessage: "user in channel: this is a message", + ExpectedCategory: model.CATEGORY_CAN_REPLY, + }, + "full message, private channel, no mention": { + Message: "this is a message", + ChannelType: model.CHANNEL_PRIVATE, + ExpectedMessage: "user in channel: this is a message", + ExpectedCategory: model.CATEGORY_CAN_REPLY, + }, + "full message, private channel, mention": { + Message: "this is a message", + WasMentioned: true, + ChannelType: model.CHANNEL_PRIVATE, + ExpectedMessage: "user in channel: this is a message", + ExpectedCategory: model.CATEGORY_CAN_REPLY, + }, + "full message, group message channel, no mention": { + Message: "this is a message", + ChannelType: model.CHANNEL_GROUP, + ExpectedMessage: "user in channel: this is a message", + ExpectedCategory: model.CATEGORY_CAN_REPLY, + }, + "full message, group message channel, mention": { + Message: "this is a message", + WasMentioned: true, + ChannelType: model.CHANNEL_GROUP, + ExpectedMessage: "user in channel: this is a message", + ExpectedCategory: model.CATEGORY_CAN_REPLY, + }, + "full message, direct message channel, no mention": { + Message: "this is a message", + ChannelType: model.CHANNEL_DIRECT, + ExpectedMessage: "user: this is a message", + ExpectedCategory: model.CATEGORY_CAN_REPLY, + }, + "full message, direct message channel, mention": { + Message: "this is a message", + WasMentioned: true, + ChannelType: model.CHANNEL_DIRECT, + ExpectedMessage: "user: this is a message", + ExpectedCategory: model.CATEGORY_CAN_REPLY, + }, + "generic message with channel, public channel, no mention": { + Message: "this is a message", + PushNotificationContents: model.GENERIC_NOTIFICATION, + ChannelType: model.CHANNEL_OPEN, + ExpectedMessage: "user posted in channel", + }, + "generic message with channel, public channel, mention": { + Message: "this is a message", + WasMentioned: true, + PushNotificationContents: model.GENERIC_NOTIFICATION, + ChannelType: model.CHANNEL_OPEN, + ExpectedMessage: "user mentioned you in channel", + ExpectedCategory: model.CATEGORY_CAN_REPLY, + }, + "generic message with channel, private channel, no mention": { + Message: "this is a message", + PushNotificationContents: model.GENERIC_NOTIFICATION, + ChannelType: model.CHANNEL_PRIVATE, + ExpectedMessage: "user posted in channel", + }, + "generic message with channel, private channel, mention": { + Message: "this is a message", + WasMentioned: true, + PushNotificationContents: model.GENERIC_NOTIFICATION, + ChannelType: model.CHANNEL_PRIVATE, + ExpectedMessage: "user mentioned you in channel", + ExpectedCategory: model.CATEGORY_CAN_REPLY, + }, + "generic message with channel, group message channel, no mention": { + Message: "this is a message", + PushNotificationContents: model.GENERIC_NOTIFICATION, + ChannelType: model.CHANNEL_GROUP, + ExpectedMessage: "user posted in channel", + }, + "generic message with channel, group message channel, mention": { + Message: "this is a message", + WasMentioned: true, + PushNotificationContents: model.GENERIC_NOTIFICATION, + ChannelType: model.CHANNEL_GROUP, + ExpectedMessage: "user mentioned you in channel", + ExpectedCategory: model.CATEGORY_CAN_REPLY, + }, + "generic message with channel, direct message channel, no mention": { + Message: "this is a message", + PushNotificationContents: model.GENERIC_NOTIFICATION, + ChannelType: model.CHANNEL_DIRECT, + ExpectedMessage: "user sent you a direct message", + ExpectedCategory: model.CATEGORY_CAN_REPLY, + }, + "generic message with channel, direct message channel, mention": { + Message: "this is a message", + WasMentioned: true, + PushNotificationContents: model.GENERIC_NOTIFICATION, + ChannelType: model.CHANNEL_DIRECT, + ExpectedMessage: "user sent you a direct message", + ExpectedCategory: model.CATEGORY_CAN_REPLY, + }, + "generic message without channel, public channel, no mention": { + Message: "this is a message", + PushNotificationContents: model.GENERIC_NO_CHANNEL_NOTIFICATION, + ChannelType: model.CHANNEL_OPEN, + ExpectedMessage: "user posted a message", + }, + "generic message without channel, public channel, mention": { + Message: "this is a message", + WasMentioned: true, + PushNotificationContents: model.GENERIC_NO_CHANNEL_NOTIFICATION, + ChannelType: model.CHANNEL_OPEN, + ExpectedMessage: "user mentioned you", + }, + "generic message without channel, private channel, no mention": { + Message: "this is a message", + PushNotificationContents: model.GENERIC_NO_CHANNEL_NOTIFICATION, + ChannelType: model.CHANNEL_PRIVATE, + ExpectedMessage: "user posted a message", + }, + "generic message without channel, private channel, mention": { + Message: "this is a message", + WasMentioned: true, + PushNotificationContents: model.GENERIC_NO_CHANNEL_NOTIFICATION, + ChannelType: model.CHANNEL_PRIVATE, + ExpectedMessage: "user mentioned you", + }, + "generic message without channel, group message channel, no mention": { + Message: "this is a message", + PushNotificationContents: model.GENERIC_NO_CHANNEL_NOTIFICATION, + ChannelType: model.CHANNEL_GROUP, + ExpectedMessage: "user posted a message", + }, + "generic message without channel, group message channel, mention": { + Message: "this is a message", + WasMentioned: true, + PushNotificationContents: model.GENERIC_NO_CHANNEL_NOTIFICATION, + ChannelType: model.CHANNEL_GROUP, + ExpectedMessage: "user mentioned you", + }, + "generic message without channel, direct message channel, no mention": { + Message: "this is a message", + PushNotificationContents: model.GENERIC_NO_CHANNEL_NOTIFICATION, + ChannelType: model.CHANNEL_DIRECT, + ExpectedMessage: "user sent you a direct message", + ExpectedCategory: model.CATEGORY_CAN_REPLY, + }, + "generic message without channel, direct message channel, mention": { + Message: "this is a message", + WasMentioned: true, + PushNotificationContents: model.GENERIC_NO_CHANNEL_NOTIFICATION, + ChannelType: model.CHANNEL_DIRECT, + ExpectedMessage: "user sent you a direct message", + ExpectedCategory: model.CATEGORY_CAN_REPLY, + }, + } { + t.Run(name, func(t *testing.T) { + locale := tc.Locale + if locale == "" { + locale = "en" + } + + pushNotificationContents := tc.PushNotificationContents + if pushNotificationContents == "" { + pushNotificationContents = model.FULL_NOTIFICATION + } + + th.App.UpdateConfig(func(cfg *model.Config) { + *cfg.EmailSettings.PushNotificationContents = pushNotificationContents + }) + + if actualMessage, actualCategory := th.App.getPushNotificationMessage( + tc.Message, + tc.WasMentioned, + tc.HasFiles, + "user", + "channel", + tc.ChannelType, + utils.GetUserTranslations(locale), + ); actualMessage != tc.ExpectedMessage { + t.Fatalf("Received incorrect push notification message `%v`, expected `%v`", actualMessage, tc.ExpectedMessage) + } else if actualCategory != tc.ExpectedCategory { + t.Fatalf("Received incorrect push notification category `%v`, expected `%v`", actualCategory, tc.ExpectedCategory) + } + }) + } +} -- cgit v1.2.3-1-g7c22 From 3fef21e350737c235e6dfc2d9f35311d65290c3e Mon Sep 17 00:00:00 2001 From: Harrison Healey Date: Mon, 12 Feb 2018 12:56:46 -0500 Subject: ICU-753 Added unit tests for messages with only push notifications --- app/notification_test.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'app/notification_test.go') diff --git a/app/notification_test.go b/app/notification_test.go index 2b7b260c4..cc501fbd0 100644 --- a/app/notification_test.go +++ b/app/notification_test.go @@ -1345,6 +1345,30 @@ func TestGetPushNotificationMessage(t *testing.T) { ExpectedMessage: "user sent you a direct message", ExpectedCategory: model.CATEGORY_CAN_REPLY, }, + "only files, public channel": { + HasFiles: true, + ChannelType: model.CHANNEL_OPEN, + ExpectedMessage: "user uploaded one or more files in channel", + ExpectedCategory: model.CATEGORY_CAN_REPLY, + }, + "only files, private channel": { + HasFiles: true, + ChannelType: model.CHANNEL_PRIVATE, + ExpectedMessage: "user uploaded one or more files in channel", + ExpectedCategory: model.CATEGORY_CAN_REPLY, + }, + "only files, group message channel": { + HasFiles: true, + ChannelType: model.CHANNEL_GROUP, + ExpectedMessage: "user uploaded one or more files in channel", + ExpectedCategory: model.CATEGORY_CAN_REPLY, + }, + "only files, direct message channel": { + HasFiles: true, + ChannelType: model.CHANNEL_DIRECT, + ExpectedMessage: "user uploaded one or more files in a direct message", + ExpectedCategory: model.CATEGORY_CAN_REPLY, + }, } { t.Run(name, func(t *testing.T) { locale := tc.Locale -- cgit v1.2.3-1-g7c22 From 08c21f75199f959bbe63396be246e2b7d36a9a39 Mon Sep 17 00:00:00 2001 From: Stephen Kiers Date: Tue, 13 Feb 2018 10:49:48 -0700 Subject: Added more tests and simplified code --- app/notification_test.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'app/notification_test.go') diff --git a/app/notification_test.go b/app/notification_test.go index 61442c048..bd7da3db7 100644 --- a/app/notification_test.go +++ b/app/notification_test.go @@ -109,6 +109,24 @@ func TestGetExplicitMentions(t *testing.T) { }, }, }, + "OnePersonWithPeriodAtEndOfUsername": { + Message: "this is a message for @user.name.", + Keywords: map[string][]string{"@user.name.": {id1}}, + Expected: &ExplicitMentions{ + MentionedUserIds: map[string]bool{ + id1: true, + }, + }, + }, + "OnePersonWithPeriodAtEndOfUsernameButNotSimilarName": { + Message: "this is a message for @user.name.", + Keywords: map[string][]string{"@user.name.": {id1}, "@user.name": {id2}}, + Expected: &ExplicitMentions{ + MentionedUserIds: map[string]bool{ + id1: true, + }, + }, + }, "OnePersonAtEndOfSentence": { Message: "this is a message for @user.", Keywords: map[string][]string{"@user": {id1}}, -- cgit v1.2.3-1-g7c22 From 1b3808f3ecf754876168a9342e18c46d49f32ddf Mon Sep 17 00:00:00 2001 From: Joram Wilander Date: Thu, 22 Feb 2018 09:00:13 -0500 Subject: Fix push notification content for file only messages (#8346) --- app/notification_test.go | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'app/notification_test.go') diff --git a/app/notification_test.go b/app/notification_test.go index 43703c019..5fc1d152c 100644 --- a/app/notification_test.go +++ b/app/notification_test.go @@ -1414,6 +1414,12 @@ func TestGetPushNotificationMessage(t *testing.T) { ExpectedMessage: "user uploaded one or more files in a direct message", ExpectedCategory: model.CATEGORY_CAN_REPLY, }, + "only files without channel, public channel": { + HasFiles: true, + PushNotificationContents: model.GENERIC_NO_CHANNEL_NOTIFICATION, + ChannelType: model.CHANNEL_OPEN, + ExpectedMessage: "user uploaded one or more files", + }, } { t.Run(name, func(t *testing.T) { locale := tc.Locale -- cgit v1.2.3-1-g7c22