diff options
author | Joram Wilander <jwawilander@gmail.com> | 2015-11-04 07:51:19 -0500 |
---|---|---|
committer | Joram Wilander <jwawilander@gmail.com> | 2015-11-04 07:51:19 -0500 |
commit | 0cc985f6f4c439eb9a951d007628849d15a16087 (patch) | |
tree | dc9ef286cdfaa4a86a9ccab1d6a4ef3d3c0134ca /api/post_test.go | |
parent | 87c4b4fbf44662b1ff70e245126921f24d0829a4 (diff) | |
parent | 188182a3a4499965dbbde254aed0ae5e60e71dc5 (diff) | |
download | chat-0cc985f6f4c439eb9a951d007628849d15a16087.tar.gz chat-0cc985f6f4c439eb9a951d007628849d15a16087.tar.bz2 chat-0cc985f6f4c439eb9a951d007628849d15a16087.zip |
Merge pull request #1285 from mattermost/plt-824
PLT-824 Adding ability to fetch posts around a specifc post
Diffstat (limited to 'api/post_test.go')
-rw-r--r-- | api/post_test.go | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/api/post_test.go b/api/post_test.go index e54e9ef0c..3452c9788 100644 --- a/api/post_test.go +++ b/api/post_test.go @@ -329,6 +329,83 @@ func TestGetPostsSince(t *testing.T) { } } +func TestGetPostsBeforeAfter(t *testing.T) { + Setup() + + team := &model.Team{DisplayName: "Name", Name: "z-z-" + model.NewId() + "a", Email: "test@nowhere.com", Type: model.TEAM_OPEN} + team = Client.Must(Client.CreateTeam(team)).Data.(*model.Team) + + user1 := &model.User{TeamId: team.Id, Email: model.NewId() + "corey@test.com", Nickname: "Corey Hulen", Password: "pwd"} + user1 = Client.Must(Client.CreateUser(user1, "")).Data.(*model.User) + store.Must(Srv.Store.User().VerifyEmail(user1.Id)) + + Client.LoginByEmail(team.Name, user1.Email, "pwd") + + channel1 := &model.Channel{DisplayName: "TestGetPosts", Name: "a" + model.NewId() + "a", Type: model.CHANNEL_OPEN, TeamId: team.Id} + channel1 = Client.Must(Client.CreateChannel(channel1)).Data.(*model.Channel) + + time.Sleep(10 * time.Millisecond) + post0 := &model.Post{ChannelId: channel1.Id, Message: "a" + model.NewId() + "a"} + post0 = Client.Must(Client.CreatePost(post0)).Data.(*model.Post) + + time.Sleep(10 * time.Millisecond) + post1 := &model.Post{ChannelId: channel1.Id, Message: "a" + model.NewId() + "a"} + post1 = Client.Must(Client.CreatePost(post1)).Data.(*model.Post) + + time.Sleep(10 * time.Millisecond) + post1a1 := &model.Post{ChannelId: channel1.Id, Message: "a" + model.NewId() + "a", RootId: post1.Id} + post1a1 = Client.Must(Client.CreatePost(post1a1)).Data.(*model.Post) + + time.Sleep(10 * time.Millisecond) + post2 := &model.Post{ChannelId: channel1.Id, Message: "a" + model.NewId() + "a"} + post2 = Client.Must(Client.CreatePost(post2)).Data.(*model.Post) + + time.Sleep(10 * time.Millisecond) + post3 := &model.Post{ChannelId: channel1.Id, Message: "a" + model.NewId() + "a"} + post3 = Client.Must(Client.CreatePost(post3)).Data.(*model.Post) + + time.Sleep(10 * time.Millisecond) + post3a1 := &model.Post{ChannelId: channel1.Id, Message: "a" + model.NewId() + "a", RootId: post3.Id} + post3a1 = Client.Must(Client.CreatePost(post3a1)).Data.(*model.Post) + + r1 := Client.Must(Client.GetPostsBefore(channel1.Id, post1a1.Id, 0, 10, "")).Data.(*model.PostList) + + if r1.Order[0] != post1.Id { + t.Fatal("wrong order") + } + + if r1.Order[1] != post0.Id { + t.Fatal("wrong order") + } + + if len(r1.Posts) != 2 { + t.Fatal("wrong size") + } + + r2 := Client.Must(Client.GetPostsAfter(channel1.Id, post3a1.Id, 0, 3, "")).Data.(*model.PostList) + + if len(r2.Posts) != 0 { + t.Fatal("should have been empty") + } + + post2.Message = "new message" + Client.Must(Client.UpdatePost(post2)) + + r3 := Client.Must(Client.GetPostsAfter(channel1.Id, post1a1.Id, 0, 2, "")).Data.(*model.PostList) + + if r3.Order[0] != post3.Id { + t.Fatal("wrong order") + } + + if r3.Order[1] != post2.Id { + t.Fatal("wrong order") + } + + if len(r3.Order) != 2 { + t.Fatal("missing post update") + } +} + func TestSearchPosts(t *testing.T) { Setup() |