github.com/jlevesy/mattermost-server@v5.3.2-0.20181003190404-7468f35cb0c8+incompatible/app/command_msg_test.go (about) 1 // Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved. 2 // See License.txt for license information. 3 4 package app 5 6 import ( 7 "testing" 8 9 "github.com/nicksnyder/go-i18n/i18n" 10 "github.com/stretchr/testify/assert" 11 12 "github.com/mattermost/mattermost-server/model" 13 ) 14 15 func TestMsgProvider(t *testing.T) { 16 th := Setup().InitBasic() 17 defer th.TearDown() 18 19 team := th.CreateTeam() 20 th.LinkUserToTeam(th.BasicUser, team) 21 cmd := &msgProvider{} 22 23 // Check without permission to create a DM channel. 24 resp := cmd.DoCommand(th.App, &model.CommandArgs{ 25 T: i18n.IdentityTfunc(), 26 SiteURL: "http://test.url", 27 TeamId: team.Id, 28 UserId: th.BasicUser.Id, 29 Session: model.Session{ 30 Roles: "", 31 }, 32 }, "@"+th.BasicUser2.Username+" hello") 33 34 channelName := model.GetDMNameFromIds(th.BasicUser.Id, th.BasicUser2.Id) 35 assert.Equal(t, "api.command_msg.permission.app_error", resp.Text) 36 assert.Equal(t, "", resp.GotoLocation) 37 38 // Check with permission to create a DM channel. 39 resp = cmd.DoCommand(th.App, &model.CommandArgs{ 40 T: i18n.IdentityTfunc(), 41 SiteURL: "http://test.url", 42 TeamId: team.Id, 43 UserId: th.BasicUser.Id, 44 Session: model.Session{ 45 Roles: model.SYSTEM_USER_ROLE_ID, 46 }, 47 }, "@"+th.BasicUser2.Username+" hello") 48 49 assert.Equal(t, "", resp.Text) 50 assert.Equal(t, "http://test.url/"+team.Name+"/channels/"+channelName, resp.GotoLocation) 51 52 // Check without permission to post to an existing DM channel. 53 resp = cmd.DoCommand(th.App, &model.CommandArgs{ 54 T: i18n.IdentityTfunc(), 55 SiteURL: "http://test.url", 56 TeamId: team.Id, 57 UserId: th.BasicUser.Id, 58 Session: model.Session{ 59 Roles: "", 60 }, 61 }, "@"+th.BasicUser2.Username+" hello") 62 63 assert.Equal(t, "", resp.Text) 64 assert.Equal(t, "http://test.url/"+team.Name+"/channels/"+channelName, resp.GotoLocation) 65 }