MM-23508: Fix plugin API's GetPostsForChannel (#14125)

Add a test checking the basic behaviour of the function
Этот коммит содержится в:
Alejandro García Montoro
2020-03-25 10:24:42 +01:00
коммит произвёл GitHub
родитель 190631b6e1
Коммит aa47b4633f
2 изменённых файлов: 44 добавлений и 1 удалений

Просмотреть файл

@@ -1409,3 +1409,46 @@ func TestApiMetrics(t *testing.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())
}