From 2df818b9c680d9e6aec2cddb4c910ecf8341e3a9 Mon Sep 17 00:00:00 2001 From: George Goldberg Date: Tue, 10 Jul 2018 09:54:49 +0100 Subject: MM-11227: Fix group msg slash command. (#9070) --- app/command_groupmsg_test.go | 60 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) (limited to 'app/command_groupmsg_test.go') diff --git a/app/command_groupmsg_test.go b/app/command_groupmsg_test.go index 610d2e446..422679525 100644 --- a/app/command_groupmsg_test.go +++ b/app/command_groupmsg_test.go @@ -2,6 +2,11 @@ package app import ( "testing" + + "github.com/nicksnyder/go-i18n/i18n" + "github.com/stretchr/testify/assert" + + "github.com/mattermost/mattermost-server/model" ) func TestGroupMsgUsernames(t *testing.T) { @@ -35,3 +40,58 @@ func TestGroupMsgUsernames(t *testing.T) { t.Fatal("error parsing different types of users") } } + +func TestGroupMsgProvider(t *testing.T) { + th := Setup().InitBasic() + defer th.TearDown() + + user3 := th.CreateUser() + targetUsers := "@" + th.BasicUser2.Username + ",@" + user3.Username + " " + + team := th.CreateTeam() + th.LinkUserToTeam(th.BasicUser, team) + cmd := &groupmsgProvider{} + + // Check without permission to create a GM channel. + resp := cmd.DoCommand(th.App, &model.CommandArgs{ + T: i18n.IdentityTfunc(), + SiteURL: "http://test.url", + TeamId: team.Id, + UserId: th.BasicUser.Id, + Session: model.Session{ + Roles: "", + }, + }, targetUsers+"hello") + + channelName := model.GetGroupNameFromUserIds([]string{th.BasicUser.Id, th.BasicUser2.Id, user3.Id}) + assert.Equal(t, "api.command_groupmsg.permission.app_error", resp.Text) + assert.Equal(t, "", resp.GotoLocation) + + // Check with permission to create a GM channel. + resp = cmd.DoCommand(th.App, &model.CommandArgs{ + T: i18n.IdentityTfunc(), + SiteURL: "http://test.url", + TeamId: team.Id, + UserId: th.BasicUser.Id, + Session: model.Session{ + Roles: model.SYSTEM_USER_ROLE_ID, + }, + }, targetUsers+"hello") + + assert.Equal(t, "", resp.Text) + assert.Equal(t, "http://test.url/"+team.Name+"/channels/"+channelName, resp.GotoLocation) + + // Check without permission to post to an existing GM channel. + resp = cmd.DoCommand(th.App, &model.CommandArgs{ + T: i18n.IdentityTfunc(), + SiteURL: "http://test.url", + TeamId: team.Id, + UserId: th.BasicUser.Id, + Session: model.Session{ + Roles: "", + }, + }, targetUsers+"hello") + + assert.Equal(t, "", resp.Text) + assert.Equal(t, "http://test.url/"+team.Name+"/channels/"+channelName, resp.GotoLocation) +} -- cgit v1.2.3-1-g7c22