[MM-44263] Only include user posts in post count (#20250)

* Fetch users only posts

* Explicitly validate posts count before testing usage
Этот коммит содержится в:
Vishal
2022-05-31 14:18:41 +05:30
коммит произвёл GitHub
родитель 70610a9c96
Коммит 57e9aa767c
5 изменённых файлов: 30 добавлений и 5 удалений

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

@@ -7,7 +7,9 @@ import (
"net/http"
"testing"
"github.com/mattermost/mattermost-server/v6/model"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestGetPostsUsage(t *testing.T) {
@@ -24,11 +26,21 @@ func TestGetPostsUsage(t *testing.T) {
})
t.Run("good request returns response", func(t *testing.T) {
// Following calls create a total of 15 posts
th := Setup(t).InitBasic()
defer th.TearDown()
th.CreatePost()
th.CreatePost()
for i := 0; i < 14; i++ {
th.CreatePost()
}
total, err := th.Server.Store.Post().AnalyticsPostCount(&model.PostCountOptions{ExcludeDeleted: true})
require.NoError(t, err)
usersOnly, err := th.Server.Store.Post().AnalyticsPostCount(&model.PostCountOptions{ExcludeDeleted: true, UsersPostsOnly: true})
require.NoError(t, err)
require.GreaterOrEqual(t, usersOnly, int64(14))
require.LessOrEqual(t, usersOnly, int64(20))
require.GreaterOrEqual(t, total, usersOnly)
usage, r, err := th.Client.GetPostsUsage()
assert.NoError(t, err)