Files
mattermost/app/command_channel_rename_test.go
Jesús Espino a63684fcb5 Consistent license message for all the go files (#13235)
* Consistent license message for all the go files

* Fixing the last set of unconsistencies with the license headers

* Addressing PR review comments

* Fixing busy.go and busy_test.go license header
2019-11-29 12:59:40 +01:00

105 lines
4.0 KiB
Go

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package app
import (
"strings"
"testing"
"github.com/stretchr/testify/assert"
"github.com/mattermost/mattermost-server/v5/model"
)
func TestRenameProviderDoCommand(t *testing.T) {
th := Setup(t).InitBasic()
defer th.TearDown()
th.AddPermissionToRole(model.PERMISSION_MANAGE_PUBLIC_CHANNEL_PROPERTIES.Id, model.CHANNEL_USER_ROLE_ID)
rp := RenameProvider{}
args := &model.CommandArgs{
T: func(s string, args ...interface{}) string { return s },
ChannelId: th.BasicChannel.Id,
Session: model.Session{UserId: th.BasicUser.Id, TeamMembers: []*model.TeamMember{{TeamId: th.BasicTeam.Id, Roles: model.TEAM_USER_ROLE_ID}}},
}
// Table Test for basic cases. Blank text in response indicates success
for msg, expected := range map[string]string{
"": "api.command_channel_rename.message.app_error",
"o": "api.command_channel_rename.too_short.app_error",
"joram": "",
"More than 22 chars but less than 64": "",
strings.Repeat("12345", 13): "api.command_channel_rename.too_long.app_error",
} {
actual := rp.DoCommand(th.App, args, msg).Text
assert.Equal(t, expected, actual)
}
// Try a public channel *without* permission.
th.RemovePermissionFromRole(model.PERMISSION_MANAGE_PUBLIC_CHANNEL_PROPERTIES.Id, model.CHANNEL_USER_ROLE_ID)
args = &model.CommandArgs{
T: func(s string, args ...interface{}) string { return s },
ChannelId: th.BasicChannel.Id,
Session: model.Session{UserId: th.BasicUser.Id, TeamMembers: []*model.TeamMember{{TeamId: th.BasicTeam.Id, Roles: model.TEAM_USER_ROLE_ID}}},
}
actual := rp.DoCommand(th.App, args, "hello").Text
assert.Equal(t, "api.command_channel_rename.permission.app_error", actual)
// Try a private channel *with* permission.
privateChannel := th.CreatePrivateChannel(th.BasicTeam)
th.AddPermissionToRole(model.PERMISSION_MANAGE_PRIVATE_CHANNEL_PROPERTIES.Id, model.CHANNEL_USER_ROLE_ID)
args = &model.CommandArgs{
T: func(s string, args ...interface{}) string { return s },
ChannelId: privateChannel.Id,
Session: model.Session{UserId: th.BasicUser.Id, TeamMembers: []*model.TeamMember{{TeamId: th.BasicTeam.Id, Roles: model.TEAM_USER_ROLE_ID}}},
}
actual = rp.DoCommand(th.App, args, "hello").Text
assert.Equal(t, "", actual)
// Try a private channel *without* permission.
th.RemovePermissionFromRole(model.PERMISSION_MANAGE_PRIVATE_CHANNEL_PROPERTIES.Id, model.CHANNEL_USER_ROLE_ID)
args = &model.CommandArgs{
T: func(s string, args ...interface{}) string { return s },
ChannelId: privateChannel.Id,
Session: model.Session{UserId: th.BasicUser.Id, TeamMembers: []*model.TeamMember{{TeamId: th.BasicTeam.Id, Roles: model.TEAM_USER_ROLE_ID}}},
}
actual = rp.DoCommand(th.App, args, "hello").Text
assert.Equal(t, "api.command_channel_rename.permission.app_error", actual)
// Try a group channel *with* being a member.
user1 := th.CreateUser()
user2 := th.CreateUser()
groupChannel := th.CreateGroupChannel(user1, user2)
args = &model.CommandArgs{
T: func(s string, args ...interface{}) string { return s },
ChannelId: groupChannel.Id,
Session: model.Session{UserId: th.BasicUser.Id, TeamMembers: []*model.TeamMember{{TeamId: th.BasicTeam.Id, Roles: model.TEAM_USER_ROLE_ID}}},
}
actual = rp.DoCommand(th.App, args, "hello").Text
assert.Equal(t, "api.command_channel_rename.direct_group.app_error", actual)
// Try a direct channel *with* being a member.
directChannel := th.CreateDmChannel(user1)
args = &model.CommandArgs{
T: func(s string, args ...interface{}) string { return s },
ChannelId: directChannel.Id,
Session: model.Session{UserId: th.BasicUser.Id, TeamMembers: []*model.TeamMember{{TeamId: th.BasicTeam.Id, Roles: model.TEAM_USER_ROLE_ID}}},
}
actual = rp.DoCommand(th.App, args, "hello").Text
assert.Equal(t, "api.command_channel_rename.direct_group.app_error", actual)
}