mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
Add initial unit test for post.getPostById() (#4910)
* add itinial tests for GetPostById update per review fix lint * add missing comment
This commit is contained in:
committed by
enahum
parent
42da7aa700
commit
21af988e49
@@ -1360,3 +1360,33 @@ func TestSendNotifications(t *testing.T) {
|
||||
t.Fatal("user should have been mentioned")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetPostById(t *testing.T) {
|
||||
th := Setup().InitBasic()
|
||||
Client := th.BasicClient
|
||||
channel1 := th.BasicChannel
|
||||
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
post1 := &model.Post{ChannelId: channel1.Id, Message: "yommamma" + model.NewId() + "a"}
|
||||
post1 = Client.Must(Client.CreatePost(post1)).Data.(*model.Post)
|
||||
|
||||
if post, respMetadata := Client.GetPostById(post1.Id, ""); respMetadata.Error != nil {
|
||||
t.Fatal(respMetadata.Error)
|
||||
} else {
|
||||
if len(post.Order) != 1 {
|
||||
t.Fatal("should be just one post")
|
||||
}
|
||||
|
||||
if post.Order[0] != post1.Id {
|
||||
t.Fatal("wrong order")
|
||||
}
|
||||
|
||||
if post.Posts[post.Order[0]].Message != post1.Message {
|
||||
t.Fatal("wrong message from post")
|
||||
}
|
||||
}
|
||||
|
||||
if _, respMetadata := Client.GetPostById("45345435345345", ""); respMetadata.Error == nil {
|
||||
t.Fatal(respMetadata.Error)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1483,6 +1483,21 @@ func (c *Client) GetPost(channelId string, postId string, etag string) (*Result,
|
||||
}
|
||||
}
|
||||
|
||||
// GetPostById returns a post and any posts in the same thread by post id
|
||||
func (c *Client) GetPostById(postId string, etag string) (*PostList, *ResponseMetadata) {
|
||||
if r, err := c.DoApiGet(c.GetTeamRoute()+fmt.Sprintf("/posts/%v", postId), "", etag); err != nil {
|
||||
return nil, &ResponseMetadata{StatusCode: r.StatusCode, Error: err}
|
||||
} else {
|
||||
defer closeBody(r)
|
||||
return PostListFromJson(r.Body),
|
||||
&ResponseMetadata{
|
||||
StatusCode: r.StatusCode,
|
||||
RequestId: r.Header.Get(HEADER_REQUEST_ID),
|
||||
Etag: r.Header.Get(HEADER_ETAG_SERVER),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Client) DeletePost(channelId string, postId string) (*Result, *AppError) {
|
||||
if r, err := c.DoApiPost(c.GetChannelRoute(channelId)+fmt.Sprintf("/posts/%v/delete", postId), ""); err != nil {
|
||||
return nil, err
|
||||
|
||||
Reference in New Issue
Block a user