summaryrefslogtreecommitdiffstats
path: root/api4/channel_test.go
diff options
context:
space:
mode:
authorSaturnino Abril <saturnino.abril@gmail.com>2017-03-20 21:44:08 +0900
committerGeorge Goldberg <george@gberg.me>2017-03-20 12:44:08 +0000
commit7e89077a93fd187284e426db503a4ab5cbcdf248 (patch)
tree9f2790d73c238b7d57eff7f6317c30e594bfa141 /api4/channel_test.go
parentac8282cda1455802f52ebe6687eeeef6c950bf49 (diff)
downloadchat-7e89077a93fd187284e426db503a4ab5cbcdf248.tar.gz
chat-7e89077a93fd187284e426db503a4ab5cbcdf248.tar.bz2
chat-7e89077a93fd187284e426db503a4ab5cbcdf248.zip
Endpoint for APIv4 POST /channels/{channel_id}/members (#5775)
Diffstat (limited to 'api4/channel_test.go')
-rw-r--r--api4/channel_test.go88
1 files changed, 88 insertions, 0 deletions
diff --git a/api4/channel_test.go b/api4/channel_test.go
index 6d5b5cef3..fd72a8ba7 100644
--- a/api4/channel_test.go
+++ b/api4/channel_test.go
@@ -1118,6 +1118,94 @@ func TestUpdateChannelRoles(t *testing.T) {
CheckForbiddenStatus(t, resp)
}
+func TestAddChannelMember(t *testing.T) {
+ th := Setup().InitBasic().InitSystemAdmin()
+ defer TearDown()
+ Client := th.Client
+ user := th.BasicUser
+ user2 := th.BasicUser2
+ publicChannel := th.CreatePublicChannel()
+ privateChannel := th.CreatePrivateChannel()
+
+ cm, resp := Client.AddChannelMember(publicChannel.Id, user2.Id)
+ CheckNoError(t, resp)
+
+ if cm.ChannelId != publicChannel.Id {
+ t.Fatal("should have returned exact channel")
+ }
+
+ if cm.UserId != user2.Id {
+ t.Fatal("should have returned exact user added to public channel")
+ }
+
+ cm, resp = Client.AddChannelMember(privateChannel.Id, user2.Id)
+ CheckNoError(t, resp)
+
+ if cm.ChannelId != privateChannel.Id {
+ t.Fatal("should have returned exact channel")
+ }
+
+ if cm.UserId != user2.Id {
+ t.Fatal("should have returned exact user added to private channel")
+ }
+
+ cm, resp = Client.AddChannelMember(publicChannel.Id, "junk")
+ CheckBadRequestStatus(t, resp)
+
+ if cm != nil {
+ t.Fatal("should return nothing")
+ }
+
+ _, resp = Client.AddChannelMember(publicChannel.Id, GenerateTestId())
+ CheckNotFoundStatus(t, resp)
+
+ _, resp = Client.AddChannelMember("junk", user2.Id)
+ CheckBadRequestStatus(t, resp)
+
+ _, resp = Client.AddChannelMember(GenerateTestId(), user2.Id)
+ CheckNotFoundStatus(t, resp)
+
+ otherUser := th.CreateUser()
+ otherChannel := th.CreatePublicChannel()
+ Client.Logout()
+ Client.Login(user2.Id, user2.Password)
+
+ _, resp = Client.AddChannelMember(publicChannel.Id, otherUser.Id)
+ CheckUnauthorizedStatus(t, resp)
+
+ _, resp = Client.AddChannelMember(privateChannel.Id, otherUser.Id)
+ CheckUnauthorizedStatus(t, resp)
+
+ _, resp = Client.AddChannelMember(otherChannel.Id, otherUser.Id)
+ CheckUnauthorizedStatus(t, resp)
+
+ Client.Logout()
+ Client.Login(user.Id, user.Password)
+
+ // should fail adding user who is not a member of the team
+ _, resp = Client.AddChannelMember(otherChannel.Id, otherUser.Id)
+ CheckUnauthorizedStatus(t, resp)
+
+ Client.DeleteChannel(otherChannel.Id)
+
+ // should fail adding user to a deleted channel
+ _, resp = Client.AddChannelMember(otherChannel.Id, user2.Id)
+ CheckUnauthorizedStatus(t, resp)
+
+ Client.Logout()
+ _, resp = Client.AddChannelMember(publicChannel.Id, user2.Id)
+ CheckUnauthorizedStatus(t, resp)
+
+ _, resp = Client.AddChannelMember(privateChannel.Id, user2.Id)
+ CheckUnauthorizedStatus(t, resp)
+
+ _, resp = th.SystemAdminClient.AddChannelMember(publicChannel.Id, user2.Id)
+ CheckNoError(t, resp)
+
+ _, resp = th.SystemAdminClient.AddChannelMember(privateChannel.Id, user2.Id)
+ CheckNoError(t, resp)
+}
+
func TestRemoveChannelMember(t *testing.T) {
th := Setup().InitBasic().InitSystemAdmin()
defer TearDown()