summaryrefslogtreecommitdiffstats
path: root/api4/post_test.go
diff options
context:
space:
mode:
authorJoram Wilander <jwawilander@gmail.com>2017-03-24 16:46:11 -0400
committerCorey Hulen <corey@hulen.com>2017-03-24 13:46:11 -0700
commit69fb47b88bc8d97c4797fa72e60416f8fb658e20 (patch)
tree263641b645eb1c1403d238c91c470de49a5a516d /api4/post_test.go
parent28a78d76074749a3b7f1ef2a56617b0a1c7fd623 (diff)
downloadchat-69fb47b88bc8d97c4797fa72e60416f8fb658e20.tar.gz
chat-69fb47b88bc8d97c4797fa72e60416f8fb658e20.tar.bz2
chat-69fb47b88bc8d97c4797fa72e60416f8fb658e20.zip
Add query parameters to get posts v4 endpoint (#5858)
* Add since query paremeter to get posts v4 endpoint * Add query paremeters for before/after to get posts v4 endpoint
Diffstat (limited to 'api4/post_test.go')
-rw-r--r--api4/post_test.go119
1 files changed, 115 insertions, 4 deletions
diff --git a/api4/post_test.go b/api4/post_test.go
index 5c5c98d3d..9e0880004 100644
--- a/api4/post_test.go
+++ b/api4/post_test.go
@@ -174,9 +174,12 @@ func TestGetPostsForChannel(t *testing.T) {
post1 := th.CreatePost()
post2 := th.CreatePost()
- post3 := th.CreatePost()
- post4 := &model.Post{ChannelId: th.BasicChannel.Id, Message: "a" + model.NewId() + "a", RootId: post1.Id}
- post4, _ = Client.CreatePost(post4)
+ post3 := &model.Post{ChannelId: th.BasicChannel.Id, Message: "a" + model.NewId() + "a", RootId: post1.Id}
+ post3, _ = Client.CreatePost(post3)
+
+ time := model.GetMillis()
+
+ post4 := th.CreatePost()
posts, resp := Client.GetPostsForChannel(th.BasicChannel.Id, 0, 60, "")
CheckNoError(t, resp)
@@ -207,7 +210,7 @@ func TestGetPostsForChannel(t *testing.T) {
t.Fatal("wrong number returned")
}
- if _, ok := posts.Posts[post4.Id]; !ok {
+ if _, ok := posts.Posts[post3.Id]; !ok {
t.Fatal("missing comment")
}
@@ -229,6 +232,30 @@ func TestGetPostsForChannel(t *testing.T) {
t.Fatal("should be no posts")
}
+ post5 := th.CreatePost()
+
+ posts, resp = Client.GetPostsSince(th.BasicChannel.Id, time)
+ CheckNoError(t, resp)
+
+ found := make([]bool, 2)
+ for _, p := range posts.Posts {
+ if p.CreateAt < time {
+ t.Fatal("bad create at for post returned")
+ }
+
+ if p.Id == post4.Id {
+ found[0] = true
+ } else if p.Id == post5.Id {
+ found[1] = true
+ }
+ }
+
+ for _, f := range found {
+ if !f {
+ t.Fatal("missing post")
+ }
+ }
+
_, resp = Client.GetPostsForChannel("", 0, 60, "")
CheckBadRequestStatus(t, resp)
@@ -246,6 +273,90 @@ func TestGetPostsForChannel(t *testing.T) {
CheckNoError(t, resp)
}
+func TestGetPostsAfterAndBefore(t *testing.T) {
+ th := Setup().InitBasic()
+ defer TearDown()
+ Client := th.Client
+
+ post1 := th.CreatePost()
+ post2 := th.CreatePost()
+ post3 := th.CreatePost()
+ post4 := th.CreatePost()
+ post5 := th.CreatePost()
+
+ posts, resp := Client.GetPostsBefore(th.BasicChannel.Id, post3.Id, 0, 100, "")
+ CheckNoError(t, resp)
+
+ found := make([]bool, 2)
+ for _, p := range posts.Posts {
+ if p.Id == post1.Id {
+ found[0] = true
+ } else if p.Id == post2.Id {
+ found[1] = true
+ }
+
+ if p.Id == post4.Id || p.Id == post5.Id {
+ t.Fatal("returned posts after")
+ }
+ }
+
+ for _, f := range found {
+ if !f {
+ t.Fatal("missing post")
+ }
+ }
+
+ posts, resp = Client.GetPostsBefore(th.BasicChannel.Id, post3.Id, 1, 1, "")
+ CheckNoError(t, resp)
+
+ if len(posts.Posts) != 1 {
+ t.Fatal("too many posts returned")
+ }
+
+ posts, resp = Client.GetPostsBefore(th.BasicChannel.Id, "junk", 1, 1, "")
+ CheckNoError(t, resp)
+
+ if len(posts.Posts) != 0 {
+ t.Fatal("should have no posts")
+ }
+
+ posts, resp = Client.GetPostsAfter(th.BasicChannel.Id, post3.Id, 0, 100, "")
+ CheckNoError(t, resp)
+
+ found = make([]bool, 2)
+ for _, p := range posts.Posts {
+ if p.Id == post4.Id {
+ found[0] = true
+ } else if p.Id == post5.Id {
+ found[1] = true
+ }
+
+ if p.Id == post1.Id || p.Id == post2.Id {
+ t.Fatal("returned posts before")
+ }
+ }
+
+ for _, f := range found {
+ if !f {
+ t.Fatal("missing post")
+ }
+ }
+
+ posts, resp = Client.GetPostsAfter(th.BasicChannel.Id, post3.Id, 1, 1, "")
+ CheckNoError(t, resp)
+
+ if len(posts.Posts) != 1 {
+ t.Fatal("too many posts returned")
+ }
+
+ posts, resp = Client.GetPostsAfter(th.BasicChannel.Id, "junk", 1, 1, "")
+ CheckNoError(t, resp)
+
+ if len(posts.Posts) != 0 {
+ t.Fatal("should have no posts")
+ }
+}
+
func TestGetPost(t *testing.T) {
th := Setup().InitBasic().InitSystemAdmin()
defer TearDown()