From 8a31718db11c803fa3b14f85c760ca9db6083670 Mon Sep 17 00:00:00 2001 From: Saturnino Abril Date: Thu, 30 Mar 2017 00:09:05 +0900 Subject: APIv4 get /channels/{channel_id}/pinned (#5893) --- api4/channel_test.go | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'api4/channel_test.go') diff --git a/api4/channel_test.go b/api4/channel_test.go index 3d501b313..3cc1cb64f 100644 --- a/api4/channel_test.go +++ b/api4/channel_test.go @@ -1322,6 +1322,45 @@ func TestGetChannelStats(t *testing.T) { CheckNoError(t, resp) } +func TestGetPinnedPosts(t *testing.T) { + th := Setup().InitBasic().InitSystemAdmin() + defer TearDown() + Client := th.Client + channel := th.BasicChannel + + posts, resp := Client.GetPinnedPosts(channel.Id, "") + CheckNoError(t, resp) + if len(posts.Posts) != 0 { + t.Fatal("should not have gotten a pinned post") + } + + pinnedPost := th.CreatePinnedPost() + posts, resp = Client.GetPinnedPosts(channel.Id, "") + CheckNoError(t, resp) + if len(posts.Posts) != 1 { + t.Fatal("should have returned 1 pinned post") + } + if _, ok := posts.Posts[pinnedPost.Id]; !ok { + t.Fatal("missing pinned post") + } + + posts, resp = Client.GetPinnedPosts(channel.Id, resp.Etag) + CheckEtag(t, posts, resp) + + _, resp = Client.GetPinnedPosts(GenerateTestId(), "") + CheckForbiddenStatus(t, resp) + + _, resp = Client.GetPinnedPosts("junk", "") + CheckBadRequestStatus(t, resp) + + Client.Logout() + _, resp = Client.GetPinnedPosts(channel.Id, "") + CheckUnauthorizedStatus(t, resp) + + _, resp = th.SystemAdminClient.GetPinnedPosts(channel.Id, "") + CheckNoError(t, resp) +} + func TestUpdateChannelRoles(t *testing.T) { th := Setup().InitBasic().InitSystemAdmin() defer TearDown() -- cgit v1.2.3-1-g7c22