summaryrefslogtreecommitdiffstats
path: root/api4/channel_test.go
diff options
context:
space:
mode:
authorRuzette Tanyag <ruzette@users.noreply.github.com>2017-02-14 10:28:08 -0500
committerHarrison Healey <harrisonmhealey@gmail.com>2017-02-14 10:28:08 -0500
commit28aa7cdbf2357bda51ba740fd4d7af48b36b96b4 (patch)
tree0a7daa93b5fa594b113f905506ed6ee6940e789b /api4/channel_test.go
parent9dabd10da975a47155641351bbf61b6fb203b4ca (diff)
downloadchat-28aa7cdbf2357bda51ba740fd4d7af48b36b96b4.tar.gz
chat-28aa7cdbf2357bda51ba740fd4d7af48b36b96b4.tar.bz2
chat-28aa7cdbf2357bda51ba740fd4d7af48b36b96b4.zip
Implement GET channels endpoints for APIv4 (#5363)
* implement get channels endpoints and updated drivers and unittests * removed channel deletion on tear down, removed manage permission on get channels endpoints, and updated utils to add constant channel length * added constants for user, team and channel length, updated context to use the model functions * make sure team name length should be less than the minimum length and revert underscore to team name validity * changed post test condition from notfound to unauthorized
Diffstat (limited to 'api4/channel_test.go')
-rw-r--r--api4/channel_test.go80
1 files changed, 79 insertions, 1 deletions
diff --git a/api4/channel_test.go b/api4/channel_test.go
index 91d055bff..7e59f60e8 100644
--- a/api4/channel_test.go
+++ b/api4/channel_test.go
@@ -221,6 +221,84 @@ func TestCreateDirectChannel(t *testing.T) {
CheckNoError(t, resp)
}
+func TestGetChannel(t *testing.T) {
+ th := Setup().InitBasic().InitSystemAdmin()
+ defer TearDown()
+ Client := th.Client
+
+ _, resp := Client.GetChannel(th.BasicChannel.Id, "")
+ CheckNoError(t, resp)
+
+ _, resp = Client.GetChannel(model.NewId(), "")
+ CheckForbiddenStatus(t, resp)
+
+ Client.Logout()
+ _, resp = Client.GetChannel(th.BasicChannel.Id, "")
+ CheckUnauthorizedStatus(t, resp)
+
+ user := th.CreateUser()
+ Client.Login(user.Email, user.Password)
+ _, resp = Client.GetChannel(th.BasicChannel.Id, "")
+ CheckForbiddenStatus(t, resp)
+
+ _, resp = th.SystemAdminClient.GetChannel(th.BasicChannel.Id, "")
+ CheckNoError(t, resp)
+
+ _, resp = th.SystemAdminClient.GetChannel(th.BasicUser.Id, "")
+ CheckNotFoundStatus(t, resp)
+}
+
+func TestGetChannelByName(t *testing.T) {
+ th := Setup().InitBasic().InitSystemAdmin()
+ defer TearDown()
+ Client := th.Client
+
+ _, resp := Client.GetChannelByName(th.BasicChannel.Name, th.BasicTeam.Id, "")
+ CheckNoError(t, resp)
+
+ _, resp = Client.GetChannelByName(GenerateTestChannelName(), th.BasicTeam.Id, "")
+ CheckNotFoundStatus(t, resp)
+
+ Client.Logout()
+ _, resp = Client.GetChannelByName(th.BasicChannel.Name, th.BasicTeam.Id, "")
+ CheckUnauthorizedStatus(t, resp)
+
+ user := th.CreateUser()
+ Client.Login(user.Email, user.Password)
+ _, resp = Client.GetChannelByName(th.BasicChannel.Name, th.BasicTeam.Id, "")
+ CheckForbiddenStatus(t, resp)
+
+ _, resp = th.SystemAdminClient.GetChannelByName(th.BasicChannel.Name, th.BasicTeam.Id, "")
+ CheckNoError(t, resp)
+}
+
+func TestGetChannelByNameForTeamName(t *testing.T) {
+ th := Setup().InitBasic().InitSystemAdmin()
+ defer TearDown()
+ Client := th.Client
+
+ _, resp := th.SystemAdminClient.GetChannelByNameForTeamName(th.BasicChannel.Name, th.BasicTeam.Name, "")
+ CheckNoError(t, resp)
+
+ _, resp = Client.GetChannelByNameForTeamName(th.BasicChannel.Name, th.BasicTeam.Name, "")
+ CheckNoError(t, resp)
+
+ _, resp = Client.GetChannelByNameForTeamName(th.BasicChannel.Name, model.NewRandomString(15), "")
+ CheckNotFoundStatus(t, resp)
+
+ _, resp = Client.GetChannelByNameForTeamName(GenerateTestChannelName(), th.BasicTeam.Name, "")
+ CheckNotFoundStatus(t, resp)
+
+ Client.Logout()
+ _, resp = Client.GetChannelByNameForTeamName(th.BasicChannel.Name, th.BasicTeam.Name, "")
+ CheckUnauthorizedStatus(t, resp)
+
+ user := th.CreateUser()
+ Client.Login(user.Email, user.Password)
+ _, resp = Client.GetChannelByNameForTeamName(th.BasicChannel.Name, th.BasicTeam.Name, "")
+ CheckForbiddenStatus(t, resp)
+}
+
func TestGetChannelMembers(t *testing.T) {
th := Setup().InitBasic().InitSystemAdmin()
defer TearDown()
@@ -255,7 +333,7 @@ func TestGetChannelMembers(t *testing.T) {
}
_, resp = Client.GetChannelMembers("", 0, 60, "")
- CheckNotFoundStatus(t, resp)
+ CheckUnauthorizedStatus(t, resp)
_, resp = Client.GetChannelMembers("junk", 0, 60, "")
CheckBadRequestStatus(t, resp)