[MM-30980] Avoid modifying original post when sending a notification (#17697)

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
Miguel de la Cruz
2021-06-03 12:52:29 +02:00
коммит произвёл GitHub
родитель 3299a72adb
Коммит 42157fafa2
2 изменённых файлов: 13 добавлений и 5 удалений

Просмотреть файл

@@ -577,9 +577,10 @@ func (a *App) buildFullPushNotificationMessage(contentsConfig string, post *mode
msg.FromWebhook = fw
}
postMessage := post.Message
for _, attachment := range post.Attachments() {
if attachment.Fallback != "" {
post.Message += "\n" + attachment.Fallback
postMessage += "\n" + attachment.Fallback
}
}
@@ -588,7 +589,7 @@ func (a *App) buildFullPushNotificationMessage(contentsConfig string, post *mode
msg.Message = a.getPushNotificationMessage(
contentsConfig,
post.Message,
postMessage,
explicitMention,
channelWideMention,
hasFiles,

Просмотреть файл

@@ -1406,8 +1406,9 @@ func TestPushNotificationAttachment(t *testing.T) {
th := Setup(t)
defer th.TearDown()
originalMessage := "hello world"
post := &model.Post{
Message: "hello world",
Message: originalMessage,
Props: map[string]interface{}{
"attachments": []*model.SlackAttachment{
{
@@ -1421,8 +1422,14 @@ func TestPushNotificationAttachment(t *testing.T) {
user := &model.User{}
ch := &model.Channel{}
pn := th.App.buildFullPushNotificationMessage("full", post, user, ch, ch.Name, "test", false, false, "")
assert.Equal(t, "test: hello world\nfallback text", pn.Message)
t.Run("The notification should contain the fallback message from the attachment", func(t *testing.T) {
pn := th.App.buildFullPushNotificationMessage("full", post, user, ch, ch.Name, "test", false, false, "")
assert.Equal(t, "test: hello world\nfallback text", pn.Message)
})
t.Run("The original post message should not be modified", func(t *testing.T) {
assert.Equal(t, originalMessage, post.Message)
})
}
// Run it with | grep -v '{"level"' to prevent spamming the console.