MM-23508: Fix plugin API's GetPostsForChannel (#14125)
Add a test checking the basic behaviour of the function
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
190631b6e1
Коммит
aa47b4633f
@@ -521,7 +521,7 @@ func (api *PluginAPI) GetPostsBefore(channelId, postId string, page, perPage int
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (api *PluginAPI) GetPostsForChannel(channelId string, page, perPage int) (*model.PostList, *model.AppError) {
|
func (api *PluginAPI) GetPostsForChannel(channelId string, page, perPage int) (*model.PostList, *model.AppError) {
|
||||||
return api.app.GetPostsPage(model.GetPostsOptions{ChannelId: channelId, Page: perPage, PerPage: page})
|
return api.app.GetPostsPage(model.GetPostsOptions{ChannelId: channelId, Page: page, PerPage: perPage})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *PluginAPI) UpdatePost(post *model.Post) (*model.Post, *model.AppError) {
|
func (api *PluginAPI) UpdatePost(post *model.Post) (*model.Post, *model.AppError) {
|
||||||
|
|||||||
@@ -1409,3 +1409,46 @@ func TestApiMetrics(t *testing.T) {
|
|||||||
metricsMock.AssertExpectations(t)
|
metricsMock.AssertExpectations(t)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestPluginAPIGetPostsForChannel(t *testing.T) {
|
||||||
|
require := require.New(t)
|
||||||
|
|
||||||
|
th := Setup(t).InitBasic()
|
||||||
|
defer th.TearDown()
|
||||||
|
api := th.SetupPluginAPI()
|
||||||
|
|
||||||
|
numPosts := 10
|
||||||
|
|
||||||
|
// GetPostsForChannel returns posts ordered with the most recent first, so we
|
||||||
|
// need to invert the expected slice, the oldest post being BasicPost
|
||||||
|
expectedPosts := make([]*model.Post, numPosts)
|
||||||
|
expectedPosts[numPosts-1] = th.BasicPost
|
||||||
|
for i := numPosts - 2; i >= 0; i-- {
|
||||||
|
expectedPosts[i] = th.CreatePost(th.BasicChannel)
|
||||||
|
}
|
||||||
|
// CreatePost does not add Metadata, but initializes the structure. GetPostsForChannel
|
||||||
|
// returns nil for an empty Metadata, so we need to match that behaviour
|
||||||
|
for _, post := range expectedPosts {
|
||||||
|
post.Metadata = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
postList, err := api.GetPostsForChannel(th.BasicChannel.Id, 0, 0)
|
||||||
|
require.Nil(err)
|
||||||
|
require.Nil(postList.ToSlice())
|
||||||
|
|
||||||
|
postList, err = api.GetPostsForChannel(th.BasicChannel.Id, 0, numPosts/2)
|
||||||
|
require.Nil(err)
|
||||||
|
require.Equal(expectedPosts[:numPosts/2], postList.ToSlice())
|
||||||
|
|
||||||
|
postList, err = api.GetPostsForChannel(th.BasicChannel.Id, 1, numPosts/2)
|
||||||
|
require.Nil(err)
|
||||||
|
require.Equal(expectedPosts[numPosts/2:], postList.ToSlice())
|
||||||
|
|
||||||
|
postList, err = api.GetPostsForChannel(th.BasicChannel.Id, 2, numPosts/2)
|
||||||
|
require.Nil(err)
|
||||||
|
require.Nil(postList.ToSlice())
|
||||||
|
|
||||||
|
postList, err = api.GetPostsForChannel(th.BasicChannel.Id, 0, numPosts+1)
|
||||||
|
require.Nil(err)
|
||||||
|
require.Equal(expectedPosts, postList.ToSlice())
|
||||||
|
}
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user