Files
mostlymatter/api/command_mute_test.go
Christian Claus 257f748732 [PLT-4340] Channel Mute and "/mute" command #7617 (#7713)
* Add command and store changes to allow mute toggling

* Change channel muting to use ChannelMember notification structure

* Suppress email and push notifications for a muted channel

* Make i18n keys issue-compliant

* Add notification-cache handling for channel-muting

* Add channel handle for channel-muting slash-command

* Add unit test for mute command

* Merge branch 'master' into PLT-4340

# Conflicts:
#	app/notification.go

* Fix issue that command_mute responses will be overwritten

* Fix i18n key for channel muting

* Apply new Provider Interface to MuteCommand

* Migrate mute notification property to mark_unread

PLT-4340

* Make some i18n improvements for command_mute

PLT-4340

* Remove de.json translations

* Prevent push notifications when channel is muted

* Treat Group messages like Direct messages

* Fix unit test

* Send WS event when the channel member notify props changed
2018-03-28 07:02:04 +03:00

115 строки
4.9 KiB
Go

// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
package api
import (
"strings"
"testing"
"github.com/mattermost/mattermost-server/model"
"github.com/nicksnyder/go-i18n/i18n"
)
func TestMuteCommand(t *testing.T) {
th := Setup().InitBasic()
defer th.TearDown()
i18n.MustLoadTranslationFile("../i18n/en.json")
T, _ := i18n.Tfunc("en")
// Create client and users
Client := th.BasicClient
team := th.BasicTeam
user1 := Client.Must(Client.GetMe("")).Data.(*model.User)
user2 := th.BasicUser2
// Mute channel1 directly with '/mute'
channel1 := &model.Channel{DisplayName: "AA", Name: "aa" + model.NewId() + "a", Type: model.CHANNEL_OPEN, TeamId: team.Id}
channel1 = Client.Must(Client.CreateChannel(channel1)).Data.(*model.Channel)
Client.Must(Client.JoinChannel(channel1.Id))
channel1M := Client.Must(Client.GetChannelMember(channel1.Id, user1.Id)).Data.(*model.ChannelMember)
if channel1M.NotifyProps[model.MARK_UNREAD_NOTIFY_PROP] == model.CHANNEL_NOTIFY_MENTION {
t.Fatal("channel shouldn't be muted on initial setup")
}
rs := Client.Must(Client.Command(channel1.Id, "/mute")).Data.(*model.CommandResponse)
if !strings.EqualFold(rs.Text, T("api.command_mute.success_mute", map[string]interface{}{"Channel": channel1.DisplayName})) {
t.Fatal("failed to mute channel")
}
channel1M = Client.Must(Client.GetChannelMember(channel1.Id, user1.Id)).Data.(*model.ChannelMember)
if channel1M.NotifyProps[model.MARK_UNREAD_NOTIFY_PROP] == model.CHANNEL_NOTIFY_ALL {
t.Fatal("channel should be muted")
}
rs = Client.Must(Client.Command(channel1.Id, "/mute")).Data.(*model.CommandResponse)
if !strings.EqualFold(rs.Text, T("api.command_mute.success_unmute", map[string]interface{}{"Channel": channel1.DisplayName})) {
t.Fatal("failed to mute channel")
}
channel1M = Client.Must(Client.GetChannelMember(channel1.Id, user1.Id)).Data.(*model.ChannelMember)
if channel1M.NotifyProps[model.MARK_UNREAD_NOTIFY_PROP] == model.CHANNEL_NOTIFY_MENTION {
t.Fatal("channel shouldn't be muted anymore")
}
// Mute channel2 via channel1 with chan-handle '/mute ~aa'
channel2 := &model.Channel{DisplayName: "BB", Name: "bb" + model.NewId() + "a", Type: model.CHANNEL_PRIVATE, TeamId: team.Id}
channel2 = Client.Must(Client.CreateChannel(channel2)).Data.(*model.Channel)
Client.Must(Client.JoinChannel(channel2.Id))
Client.Must(Client.AddChannelMember(channel2.Id, user2.Id))
channel2M := Client.Must(Client.GetChannelMember(channel2.Id, user1.Id)).Data.(*model.ChannelMember)
if channel2M.NotifyProps[model.MARK_UNREAD_NOTIFY_PROP] == model.CHANNEL_NOTIFY_MENTION {
t.Fatal("channel shouldn't be muted on initial setup")
}
rs = Client.Must(Client.Command(channel1.Id, "/mute ~" + channel2.Name)).Data.(*model.CommandResponse)
if !strings.EqualFold(rs.Text, T("api.command_mute.success_mute", map[string]interface{}{"Channel": channel2.DisplayName})) {
t.Fatal("failed to mute channel")
}
channel2M = Client.Must(Client.GetChannelMember(channel2.Id, user1.Id)).Data.(*model.ChannelMember)
if channel2M.NotifyProps[model.MARK_UNREAD_NOTIFY_PROP] == model.CHANNEL_NOTIFY_ALL {
t.Fatal("channel should be muted")
}
rs = Client.Must(Client.Command(channel1.Id, "/mute ~" + channel2.Name)).Data.(*model.CommandResponse)
if !strings.EqualFold(rs.Text, T("api.command_mute.success_unmute", map[string]interface{}{"Channel": channel2.DisplayName})) {
t.Fatal("failed to mute channel")
}
channel2M = Client.Must(Client.GetChannelMember(channel2.Id, user1.Id)).Data.(*model.ChannelMember)
if channel2M.NotifyProps[model.MARK_UNREAD_NOTIFY_PROP] == model.CHANNEL_NOTIFY_MENTION {
t.Fatal("channel shouldn't be muted anymore")
}
// Mute direct message
channel3 := Client.Must(Client.CreateDirectChannel(user2.Id)).Data.(*model.Channel)
channel3M := Client.Must(Client.GetChannelMember(channel3.Id, user1.Id)).Data.(*model.ChannelMember)
if channel3M.NotifyProps[model.MARK_UNREAD_NOTIFY_PROP] == model.CHANNEL_NOTIFY_MENTION {
t.Fatal("channel shouldn't be muted on initial setup")
}
rs = Client.Must(Client.Command(channel3.Id, "/mute")).Data.(*model.CommandResponse)
if !strings.EqualFold(rs.Text, T("api.command_mute.success_mute_direct_msg")) {
t.Fatal("failed to mute channel")
}
channel3M = Client.Must(Client.GetChannelMember(channel3.Id, user1.Id)).Data.(*model.ChannelMember)
if channel3M.NotifyProps[model.MARK_UNREAD_NOTIFY_PROP] == model.CHANNEL_NOTIFY_ALL {
t.Fatal("channel should be muted")
}
rs = Client.Must(Client.Command(channel3.Id, "/mute")).Data.(*model.CommandResponse)
if !strings.EqualFold(rs.Text, T("api.command_mute.success_unmute_direct_msg")) {
t.Fatal("failed to mute channel")
}
channel3M = Client.Must(Client.GetChannelMember(channel3.Id, user1.Id)).Data.(*model.ChannelMember)
if channel3M.NotifyProps[model.MARK_UNREAD_NOTIFY_PROP] == model.CHANNEL_NOTIFY_MENTION {
t.Fatal("channel shouldn't be muted anymore")
}
}