summaryrefslogtreecommitdiffstats
path: root/app/notification_test.go
diff options
context:
space:
mode:
authorJonathan <jonfritz@gmail.com>2017-08-05 19:52:35 -0400
committerSaturnino Abril <saturnino.abril@gmail.com>2017-08-06 07:52:35 +0800
commit178ccd16cba26144eac404f413440867b360033c (patch)
tree5a2304ee8fbe7586d4101b7e38cd85756e114a05 /app/notification_test.go
parent9f3713aa98011596a62315fd3b96fa2e77044081 (diff)
downloadchat-178ccd16cba26144eac404f413440867b360033c.tar.gz
chat-178ccd16cba26144eac404f413440867b360033c.tar.bz2
chat-178ccd16cba26144eac404f413440867b360033c.zip
System Console: Email notification content setting (#7122)
* PLT-7195: Added new config option, new license feature, and config UI to system console. Still need to implement behaviour change in email batching code * PLT-7195: Modified batch emails to respect email notification content type setting * PLT-7195: Tweaking the colours a bit * PLT-7195: Added support for email notification content type setting in immediate (non-batched) notification messages. Attempted to clean up the code somewhat. Unit tests coming in a future commit * PLT-7195: Added unit tests for non-batched emails * Checked license when applying email content settings * Changed return type of getFormattedPostTime
Diffstat (limited to 'app/notification_test.go')
-rw-r--r--app/notification_test.go286
1 files changed, 286 insertions, 0 deletions
diff --git a/app/notification_test.go b/app/notification_test.go
index 022f671ae..5f57290e7 100644
--- a/app/notification_test.go
+++ b/app/notification_test.go
@@ -4,9 +4,11 @@
package app
import (
+ "strings"
"testing"
"github.com/mattermost/platform/model"
+ "github.com/mattermost/platform/utils"
)
func TestSendNotifications(t *testing.T) {
@@ -817,3 +819,287 @@ func TestDoesStatusAllowPushNotification(t *testing.T) {
t.Fatal("Should have been false")
}
}
+
+func TestGetDirectMessageNotificationEmailSubject(t *testing.T) {
+ Setup()
+ expectedPrefix := "[http://localhost:8065] New Direct Message from sender on"
+ post := &model.Post{
+ CreateAt: 1501804801000,
+ }
+ translateFunc := utils.GetUserTranslations("en")
+ subject := getDirectMessageNotificationEmailSubject(post, translateFunc, "http://localhost:8065", "sender")
+ if !strings.HasPrefix(subject, expectedPrefix) {
+ t.Fatal("Expected subject line prefix '" + expectedPrefix + "', got " + subject)
+ }
+}
+
+func TestGetNotificationEmailSubject(t *testing.T) {
+ Setup()
+ expectedPrefix := "[http://localhost:8065] Notification in team on"
+ post := &model.Post{
+ CreateAt: 1501804801000,
+ }
+ translateFunc := utils.GetUserTranslations("en")
+ subject := getNotificationEmailSubject(post, translateFunc, "http://localhost:8065", "team")
+ if !strings.HasPrefix(subject, expectedPrefix) {
+ t.Fatal("Expected subject line prefix '" + expectedPrefix + "', got " + subject)
+ }
+}
+
+func TestGetNotificationEmailBodyFullNotificationPublicChannel(t *testing.T) {
+ Setup()
+ recipient := &model.User{}
+ post := &model.Post{
+ Message: "This is the message",
+ }
+ channel := &model.Channel{
+ DisplayName: "ChannelName",
+ Type: model.CHANNEL_OPEN,
+ }
+ senderName := "sender"
+ teamName := "team"
+ teamURL := "http://localhost:8065/" + teamName
+ emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_FULL
+ translateFunc := utils.GetUserTranslations("en")
+
+ body := getNotificationEmailBody(recipient, post, channel, senderName, teamName, teamURL, emailNotificationContentsType, translateFunc)
+ if !strings.Contains(body, "You have a new notification.") {
+ t.Fatal("Expected email text 'You have a new notification. Got " + body)
+ }
+ if !strings.Contains(body, "CHANNEL: "+channel.DisplayName) {
+ t.Fatal("Expected email text 'CHANNEL: " + channel.DisplayName + "'. Got " + body)
+ }
+ if !strings.Contains(body, senderName+" - ") {
+ t.Fatal("Expected email text '" + senderName + " - '. Got " + body)
+ }
+ if !strings.Contains(body, post.Message) {
+ t.Fatal("Expected email text '" + post.Message + "'. Got " + body)
+ }
+ if !strings.Contains(body, teamURL) {
+ t.Fatal("Expected email text '" + teamURL + "'. Got " + body)
+ }
+}
+
+func TestGetNotificationEmailBodyFullNotificationGroupChannel(t *testing.T) {
+ Setup()
+ recipient := &model.User{}
+ post := &model.Post{
+ Message: "This is the message",
+ }
+ channel := &model.Channel{
+ DisplayName: "ChannelName",
+ Type: model.CHANNEL_GROUP,
+ }
+ senderName := "sender"
+ teamName := "team"
+ teamURL := "http://localhost:8065/" + teamName
+ emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_FULL
+ translateFunc := utils.GetUserTranslations("en")
+
+ body := getNotificationEmailBody(recipient, post, channel, senderName, teamName, teamURL, emailNotificationContentsType, translateFunc)
+ if !strings.Contains(body, "You have a new notification.") {
+ t.Fatal("Expected email text 'You have a new notification. Got " + body)
+ }
+ if !strings.Contains(body, "CHANNEL: Group Message") {
+ t.Fatal("Expected email text 'CHANNEL: Group Message'. Got " + body)
+ }
+ if !strings.Contains(body, senderName+" - ") {
+ t.Fatal("Expected email text '" + senderName + " - '. Got " + body)
+ }
+ if !strings.Contains(body, post.Message) {
+ t.Fatal("Expected email text '" + post.Message + "'. Got " + body)
+ }
+ if !strings.Contains(body, teamURL) {
+ t.Fatal("Expected email text '" + teamURL + "'. Got " + body)
+ }
+}
+
+func TestGetNotificationEmailBodyFullNotificationPrivateChannel(t *testing.T) {
+ Setup()
+ recipient := &model.User{}
+ post := &model.Post{
+ Message: "This is the message",
+ }
+ channel := &model.Channel{
+ DisplayName: "ChannelName",
+ Type: model.CHANNEL_PRIVATE,
+ }
+ senderName := "sender"
+ teamName := "team"
+ teamURL := "http://localhost:8065/" + teamName
+ emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_FULL
+ translateFunc := utils.GetUserTranslations("en")
+
+ body := getNotificationEmailBody(recipient, post, channel, senderName, teamName, teamURL, emailNotificationContentsType, translateFunc)
+ if !strings.Contains(body, "You have a new notification.") {
+ t.Fatal("Expected email text 'You have a new notification. Got " + body)
+ }
+ if !strings.Contains(body, "CHANNEL: "+channel.DisplayName) {
+ t.Fatal("Expected email text 'CHANNEL: " + channel.DisplayName + "'. Got " + body)
+ }
+ if !strings.Contains(body, senderName+" - ") {
+ t.Fatal("Expected email text '" + senderName + " - '. Got " + body)
+ }
+ if !strings.Contains(body, post.Message) {
+ t.Fatal("Expected email text '" + post.Message + "'. Got " + body)
+ }
+ if !strings.Contains(body, teamURL) {
+ t.Fatal("Expected email text '" + teamURL + "'. Got " + body)
+ }
+}
+
+func TestGetNotificationEmailBodyFullNotificationDirectChannel(t *testing.T) {
+ Setup()
+ recipient := &model.User{}
+ post := &model.Post{
+ Message: "This is the message",
+ }
+ channel := &model.Channel{
+ DisplayName: "ChannelName",
+ Type: model.CHANNEL_DIRECT,
+ }
+ senderName := "sender"
+ teamName := "team"
+ teamURL := "http://localhost:8065/" + teamName
+ emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_FULL
+ translateFunc := utils.GetUserTranslations("en")
+
+ body := getNotificationEmailBody(recipient, post, channel, senderName, teamName, teamURL, emailNotificationContentsType, translateFunc)
+ if !strings.Contains(body, "You have a new direct message.") {
+ t.Fatal("Expected email text 'You have a new direct message. Got " + body)
+ }
+ if !strings.Contains(body, senderName+" - ") {
+ t.Fatal("Expected email text '" + senderName + " - '. Got " + body)
+ }
+ if !strings.Contains(body, post.Message) {
+ t.Fatal("Expected email text '" + post.Message + "'. Got " + body)
+ }
+ if !strings.Contains(body, teamURL) {
+ t.Fatal("Expected email text '" + teamURL + "'. Got " + body)
+ }
+}
+
+// from here
+func TestGetNotificationEmailBodyGenericNotificationPublicChannel(t *testing.T) {
+ Setup()
+ recipient := &model.User{}
+ post := &model.Post{
+ Message: "This is the message",
+ }
+ channel := &model.Channel{
+ DisplayName: "ChannelName",
+ Type: model.CHANNEL_OPEN,
+ }
+ senderName := "sender"
+ teamName := "team"
+ teamURL := "http://localhost:8065/" + teamName
+ emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_GENERIC
+ translateFunc := utils.GetUserTranslations("en")
+
+ body := getNotificationEmailBody(recipient, post, channel, senderName, teamName, teamURL, emailNotificationContentsType, translateFunc)
+ if !strings.Contains(body, "You have a new notification from "+senderName) {
+ t.Fatal("Expected email text 'You have a new notification from " + senderName + "'. Got " + body)
+ }
+ if strings.Contains(body, "CHANNEL: "+channel.DisplayName) {
+ t.Fatal("Did not expect email text 'CHANNEL: " + channel.DisplayName + "'. Got " + body)
+ }
+ if strings.Contains(body, post.Message) {
+ t.Fatal("Did not expect email text '" + post.Message + "'. Got " + body)
+ }
+ if !strings.Contains(body, teamURL) {
+ t.Fatal("Expected email text '" + teamURL + "'. Got " + body)
+ }
+}
+
+func TestGetNotificationEmailBodyGenericNotificationGroupChannel(t *testing.T) {
+ Setup()
+ recipient := &model.User{}
+ post := &model.Post{
+ Message: "This is the message",
+ }
+ channel := &model.Channel{
+ DisplayName: "ChannelName",
+ Type: model.CHANNEL_GROUP,
+ }
+ senderName := "sender"
+ teamName := "team"
+ teamURL := "http://localhost:8065/" + teamName
+ emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_GENERIC
+ translateFunc := utils.GetUserTranslations("en")
+
+ body := getNotificationEmailBody(recipient, post, channel, senderName, teamName, teamURL, emailNotificationContentsType, translateFunc)
+ if !strings.Contains(body, "You have a new notification from "+senderName) {
+ t.Fatal("Expected email text 'You have a new notification from " + senderName + "'. Got " + body)
+ }
+ if strings.Contains(body, "CHANNEL: "+channel.DisplayName) {
+ t.Fatal("Did not expect email text 'CHANNEL: " + channel.DisplayName + "'. Got " + body)
+ }
+ if strings.Contains(body, post.Message) {
+ t.Fatal("Did not expect email text '" + post.Message + "'. Got " + body)
+ }
+ if !strings.Contains(body, teamURL) {
+ t.Fatal("Expected email text '" + teamURL + "'. Got " + body)
+ }
+}
+
+func TestGetNotificationEmailBodyGenericNotificationPrivateChannel(t *testing.T) {
+ Setup()
+ recipient := &model.User{}
+ post := &model.Post{
+ Message: "This is the message",
+ }
+ channel := &model.Channel{
+ DisplayName: "ChannelName",
+ Type: model.CHANNEL_PRIVATE,
+ }
+ senderName := "sender"
+ teamName := "team"
+ teamURL := "http://localhost:8065/" + teamName
+ emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_GENERIC
+ translateFunc := utils.GetUserTranslations("en")
+
+ body := getNotificationEmailBody(recipient, post, channel, senderName, teamName, teamURL, emailNotificationContentsType, translateFunc)
+ if !strings.Contains(body, "You have a new notification from "+senderName) {
+ t.Fatal("Expected email text 'You have a new notification from " + senderName + "'. Got " + body)
+ }
+ if strings.Contains(body, "CHANNEL: "+channel.DisplayName) {
+ t.Fatal("Did not expect email text 'CHANNEL: " + channel.DisplayName + "'. Got " + body)
+ }
+ if strings.Contains(body, post.Message) {
+ t.Fatal("Did not expect email text '" + post.Message + "'. Got " + body)
+ }
+ if !strings.Contains(body, teamURL) {
+ t.Fatal("Expected email text '" + teamURL + "'. Got " + body)
+ }
+}
+
+func TestGetNotificationEmailBodyGenericNotificationDirectChannel(t *testing.T) {
+ Setup()
+ recipient := &model.User{}
+ post := &model.Post{
+ Message: "This is the message",
+ }
+ channel := &model.Channel{
+ DisplayName: "ChannelName",
+ Type: model.CHANNEL_DIRECT,
+ }
+ senderName := "sender"
+ teamName := "team"
+ teamURL := "http://localhost:8065/" + teamName
+ emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_GENERIC
+ translateFunc := utils.GetUserTranslations("en")
+
+ body := getNotificationEmailBody(recipient, post, channel, senderName, teamName, teamURL, emailNotificationContentsType, translateFunc)
+ if !strings.Contains(body, "You have a new direct message from "+senderName) {
+ t.Fatal("Expected email text 'You have a new direct message from " + senderName + "'. Got " + body)
+ }
+ if strings.Contains(body, "CHANNEL: "+channel.DisplayName) {
+ t.Fatal("Did not expect email text 'CHANNEL: " + channel.DisplayName + "'. Got " + body)
+ }
+ if strings.Contains(body, post.Message) {
+ t.Fatal("Did not expect email text '" + post.Message + "'. Got " + body)
+ }
+ if !strings.Contains(body, teamURL) {
+ t.Fatal("Expected email text '" + teamURL + "'. Got " + body)
+ }
+}