summaryrefslogtreecommitdiffstats
path: root/api4/channel_test.go
diff options
context:
space:
mode:
authorJoram Wilander <jwawilander@gmail.com>2017-03-16 14:58:33 -0400
committerCorey Hulen <corey@hulen.com>2017-03-16 11:58:33 -0700
commitd757645c2490dd4f0de16cc32e05551b1476d0a0 (patch)
tree5d6e4049aa296b7629a34ca5b02d0aba25dd27dc /api4/channel_test.go
parent04c0223c6402b12e67c61474ae310b0a56af6482 (diff)
downloadchat-d757645c2490dd4f0de16cc32e05551b1476d0a0.tar.gz
chat-d757645c2490dd4f0de16cc32e05551b1476d0a0.tar.bz2
chat-d757645c2490dd4f0de16cc32e05551b1476d0a0.zip
Implement some channel endpoints for APIv4 (#5767)
Diffstat (limited to 'api4/channel_test.go')
-rw-r--r--api4/channel_test.go125
1 files changed, 125 insertions, 0 deletions
diff --git a/api4/channel_test.go b/api4/channel_test.go
index 97364a73e..bf7218f0b 100644
--- a/api4/channel_test.go
+++ b/api4/channel_test.go
@@ -759,6 +759,53 @@ func TestGetChannelMembers(t *testing.T) {
CheckNoError(t, resp)
}
+func TestGetChannelMembersByIds(t *testing.T) {
+ th := Setup().InitBasic().InitSystemAdmin()
+ defer TearDown()
+ Client := th.Client
+
+ cm, resp := Client.GetChannelMembersByIds(th.BasicChannel.Id, []string{th.BasicUser.Id})
+ CheckNoError(t, resp)
+
+ if (*cm)[0].UserId != th.BasicUser.Id {
+ t.Fatal("returned wrong user")
+ }
+
+ _, resp = Client.GetChannelMembersByIds(th.BasicChannel.Id, []string{})
+ CheckBadRequestStatus(t, resp)
+
+ cm1, resp := Client.GetChannelMembersByIds(th.BasicChannel.Id, []string{"junk"})
+ CheckNoError(t, resp)
+ if len(*cm1) > 0 {
+ t.Fatal("no users should be returned")
+ }
+
+ cm1, resp = Client.GetChannelMembersByIds(th.BasicChannel.Id, []string{"junk", th.BasicUser.Id})
+ CheckNoError(t, resp)
+ if len(*cm1) != 1 {
+ t.Fatal("1 member should be returned")
+ }
+
+ cm1, resp = Client.GetChannelMembersByIds(th.BasicChannel.Id, []string{th.BasicUser2.Id, th.BasicUser.Id})
+ CheckNoError(t, resp)
+ if len(*cm1) != 2 {
+ t.Fatal("2 members should be returned")
+ }
+
+ _, resp = Client.GetChannelMembersByIds("junk", []string{th.BasicUser.Id})
+ CheckBadRequestStatus(t, resp)
+
+ _, resp = Client.GetChannelMembersByIds(model.NewId(), []string{th.BasicUser.Id})
+ CheckForbiddenStatus(t, resp)
+
+ Client.Logout()
+ _, resp = Client.GetChannelMembersByIds(th.BasicChannel.Id, []string{th.BasicUser.Id})
+ CheckUnauthorizedStatus(t, resp)
+
+ _, resp = th.SystemAdminClient.GetChannelMembersByIds(th.BasicChannel.Id, []string{th.BasicUser2.Id, th.BasicUser.Id})
+ CheckNoError(t, resp)
+}
+
func TestGetChannelMember(t *testing.T) {
th := Setup().InitBasic().InitSystemAdmin()
defer TearDown()
@@ -914,6 +961,84 @@ func TestViewChannel(t *testing.T) {
CheckNoError(t, resp)
}
+func TestGetChannelUnread(t *testing.T) {
+ th := Setup().InitBasic().InitSystemAdmin()
+ defer TearDown()
+ Client := th.Client
+ user := th.BasicUser
+ channel := th.BasicChannel
+
+ channelUnread, resp := Client.GetChannelUnread(channel.Id, user.Id)
+ CheckNoError(t, resp)
+ if channelUnread.TeamId != th.BasicTeam.Id {
+ t.Fatal("wrong team id returned for a regular user call")
+ } else if channelUnread.ChannelId != channel.Id {
+ t.Fatal("wrong team id returned for a regular user call")
+ }
+
+ _, resp = Client.GetChannelUnread("junk", user.Id)
+ CheckBadRequestStatus(t, resp)
+
+ _, resp = Client.GetChannelUnread(channel.Id, "junk")
+ CheckBadRequestStatus(t, resp)
+
+ _, resp = Client.GetChannelUnread(channel.Id, model.NewId())
+ CheckForbiddenStatus(t, resp)
+
+ _, resp = Client.GetChannelUnread(model.NewId(), user.Id)
+ CheckForbiddenStatus(t, resp)
+
+ newUser := th.CreateUser()
+ Client.Login(newUser.Email, newUser.Password)
+ _, resp = Client.GetChannelUnread(th.BasicChannel.Id, user.Id)
+ CheckForbiddenStatus(t, resp)
+
+ Client.Logout()
+
+ _, resp = th.SystemAdminClient.GetChannelUnread(channel.Id, user.Id)
+ CheckNoError(t, resp)
+
+ _, resp = th.SystemAdminClient.GetChannelUnread(model.NewId(), user.Id)
+ CheckNotFoundStatus(t, resp)
+
+ _, resp = th.SystemAdminClient.GetChannelUnread(channel.Id, model.NewId())
+ CheckNotFoundStatus(t, resp)
+}
+
+func TestGetChannelStats(t *testing.T) {
+ th := Setup().InitBasic().InitSystemAdmin()
+ defer TearDown()
+ Client := th.Client
+ channel := th.CreatePrivateChannel()
+
+ stats, resp := Client.GetChannelStats(channel.Id, "")
+ CheckNoError(t, resp)
+
+ if stats.ChannelId != channel.Id {
+ t.Fatal("couldnt't get extra info")
+ } else if stats.MemberCount != 1 {
+ t.Fatal("got incorrect member count")
+ }
+
+ _, resp = Client.GetChannelStats("junk", "")
+ CheckBadRequestStatus(t, resp)
+
+ _, resp = Client.GetChannelStats(model.NewId(), "")
+ CheckForbiddenStatus(t, resp)
+
+ Client.Logout()
+ _, resp = Client.GetChannelStats(channel.Id, "")
+ CheckUnauthorizedStatus(t, resp)
+
+ th.LoginBasic2()
+
+ _, resp = Client.GetChannelStats(channel.Id, "")
+ CheckForbiddenStatus(t, resp)
+
+ _, resp = th.SystemAdminClient.GetChannelStats(channel.Id, "")
+ CheckNoError(t, resp)
+}
+
func TestUpdateChannelRoles(t *testing.T) {
th := Setup().InitBasic().InitSystemAdmin()
defer TearDown()