1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
// 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")
}
}
|