[MM-43917] Cloud Freemium limits API: messages/posts (#20152)
* WIP - Add api and app funcs * Add test cases * Add utils testcases * Exclude deleted posts * Add doc for func * Move api from cloud to usage * Allow api access to authenticated users * Change int to int64 * Fix lint issue * Simplify err check Co-authored-by: Ashish Bhate <ashish.bhate@mattermost.com> Co-authored-by: Mattermod <mattermod@users.noreply.github.com> Co-authored-by: Ashish Bhate <ashish.bhate@mattermost.com>
Этот коммит содержится в:
@@ -16,20 +16,20 @@ type PostStore struct {
|
||||
mock.Mock
|
||||
}
|
||||
|
||||
// AnalyticsPostCount provides a mock function with given fields: teamID, mustHaveFile, mustHaveHashtag
|
||||
func (_m *PostStore) AnalyticsPostCount(teamID string, mustHaveFile bool, mustHaveHashtag bool) (int64, error) {
|
||||
ret := _m.Called(teamID, mustHaveFile, mustHaveHashtag)
|
||||
// AnalyticsPostCount provides a mock function with given fields: options
|
||||
func (_m *PostStore) AnalyticsPostCount(options *model.PostCountOptions) (int64, error) {
|
||||
ret := _m.Called(options)
|
||||
|
||||
var r0 int64
|
||||
if rf, ok := ret.Get(0).(func(string, bool, bool) int64); ok {
|
||||
r0 = rf(teamID, mustHaveFile, mustHaveHashtag)
|
||||
if rf, ok := ret.Get(0).(func(*model.PostCountOptions) int64); ok {
|
||||
r0 = rf(options)
|
||||
} else {
|
||||
r0 = ret.Get(0).(int64)
|
||||
}
|
||||
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(string, bool, bool) error); ok {
|
||||
r1 = rf(teamID, mustHaveFile, mustHaveHashtag)
|
||||
if rf, ok := ret.Get(1).(func(*model.PostCountOptions) error); ok {
|
||||
r1 = rf(options)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
@@ -2115,30 +2115,39 @@ func testPostCountsByDay(t *testing.T, ss store.Store) {
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, float64(1), r1[0].Value)
|
||||
|
||||
// total
|
||||
r2, err := ss.Post().AnalyticsPostCount(t1.Id, false, false)
|
||||
// total for single team
|
||||
r2, err := ss.Post().AnalyticsPostCount(&model.PostCountOptions{TeamId: t1.Id})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, int64(6), r2)
|
||||
|
||||
// total across teams
|
||||
r2, err = ss.Post().AnalyticsPostCount("", false, false)
|
||||
r2, err = ss.Post().AnalyticsPostCount(&model.PostCountOptions{})
|
||||
require.NoError(t, err)
|
||||
assert.GreaterOrEqual(t, r2, int64(6))
|
||||
|
||||
// total across teams with files
|
||||
r2, err = ss.Post().AnalyticsPostCount("", true, false)
|
||||
r2, err = ss.Post().AnalyticsPostCount(&model.PostCountOptions{MustHaveFile: true})
|
||||
require.NoError(t, err)
|
||||
assert.GreaterOrEqual(t, r2, int64(3))
|
||||
|
||||
// total across teams with hastags
|
||||
r2, err = ss.Post().AnalyticsPostCount("", false, true)
|
||||
// total across teams with hashtags
|
||||
r2, err = ss.Post().AnalyticsPostCount(&model.PostCountOptions{MustHaveHashtag: true})
|
||||
require.NoError(t, err)
|
||||
assert.GreaterOrEqual(t, r2, int64(2))
|
||||
|
||||
// total across teams with hastags and files
|
||||
r2, err = ss.Post().AnalyticsPostCount("", true, true)
|
||||
r2, err = ss.Post().AnalyticsPostCount(&model.PostCountOptions{MustHaveFile: true, MustHaveHashtag: true})
|
||||
require.NoError(t, err)
|
||||
assert.GreaterOrEqual(t, r2, int64(1))
|
||||
|
||||
// delete 1 post
|
||||
err = ss.Post().Delete(o1.Id, 1, o1.UserId)
|
||||
require.NoError(t, err)
|
||||
|
||||
// total for single team with the deleted post excluded
|
||||
r2, err = ss.Post().AnalyticsPostCount(&model.PostCountOptions{TeamId: t1.Id, ExcludeDeleted: true})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, int64(5), r2)
|
||||
}
|
||||
|
||||
func testPostStoreGetFlaggedPostsForTeam(t *testing.T, ss store.Store, s SqlStore) {
|
||||
|
||||
Ссылка в новой задаче
Block a user