github.com/jlevesy/mattermost-server@v5.3.2-0.20181003190404-7468f35cb0c8+incompatible/app/command_channel_rename_test.go (about) 1 // Copyright (c) 2015-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/stretchr/testify/assert" 10 11 "github.com/mattermost/mattermost-server/model" 12 ) 13 14 func TestRenameProviderDoCommand(t *testing.T) { 15 th := Setup().InitBasic() 16 defer th.TearDown() 17 18 rp := RenameProvider{} 19 args := &model.CommandArgs{ 20 T: func(s string, args ...interface{}) string { return s }, 21 ChannelId: th.BasicChannel.Id, 22 Session: model.Session{UserId: th.BasicUser.Id, TeamMembers: []*model.TeamMember{{TeamId: th.BasicTeam.Id, Roles: model.TEAM_USER_ROLE_ID}}}, 23 } 24 25 // Blank text is a success 26 for msg, expected := range map[string]string{ 27 "": "api.command_channel_rename.message.app_error", 28 "o": "api.command_channel_rename.too_short.app_error", 29 "joram": "", 30 "1234567890123456789012": "", 31 "12345678901234567890123": "api.command_channel_rename.too_long.app_error", 32 } { 33 actual := rp.DoCommand(th.App, args, msg).Text 34 assert.Equal(t, expected, actual) 35 } 36 37 // Try a public channel *without* permission. 38 args = &model.CommandArgs{ 39 T: func(s string, args ...interface{}) string { return s }, 40 ChannelId: th.BasicChannel.Id, 41 Session: model.Session{UserId: th.BasicUser.Id, TeamMembers: []*model.TeamMember{{TeamId: th.BasicTeam.Id, Roles: ""}}}, 42 } 43 44 actual := rp.DoCommand(th.App, args, "hello").Text 45 assert.Equal(t, "api.command_channel_rename.permission.app_error", actual) 46 47 // Try a private channel *with* permission. 48 privateChannel := th.CreatePrivateChannel(th.BasicTeam) 49 50 args = &model.CommandArgs{ 51 T: func(s string, args ...interface{}) string { return s }, 52 ChannelId: privateChannel.Id, 53 Session: model.Session{UserId: th.BasicUser.Id, TeamMembers: []*model.TeamMember{{TeamId: th.BasicTeam.Id, Roles: model.TEAM_USER_ROLE_ID}}}, 54 } 55 56 actual = rp.DoCommand(th.App, args, "hello").Text 57 assert.Equal(t, "", actual) 58 59 // Try a private channel *without* permission. 60 args = &model.CommandArgs{ 61 T: func(s string, args ...interface{}) string { return s }, 62 ChannelId: privateChannel.Id, 63 Session: model.Session{UserId: th.BasicUser.Id, TeamMembers: []*model.TeamMember{{TeamId: th.BasicTeam.Id, Roles: ""}}}, 64 } 65 66 actual = rp.DoCommand(th.App, args, "hello").Text 67 assert.Equal(t, "api.command_channel_rename.permission.app_error", actual) 68 69 // Try a group channel *with* being a member. 70 user1 := th.CreateUser() 71 user2 := th.CreateUser() 72 73 groupChannel := th.CreateGroupChannel(user1, user2) 74 75 args = &model.CommandArgs{ 76 T: func(s string, args ...interface{}) string { return s }, 77 ChannelId: groupChannel.Id, 78 Session: model.Session{UserId: th.BasicUser.Id, TeamMembers: []*model.TeamMember{{TeamId: th.BasicTeam.Id, Roles: ""}}}, 79 } 80 81 actual = rp.DoCommand(th.App, args, "hello").Text 82 assert.Equal(t, "api.command_channel_rename.direct_group.app_error", actual) 83 84 // Try a direct channel *with* being a member. 85 directChannel := th.CreateDmChannel(user1) 86 87 args = &model.CommandArgs{ 88 T: func(s string, args ...interface{}) string { return s }, 89 ChannelId: directChannel.Id, 90 Session: model.Session{UserId: th.BasicUser.Id, TeamMembers: []*model.TeamMember{{TeamId: th.BasicTeam.Id, Roles: ""}}}, 91 } 92 93 actual = rp.DoCommand(th.App, args, "hello").Text 94 assert.Equal(t, "api.command_channel_rename.direct_group.app_error", actual) 95 }