summaryrefslogtreecommitdiffstats
path: root/app/command_invite_test.go
diff options
context:
space:
mode:
authorCarlos Tadeu Panato Junior <ctadeu@gmail.com>2018-04-16 14:23:58 +0200
committerJesús Espino <jespinog@gmail.com>2018-04-16 14:23:58 +0200
commitbf24f51c4e1cc6286885460672f7f449e8c6f5ef (patch)
tree147773b452dd017451dcc63f3f752b82d5c7694a /app/command_invite_test.go
parent0759cf639d1872680c9fc204cdef91cb784fac72 (diff)
downloadchat-bf24f51c4e1cc6286885460672f7f449e8c6f5ef.tar.gz
chat-bf24f51c4e1cc6286885460672f7f449e8c6f5ef.tar.bz2
chat-bf24f51c4e1cc6286885460672f7f449e8c6f5ef.zip
[MM-9904] Add /invite slash command to invite users to a channel (#8482)
* [MM-9904] Add /invite slash command to invite users to a channel * Update en.json
Diffstat (limited to 'app/command_invite_test.go')
-rw-r--r--app/command_invite_test.go108
1 files changed, 108 insertions, 0 deletions
diff --git a/app/command_invite_test.go b/app/command_invite_test.go
new file mode 100644
index 000000000..c46bc4628
--- /dev/null
+++ b/app/command_invite_test.go
@@ -0,0 +1,108 @@
+// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
+// See License.txt for license information.
+
+package app
+
+import (
+ "testing"
+
+ "github.com/stretchr/testify/assert"
+
+ "github.com/mattermost/mattermost-server/model"
+)
+
+func TestInviteProvider(t *testing.T) {
+ th := Setup().InitBasic()
+ defer th.TearDown()
+
+ channel := th.createChannel(th.BasicTeam, model.CHANNEL_OPEN)
+ privateChannel := th.createChannel(th.BasicTeam, model.CHANNEL_PRIVATE)
+ dmChannel := th.CreateDmChannel(th.BasicUser2)
+
+ basicUser3 := th.CreateUser()
+ th.LinkUserToTeam(basicUser3, th.BasicTeam)
+ basicUser4 := th.CreateUser()
+
+ InviteP := InviteProvider{}
+ args := &model.CommandArgs{
+ T: func(s string, args ...interface{}) string { return s },
+ ChannelId: th.BasicChannel.Id,
+ TeamId: th.BasicTeam.Id,
+ Session: model.Session{UserId: th.BasicUser.Id, TeamMembers: []*model.TeamMember{{TeamId: th.BasicTeam.Id, Roles: model.TEAM_USER_ROLE_ID}}},
+ }
+
+ userAndWrongChannel := "@" + th.BasicUser2.Username + " wrongchannel1"
+ userAndChannel := "@" + th.BasicUser2.Username + " ~" + channel.Name + " "
+ userAndDisplayChannel := "@" + th.BasicUser2.Username + " ~" + channel.DisplayName + " "
+ userAndPrivateChannel := "@" + th.BasicUser2.Username + " ~" + privateChannel.Name
+ userAndDMChannel := "@" + basicUser3.Username + " ~" + dmChannel.Name
+
+ tests := []struct {
+ desc string
+ expected string
+ msg string
+ }{
+ {
+ desc: "Missing user and channel in the command",
+ expected: "api.command_invite.missing_message.app_error",
+ msg: "",
+ },
+ {
+ desc: "User added in the current channel",
+ expected: "",
+ msg: th.BasicUser2.Username,
+ },
+ {
+ desc: "Add user to another channel not the current",
+ expected: "api.command_invite.success",
+ msg: userAndChannel,
+ },
+ {
+ desc: "try to add a user to a direct channel",
+ expected: "api.command_invite.directchannel.app_error",
+ msg: userAndDMChannel,
+ },
+ {
+ desc: "Try to add a user to a invalid channel",
+ expected: "api.command_invite.channel.error",
+ msg: userAndWrongChannel,
+ },
+ {
+ desc: "Try to add a user to an private channel",
+ expected: "api.command_invite.success",
+ msg: userAndPrivateChannel,
+ },
+ {
+ desc: "Using display channel name which is different form Channel name",
+ expected: "api.command_invite.channel.error",
+ msg: userAndDisplayChannel,
+ },
+ {
+ desc: "Invalid user to current channel",
+ expected: "api.command_invite.missing_user.app_error",
+ msg: "@invalidUser123",
+ },
+ {
+ desc: "Invalid user to current channel without @",
+ expected: "api.command_invite.missing_user.app_error",
+ msg: "invalidUser321",
+ },
+ {
+ desc: "try to add a user which is not part of the team",
+ expected: "api.command_invite.fail.app_error",
+ msg: basicUser4.Username,
+ },
+ {
+ desc: "try to add a user to a direct channel",
+ expected: "api.command_invite.directchannel.app_error",
+ msg: userAndDMChannel,
+ },
+ }
+
+ for _, test := range tests {
+ t.Run(test.desc, func(t *testing.T) {
+ actual := InviteP.DoCommand(th.App, args, test.msg).Text
+ assert.Equal(t, test.expected, actual)
+ })
+ }
+}