summaryrefslogtreecommitdiffstats
path: root/api/channel_test.go
diff options
context:
space:
mode:
authorGeorge Goldberg <george@gberg.me>2017-01-13 13:52:32 +0000
committerenahum <nahumhbl@gmail.com>2017-01-13 10:52:32 -0300
commit4e160c78abbc2a33ed9a329c0a62b1bfb7f411b6 (patch)
tree3c5d0f13fb8b61dbb75b72852d5501ab6c9251d1 /api/channel_test.go
parente69809dce3708b7ba28a7475c8babbb429ca601c (diff)
downloadchat-4e160c78abbc2a33ed9a329c0a62b1bfb7f411b6.tar.gz
chat-4e160c78abbc2a33ed9a329c0a62b1bfb7f411b6.tar.bz2
chat-4e160c78abbc2a33ed9a329c0a62b1bfb7f411b6.zip
PLT-5050 (Server). API to update channel member roles. (#5043)
Implements API reference proposal mattermost-api-reference:#66.
Diffstat (limited to 'api/channel_test.go')
-rw-r--r--api/channel_test.go73
1 files changed, 73 insertions, 0 deletions
diff --git a/api/channel_test.go b/api/channel_test.go
index 25fd885ca..8bfa0e896 100644
--- a/api/channel_test.go
+++ b/api/channel_test.go
@@ -1920,3 +1920,76 @@ func TestGetChannelMembersByIds(t *testing.T) {
t.Fatal("should have errored - empty user ids")
}
}
+
+func TestUpdateChannelRoles(t *testing.T) {
+ th := Setup().InitSystemAdmin().InitBasic()
+ th.SystemAdminClient.SetTeamId(th.BasicTeam.Id)
+ LinkUserToTeam(th.SystemAdminUser, th.BasicTeam)
+
+ const CHANNEL_ADMIN = "channel_admin channel_user"
+ const CHANNEL_MEMBER = "channel_user"
+
+ // User 1 creates a channel, making them channel admin by default.
+ createChannel := model.Channel{
+ DisplayName: "Test API Name",
+ Name: "a" + model.NewId() + "a",
+ Type: model.CHANNEL_OPEN,
+ TeamId: th.BasicTeam.Id,
+ }
+
+ rchannel, err := th.BasicClient.CreateChannel(&createChannel)
+ if err != nil {
+ t.Fatal("Failed to create channel:", err)
+ }
+ channel := rchannel.Data.(*model.Channel)
+
+ // User 1 adds User 2 to the channel, making them a channel member by default.
+ if _, err := th.BasicClient.AddChannelMember(channel.Id, th.BasicUser2.Id); err != nil {
+ t.Fatal("Failed to add user 2 to the channel:", err)
+ }
+
+ // System Admin can demote User 1 (channel admin).
+ if data, meta := th.SystemAdminClient.UpdateChannelRoles(channel.Id, th.BasicUser.Id, CHANNEL_MEMBER); data == nil {
+ t.Fatal("System Admin failed to demote channel admin to channel member:", meta)
+ }
+
+ // User 1 (channel_member) cannot promote user 2 (channel_member).
+ if data, meta := th.BasicClient.UpdateChannelRoles(channel.Id, th.BasicUser2.Id, CHANNEL_ADMIN); data != nil {
+ t.Fatal("Channel member should not be able to promote another channel member to channel admin:", meta)
+ }
+
+ // System Admin can promote user 1 (channel member).
+ if data, meta := th.SystemAdminClient.UpdateChannelRoles(channel.Id, th.BasicUser.Id, CHANNEL_ADMIN); data == nil {
+ t.Fatal("System Admin failed to promote channel member to channel admin:", meta)
+ }
+
+ // User 1 (channel_admin) can promote User 2 (channel member).
+ if data, meta := th.BasicClient.UpdateChannelRoles(channel.Id, th.BasicUser2.Id, CHANNEL_ADMIN); data == nil {
+ t.Fatal("Channel admin failed to promote channel member to channel admin:", meta)
+ }
+
+ // User 1 (channel admin) can demote User 2 (channel admin).
+ if data, meta := th.BasicClient.UpdateChannelRoles(channel.Id, th.BasicUser2.Id, CHANNEL_MEMBER); data == nil {
+ t.Fatal("Channel admin failed to demote channel admin to channel member:", meta)
+ }
+
+ // User 1 (channel admin) can demote itself.
+ if data, meta := th.BasicClient.UpdateChannelRoles(channel.Id, th.BasicUser.Id, CHANNEL_MEMBER); data == nil {
+ t.Fatal("Channel admin failed to demote itself to channel member:", meta)
+ }
+
+ // Promote User2 again for next test.
+ if data, meta := th.SystemAdminClient.UpdateChannelRoles(channel.Id, th.BasicUser2.Id, CHANNEL_ADMIN); data == nil {
+ t.Fatal("System Admin failed to promote channel member to channel admin:", meta)
+ }
+
+ // User 1 (channel member) cannot demote user 2 (channel admin).
+ if data, meta := th.BasicClient.UpdateChannelRoles(channel.Id, th.BasicUser2.Id, CHANNEL_MEMBER); data != nil {
+ t.Fatal("Channel member should not be able to demote another channel admin to channel member:", meta)
+ }
+
+ // User 1 (channel member) cannot promote itself.
+ if data, meta := th.BasicClient.UpdateChannelRoles(channel.Id, th.BasicUser.Id, CHANNEL_ADMIN); data != nil {
+ t.Fatal("Channel member should not be able to promote itself to channel admin:", meta)
+ }
+}