summaryrefslogtreecommitdiffstats
path: root/api4/post_test.go
diff options
context:
space:
mode:
authorSaturnino Abril <saturnino.abril@gmail.com>2017-03-31 22:58:47 +0900
committerChristopher Speller <crspeller@gmail.com>2017-03-31 09:58:47 -0400
commit5d56fbb036cc7044eae639c92836e0b14ffe7dab (patch)
treeb497427cc50b4ca80694bde93e81878458660e0b /api4/post_test.go
parent5f6d50bff1b4098bc0ef3c120e7b12104e5c4894 (diff)
downloadchat-5d56fbb036cc7044eae639c92836e0b14ffe7dab.tar.gz
chat-5d56fbb036cc7044eae639c92836e0b14ffe7dab.tar.bz2
chat-5d56fbb036cc7044eae639c92836e0b14ffe7dab.zip
APIv4 POST /posts/{post_id/pin & unpin (#5906)
* APIv4 get /posts/{post_id}/pin & unpin * remove PinnedPost from api test helper
Diffstat (limited to 'api4/post_test.go')
-rw-r--r--api4/post_test.go70
1 files changed, 70 insertions, 0 deletions
diff --git a/api4/post_test.go b/api4/post_test.go
index bf896f081..562136ca9 100644
--- a/api4/post_test.go
+++ b/api4/post_test.go
@@ -270,6 +270,76 @@ func TestPatchPost(t *testing.T) {
CheckNoError(t, resp)
}
+func TestPinPost(t *testing.T) {
+ th := Setup().InitBasic().InitSystemAdmin()
+ defer TearDown()
+ Client := th.Client
+
+ post := th.BasicPost
+ pass, resp := Client.PinPost(post.Id)
+ CheckNoError(t, resp)
+
+ if !pass {
+ t.Fatal("should have passed")
+ }
+
+ if rpost, err := app.GetSinglePost(post.Id); err != nil && rpost.IsPinned != true {
+ t.Fatal("failed to pin post")
+ }
+
+ pass, resp = Client.PinPost("junk")
+ CheckBadRequestStatus(t, resp)
+
+ if pass {
+ t.Fatal("should have failed")
+ }
+
+ _, resp = Client.PinPost(GenerateTestId())
+ CheckForbiddenStatus(t, resp)
+
+ Client.Logout()
+ _, resp = Client.PinPost(post.Id)
+ CheckUnauthorizedStatus(t, resp)
+
+ _, resp = th.SystemAdminClient.PinPost(post.Id)
+ CheckNoError(t, resp)
+}
+
+func TestUnpinPost(t *testing.T) {
+ th := Setup().InitBasic().InitSystemAdmin()
+ defer TearDown()
+ Client := th.Client
+
+ pinnedPost := th.CreatePinnedPost()
+ pass, resp := Client.UnpinPost(pinnedPost.Id)
+ CheckNoError(t, resp)
+
+ if !pass {
+ t.Fatal("should have passed")
+ }
+
+ if rpost, err := app.GetSinglePost(pinnedPost.Id); err != nil && rpost.IsPinned != false {
+ t.Fatal("failed to pin post")
+ }
+
+ pass, resp = Client.UnpinPost("junk")
+ CheckBadRequestStatus(t, resp)
+
+ if pass {
+ t.Fatal("should have failed")
+ }
+
+ _, resp = Client.UnpinPost(GenerateTestId())
+ CheckForbiddenStatus(t, resp)
+
+ Client.Logout()
+ _, resp = Client.UnpinPost(pinnedPost.Id)
+ CheckUnauthorizedStatus(t, resp)
+
+ _, resp = th.SystemAdminClient.UnpinPost(pinnedPost.Id)
+ CheckNoError(t, resp)
+}
+
func TestGetPostsForChannel(t *testing.T) {
th := Setup().InitBasic().InitSystemAdmin()
defer TearDown()