diff options
author | George Goldberg <george@gberg.me> | 2018-07-10 09:54:49 +0100 |
---|---|---|
committer | Carlos Tadeu Panato Junior <ctadeu@gmail.com> | 2018-07-10 10:54:49 +0200 |
commit | 2df818b9c680d9e6aec2cddb4c910ecf8341e3a9 (patch) | |
tree | b460265f1d3f2317321778f38ebc81e567caf87e /app/command_groupmsg_test.go | |
parent | 74e5d8ae66186a82e8afdd845a108d6a662751d7 (diff) | |
download | chat-2df818b9c680d9e6aec2cddb4c910ecf8341e3a9.tar.gz chat-2df818b9c680d9e6aec2cddb4c910ecf8341e3a9.tar.bz2 chat-2df818b9c680d9e6aec2cddb4c910ecf8341e3a9.zip |
MM-11227: Fix group msg slash command. (#9070)
Diffstat (limited to 'app/command_groupmsg_test.go')
-rw-r--r-- | app/command_groupmsg_test.go | 60 |
1 files changed, 60 insertions, 0 deletions
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) +} |