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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
|
// Copyright (c) 2018-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
package app
import (
"testing"
"time"
"github.com/mattermost/mattermost-server/model"
"github.com/nicksnyder/go-i18n/i18n"
"github.com/stretchr/testify/assert"
)
func TestMuteCommandNoChannel(t *testing.T) {
th := Setup().InitBasic()
defer th.TearDown()
if testing.Short() {
t.SkipNow()
}
channel1 := th.BasicChannel
channel1M, channel1MError := th.App.GetChannelMember(channel1.Id, th.BasicUser.Id)
if channel1MError != nil {
t.Fatal("User is not a member of channel 1")
}
if channel1M.NotifyProps[model.MARK_UNREAD_NOTIFY_PROP] == model.CHANNEL_NOTIFY_MENTION {
t.Fatal("channel shouldn't be muted on initial setup")
}
cmd := &MuteProvider{}
resp := cmd.DoCommand(th.App, &model.CommandArgs{
T: i18n.IdentityTfunc(),
UserId: th.BasicUser.Id,
}, "")
assert.Equal(t, "api.command_mute.no_channel.error", resp.Text)
}
func TestMuteCommandNoArgs(t *testing.T) {
th := Setup().InitBasic()
defer th.TearDown()
channel1 := th.BasicChannel
channel1M, _ := th.App.GetChannelMember(channel1.Id, th.BasicUser.Id)
assert.Equal(t, model.CHANNEL_NOTIFY_ALL, channel1M.NotifyProps[model.MARK_UNREAD_NOTIFY_PROP])
cmd := &MuteProvider{}
// First mute the channel
resp := cmd.DoCommand(th.App, &model.CommandArgs{
T: i18n.IdentityTfunc(),
ChannelId: channel1.Id,
UserId: th.BasicUser.Id,
}, "")
assert.Equal(t, "api.command_mute.success_mute", resp.Text)
// Now unmute the channel
time.Sleep(time.Millisecond)
resp = cmd.DoCommand(th.App, &model.CommandArgs{
T: i18n.IdentityTfunc(),
ChannelId: channel1.Id,
UserId: th.BasicUser.Id,
}, "")
assert.Equal(t, "api.command_mute.success_unmute", resp.Text)
}
func TestMuteCommandSpecificChannel(t *testing.T) {
th := Setup().InitBasic()
defer th.TearDown()
if testing.Short() {
t.SkipNow()
}
channel1 := th.BasicChannel
channel2, _ := th.App.CreateChannel(&model.Channel{
DisplayName: "AA",
Name: "aa" + model.NewId() + "a",
Type: model.CHANNEL_OPEN,
TeamId: th.BasicTeam.Id,
CreatorId: th.BasicUser.Id,
}, true)
channel2M, _ := th.App.GetChannelMember(channel2.Id, th.BasicUser.Id)
assert.Equal(t, model.CHANNEL_NOTIFY_ALL, channel2M.NotifyProps[model.MARK_UNREAD_NOTIFY_PROP])
cmd := &MuteProvider{}
// First mute the channel
resp := cmd.DoCommand(th.App, &model.CommandArgs{
T: i18n.IdentityTfunc(),
ChannelId: channel1.Id,
UserId: th.BasicUser.Id,
}, channel2.Name)
assert.Equal(t, "api.command_mute.success_mute", resp.Text)
time.Sleep(time.Millisecond)
channel2M, _ = th.App.GetChannelMember(channel2.Id, th.BasicUser.Id)
assert.Equal(t, model.CHANNEL_NOTIFY_MENTION, channel2M.NotifyProps[model.MARK_UNREAD_NOTIFY_PROP])
// Now unmute the channel
resp = cmd.DoCommand(th.App, &model.CommandArgs{
T: i18n.IdentityTfunc(),
ChannelId: channel1.Id,
UserId: th.BasicUser.Id,
}, "~"+channel2.Name)
assert.Equal(t, "api.command_mute.success_unmute", resp.Text)
time.Sleep(time.Millisecond)
channel2M, _ = th.App.GetChannelMember(channel2.Id, th.BasicUser.Id)
assert.Equal(t, model.CHANNEL_NOTIFY_ALL, channel2M.NotifyProps[model.MARK_UNREAD_NOTIFY_PROP])
}
func TestMuteCommandNotMember(t *testing.T) {
th := Setup().InitBasic()
defer th.TearDown()
if testing.Short() {
t.SkipNow()
}
channel1 := th.BasicChannel
channel2, _ := th.App.CreateChannel(&model.Channel{
DisplayName: "AA",
Name: "aa" + model.NewId() + "a",
Type: model.CHANNEL_OPEN,
TeamId: th.BasicTeam.Id,
CreatorId: th.BasicUser.Id,
}, false)
cmd := &MuteProvider{}
// First mute the channel
resp := cmd.DoCommand(th.App, &model.CommandArgs{
T: i18n.IdentityTfunc(),
ChannelId: channel1.Id,
UserId: th.BasicUser.Id,
}, channel2.Name)
assert.Equal(t, "api.command_mute.not_member.error", resp.Text)
}
func TestMuteCommandNotChannel(t *testing.T) {
th := Setup().InitBasic()
defer th.TearDown()
if testing.Short() {
t.SkipNow()
}
channel1 := th.BasicChannel
cmd := &MuteProvider{}
// First mute the channel
resp := cmd.DoCommand(th.App, &model.CommandArgs{
T: i18n.IdentityTfunc(),
ChannelId: channel1.Id,
UserId: th.BasicUser.Id,
}, "~noexists")
assert.Equal(t, "api.command_mute.error", resp.Text)
}
func TestMuteCommandDMChannel(t *testing.T) {
th := Setup().InitBasic()
defer th.TearDown()
if testing.Short() {
t.SkipNow()
}
channel2, _ := th.App.CreateDirectChannel(th.BasicUser.Id, th.BasicUser2.Id)
channel2M, _ := th.App.GetChannelMember(channel2.Id, th.BasicUser.Id)
assert.Equal(t, model.CHANNEL_NOTIFY_ALL, channel2M.NotifyProps[model.MARK_UNREAD_NOTIFY_PROP])
cmd := &MuteProvider{}
// First mute the channel
resp := cmd.DoCommand(th.App, &model.CommandArgs{
T: i18n.IdentityTfunc(),
ChannelId: channel2.Id,
UserId: th.BasicUser.Id,
}, "")
assert.Equal(t, "api.command_mute.success_mute_direct_msg", resp.Text)
time.Sleep(time.Millisecond)
channel2M, _ = th.App.GetChannelMember(channel2.Id, th.BasicUser.Id)
assert.Equal(t, model.CHANNEL_NOTIFY_MENTION, channel2M.NotifyProps[model.MARK_UNREAD_NOTIFY_PROP])
// Now unmute the channel
resp = cmd.DoCommand(th.App, &model.CommandArgs{
T: i18n.IdentityTfunc(),
ChannelId: channel2.Id,
UserId: th.BasicUser.Id,
}, "")
assert.Equal(t, "api.command_mute.success_unmute_direct_msg", resp.Text)
time.Sleep(time.Millisecond)
channel2M, _ = th.App.GetChannelMember(channel2.Id, th.BasicUser.Id)
assert.Equal(t, model.CHANNEL_NOTIFY_ALL, channel2M.NotifyProps[model.MARK_UNREAD_NOTIFY_PROP])
}
|