snapshot of https://github.com/mattermost/mattermost.git (master, 2026-09-16; blobs > 131072B omitted)
Some checks failed
Server CI / Postgres (shard 0) (push) Has been skipped
Server CI / Postgres (shard 3) (push) Has been skipped
BuildEnv Docker Image / build-image (push) Failing after 4s
BuildEnv Docker Image / build-image-fips (push) Failing after 4s
Migration Review & Release Notes / Generate migration review & release notes (push) Failing after 3s
Server CI / Build Environment (push) Failing after 3s
Server CI / Postgres (shard 1) (push) Has been skipped
Tools CI / check-style (mattermost-govet) (push) Failing after 4s
Server CI / Postgres (shard 2) (push) Has been skipped
Tools CI / check-style (mmgotool) (push) Failing after 3s
Server CI / Elasticsearch v8 Compatibility (push) Has been skipped
Server CI / OpenSearch v2 Compatibility (push) Has been skipped
Server CI / Postgres FIPS (shard 0) (push) Has been skipped
Tools CI / Test (mattermost-govet) (push) Failing after 3s
Server CI / Postgres FIPS (shard 1) (push) Has been skipped
Server CI / Postgres FIPS (shard 2) (push) Has been skipped
Tools CI / Test (mmgotool) (push) Failing after 3s
Server CI / Postgres FIPS (shard 3) (push) Has been skipped
Server CI / Run mmctl tests (push) Has been skipped
Server CI / Run mmctl tests (FIPS) (push) Has been skipped
Server CI / Merge Postgres Test Results (push) Has been skipped
Server CI / Merge Postgres FIPS Test Results (push) Has been skipped
Server CI / Check backport migrations (push) Has been skipped
Server CI / Check generated files (push) Has been skipped
Server CI / check-style (push) Has been skipped
Server CI / Vet API (push) Has been skipped
Server CI / Build mattermost server app (push) Has been skipped
Server CI / Server CI Complete (push) Failing after 2s
Server CI / Server CI Artifacts (push) Has been skipped
Server CI / Sentry Upload (push) Has been skipped
Server CI / Server CI Report (push) Failing after 5m1s
Server CI Nightly Race / Race Detector (push) Has been skipped
CodeQL / Analyze (go) (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
Webapp CI Cache Warm / Warm Webapp node_modules Cache (push) Has been cancelled
E2E CI Cache Warm / Warm E2E npm Registry Cache (push) Has been cancelled
API / build (push) Has been cancelled
Web App CI / check-types (push) Has been cancelled
Web App CI / check-lint (push) Has been cancelled
Web App CI / check-i18n (push) Has been cancelled
Web App CI / check-external-links (push) Has been cancelled
Web App CI / test (platform) (push) Has been cancelled
Web App CI / test (mattermost-redux) (push) Has been cancelled
Web App CI / test (channels shard 1/4) (push) Has been cancelled
Web App CI / test (channels shard 2/4) (push) Has been cancelled
Web App CI / test (channels shard 3/4) (push) Has been cancelled
Web App CI / test (channels shard 4/4) (push) Has been cancelled
Web App CI / upload-coverage (push) Has been cancelled
Web App CI / build (push) Has been cancelled
YAML Lint / yamllint (push) Has been cancelled
Push mirrored docker images / cd/Push mirrored docker images (push) Has been cancelled
docs-cd / Build and deploy docs (push) Has been cancelled
Docs CI / build (push) Has been cancelled
E2E Cache Warm: Cypress deps / Warm Cypress deps cache (push) Has been cancelled
Scorecards supply-chain security / Scorecard analysis (push) Has been cancelled
Server CI Weekly / Postgres FIPS (push) Has been skipped
Server CI Weekly / Run mmctl tests (FIPS) (push) Has been skipped
Server CI Weekly / Postgres with binary parameters (push) Has been skipped
Server CI Weekly / Build Environment (push) Failing after 1s
Server CI Cache Warm / Warm Go Module and Build Cache (push) Failing after 2s
Server CI Nightly Race / Build Environment (push) Failing after 1s
Some checks failed
Server CI / Postgres (shard 0) (push) Has been skipped
Server CI / Postgres (shard 3) (push) Has been skipped
BuildEnv Docker Image / build-image (push) Failing after 4s
BuildEnv Docker Image / build-image-fips (push) Failing after 4s
Migration Review & Release Notes / Generate migration review & release notes (push) Failing after 3s
Server CI / Build Environment (push) Failing after 3s
Server CI / Postgres (shard 1) (push) Has been skipped
Tools CI / check-style (mattermost-govet) (push) Failing after 4s
Server CI / Postgres (shard 2) (push) Has been skipped
Tools CI / check-style (mmgotool) (push) Failing after 3s
Server CI / Elasticsearch v8 Compatibility (push) Has been skipped
Server CI / OpenSearch v2 Compatibility (push) Has been skipped
Server CI / Postgres FIPS (shard 0) (push) Has been skipped
Tools CI / Test (mattermost-govet) (push) Failing after 3s
Server CI / Postgres FIPS (shard 1) (push) Has been skipped
Server CI / Postgres FIPS (shard 2) (push) Has been skipped
Tools CI / Test (mmgotool) (push) Failing after 3s
Server CI / Postgres FIPS (shard 3) (push) Has been skipped
Server CI / Run mmctl tests (push) Has been skipped
Server CI / Run mmctl tests (FIPS) (push) Has been skipped
Server CI / Merge Postgres Test Results (push) Has been skipped
Server CI / Merge Postgres FIPS Test Results (push) Has been skipped
Server CI / Check backport migrations (push) Has been skipped
Server CI / Check generated files (push) Has been skipped
Server CI / check-style (push) Has been skipped
Server CI / Vet API (push) Has been skipped
Server CI / Build mattermost server app (push) Has been skipped
Server CI / Server CI Complete (push) Failing after 2s
Server CI / Server CI Artifacts (push) Has been skipped
Server CI / Sentry Upload (push) Has been skipped
Server CI / Server CI Report (push) Failing after 5m1s
Server CI Nightly Race / Race Detector (push) Has been skipped
CodeQL / Analyze (go) (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
Webapp CI Cache Warm / Warm Webapp node_modules Cache (push) Has been cancelled
E2E CI Cache Warm / Warm E2E npm Registry Cache (push) Has been cancelled
API / build (push) Has been cancelled
Web App CI / check-types (push) Has been cancelled
Web App CI / check-lint (push) Has been cancelled
Web App CI / check-i18n (push) Has been cancelled
Web App CI / check-external-links (push) Has been cancelled
Web App CI / test (platform) (push) Has been cancelled
Web App CI / test (mattermost-redux) (push) Has been cancelled
Web App CI / test (channels shard 1/4) (push) Has been cancelled
Web App CI / test (channels shard 2/4) (push) Has been cancelled
Web App CI / test (channels shard 3/4) (push) Has been cancelled
Web App CI / test (channels shard 4/4) (push) Has been cancelled
Web App CI / upload-coverage (push) Has been cancelled
Web App CI / build (push) Has been cancelled
YAML Lint / yamllint (push) Has been cancelled
Push mirrored docker images / cd/Push mirrored docker images (push) Has been cancelled
docs-cd / Build and deploy docs (push) Has been cancelled
Docs CI / build (push) Has been cancelled
E2E Cache Warm: Cypress deps / Warm Cypress deps cache (push) Has been cancelled
Scorecards supply-chain security / Scorecard analysis (push) Has been cancelled
Server CI Weekly / Postgres FIPS (push) Has been skipped
Server CI Weekly / Run mmctl tests (FIPS) (push) Has been skipped
Server CI Weekly / Postgres with binary parameters (push) Has been skipped
Server CI Weekly / Build Environment (push) Failing after 1s
Server CI Cache Warm / Warm Go Module and Build Cache (push) Failing after 2s
Server CI Nightly Race / Build Environment (push) Failing after 1s
This commit is contained in:
463
server/channels/app/post_helpers_test.go
Normal file
463
server/channels/app/post_helpers_test.go
Normal file
@@ -0,0 +1,463 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
package app
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/mattermost/mattermost/server/public/model"
|
||||
)
|
||||
|
||||
func TestGetTimeSortedPostAccessibleBounds(t *testing.T) {
|
||||
mainHelper.Parallel(t)
|
||||
postFromCreateAt := func(at int64) *model.Post {
|
||||
return &model.Post{CreateAt: at}
|
||||
}
|
||||
|
||||
getPostListCreateAtFunc := func(pl *model.PostList) func(i int) int64 {
|
||||
return func(i int) int64 {
|
||||
return pl.Posts[pl.Order[i]].CreateAt
|
||||
}
|
||||
}
|
||||
|
||||
t.Run("empty posts returns all accessible posts", func(t *testing.T) {
|
||||
pl := &model.PostList{
|
||||
Posts: map[string]*model.Post{},
|
||||
Order: []string{},
|
||||
}
|
||||
bounds := getTimeSortedPostAccessibleBounds(0, len(pl.Posts), getPostListCreateAtFunc(pl))
|
||||
require.True(t, bounds.allAccessible(len(pl.Posts)))
|
||||
})
|
||||
|
||||
t.Run("one accessible post returns all accessible posts", func(t *testing.T) {
|
||||
pl := &model.PostList{
|
||||
Posts: map[string]*model.Post{
|
||||
"post_a": postFromCreateAt(1),
|
||||
},
|
||||
Order: []string{"post_a"},
|
||||
}
|
||||
bounds := getTimeSortedPostAccessibleBounds(0, len(pl.Posts), getPostListCreateAtFunc(pl))
|
||||
require.True(t, bounds.allAccessible(len(pl.Posts)))
|
||||
})
|
||||
|
||||
t.Run("one inaccessible post returns no accessible posts", func(t *testing.T) {
|
||||
pl := &model.PostList{
|
||||
Posts: map[string]*model.Post{
|
||||
"post_a": postFromCreateAt(0),
|
||||
},
|
||||
Order: []string{"post_a"},
|
||||
}
|
||||
bounds := getTimeSortedPostAccessibleBounds(1, len(pl.Posts), getPostListCreateAtFunc(pl))
|
||||
require.True(t, bounds.noAccessible())
|
||||
})
|
||||
|
||||
t.Run("all accessible posts returns all accessible posts", func(t *testing.T) {
|
||||
pl := &model.PostList{
|
||||
Posts: map[string]*model.Post{
|
||||
"post_a": postFromCreateAt(1),
|
||||
"post_b": postFromCreateAt(2),
|
||||
"post_c": postFromCreateAt(3),
|
||||
"post_d": postFromCreateAt(4),
|
||||
"post_e": postFromCreateAt(5),
|
||||
"post_f": postFromCreateAt(6),
|
||||
},
|
||||
Order: []string{"post_a", "post_b", "post_c", "post_d", "post_e", "post_f"},
|
||||
}
|
||||
bounds := getTimeSortedPostAccessibleBounds(0, len(pl.Posts), getPostListCreateAtFunc(pl))
|
||||
require.True(t, bounds.allAccessible(len(pl.Posts)))
|
||||
})
|
||||
|
||||
t.Run("all inaccessible posts returns all inaccessible posts", func(t *testing.T) {
|
||||
pl := &model.PostList{
|
||||
Posts: map[string]*model.Post{
|
||||
"post_a": postFromCreateAt(1),
|
||||
"post_b": postFromCreateAt(2),
|
||||
"post_c": postFromCreateAt(3),
|
||||
"post_d": postFromCreateAt(4),
|
||||
"post_e": postFromCreateAt(5),
|
||||
"post_f": postFromCreateAt(6),
|
||||
},
|
||||
Order: []string{"post_a", "post_b", "post_c", "post_d", "post_e", "post_f"},
|
||||
}
|
||||
bounds := getTimeSortedPostAccessibleBounds(7, len(pl.Posts), getPostListCreateAtFunc(pl))
|
||||
require.True(t, bounds.noAccessible())
|
||||
})
|
||||
|
||||
t.Run("all accessible posts returns all accessible posts, descending ordered", func(t *testing.T) {
|
||||
pl := &model.PostList{
|
||||
Posts: map[string]*model.Post{
|
||||
"post_a": postFromCreateAt(1),
|
||||
"post_b": postFromCreateAt(2),
|
||||
"post_c": postFromCreateAt(3),
|
||||
"post_d": postFromCreateAt(4),
|
||||
"post_e": postFromCreateAt(5),
|
||||
"post_f": postFromCreateAt(6),
|
||||
},
|
||||
Order: []string{"post_f", "post_e", "post_d", "post_c", "post_b", "post_a"},
|
||||
}
|
||||
bounds := getTimeSortedPostAccessibleBounds(0, len(pl.Posts), getPostListCreateAtFunc(pl))
|
||||
require.True(t, bounds.allAccessible(len(pl.Posts)))
|
||||
})
|
||||
|
||||
t.Run("all inaccessible posts returns all inaccessible posts, descending ordered", func(t *testing.T) {
|
||||
pl := &model.PostList{
|
||||
Posts: map[string]*model.Post{
|
||||
"post_a": postFromCreateAt(1),
|
||||
"post_b": postFromCreateAt(2),
|
||||
"post_c": postFromCreateAt(3),
|
||||
"post_d": postFromCreateAt(4),
|
||||
"post_e": postFromCreateAt(5),
|
||||
"post_f": postFromCreateAt(6),
|
||||
},
|
||||
Order: []string{"post_f", "post_e", "post_d", "post_c", "post_b", "post_a"},
|
||||
}
|
||||
bounds := getTimeSortedPostAccessibleBounds(7, len(pl.Posts), getPostListCreateAtFunc(pl))
|
||||
require.True(t, bounds.noAccessible())
|
||||
})
|
||||
|
||||
t.Run("two posts, first accessible", func(t *testing.T) {
|
||||
pl := &model.PostList{
|
||||
Posts: map[string]*model.Post{
|
||||
"post_a": postFromCreateAt(1),
|
||||
"post_b": postFromCreateAt(0),
|
||||
},
|
||||
Order: []string{"post_a", "post_b"},
|
||||
}
|
||||
bounds := getTimeSortedPostAccessibleBounds(1, len(pl.Posts), getPostListCreateAtFunc(pl))
|
||||
require.Equal(t, accessibleBounds{start: 0, end: 0}, bounds)
|
||||
})
|
||||
|
||||
t.Run("two posts, second accessible", func(t *testing.T) {
|
||||
pl := &model.PostList{
|
||||
Posts: map[string]*model.Post{
|
||||
"post_a": postFromCreateAt(0),
|
||||
"post_b": postFromCreateAt(1),
|
||||
},
|
||||
Order: []string{"post_a", "post_b"},
|
||||
}
|
||||
bounds := getTimeSortedPostAccessibleBounds(1, len(pl.Posts), getPostListCreateAtFunc(pl))
|
||||
require.Equal(t, accessibleBounds{start: 1, end: 1}, bounds)
|
||||
})
|
||||
|
||||
t.Run("picks the left most post for boundaries when there are time ties", func(t *testing.T) {
|
||||
pl := &model.PostList{
|
||||
Posts: map[string]*model.Post{
|
||||
"post_a": postFromCreateAt(0),
|
||||
"post_b": postFromCreateAt(1),
|
||||
"post_c": postFromCreateAt(1),
|
||||
"post_d": postFromCreateAt(2),
|
||||
},
|
||||
Order: []string{"post_a", "post_b", "post_c", "post_d"},
|
||||
}
|
||||
bounds := getTimeSortedPostAccessibleBounds(1, len(pl.Posts), getPostListCreateAtFunc(pl))
|
||||
require.Equal(t, accessibleBounds{start: 1, end: len(pl.Posts) - 1}, bounds)
|
||||
})
|
||||
|
||||
t.Run("picks the right most post for boundaries when there are time ties, descending ordered", func(t *testing.T) {
|
||||
pl := &model.PostList{
|
||||
Posts: map[string]*model.Post{
|
||||
"post_a": postFromCreateAt(0),
|
||||
"post_b": postFromCreateAt(1),
|
||||
"post_c": postFromCreateAt(1),
|
||||
"post_d": postFromCreateAt(2),
|
||||
},
|
||||
Order: []string{"post_d", "post_c", "post_b", "post_a"},
|
||||
}
|
||||
bounds := getTimeSortedPostAccessibleBounds(1, len(pl.Posts), getPostListCreateAtFunc(pl))
|
||||
require.Equal(t, accessibleBounds{start: 0, end: 2}, bounds)
|
||||
})
|
||||
|
||||
t.Run("odd number of posts and reverse time selects right boundaries", func(t *testing.T) {
|
||||
pl := &model.PostList{
|
||||
Posts: map[string]*model.Post{
|
||||
"post_a": postFromCreateAt(0),
|
||||
"post_b": postFromCreateAt(1),
|
||||
"post_c": postFromCreateAt(2),
|
||||
"post_d": postFromCreateAt(3),
|
||||
"post_e": postFromCreateAt(4),
|
||||
},
|
||||
Order: []string{"post_e", "post_d", "post_c", "post_b", "post_a"},
|
||||
}
|
||||
bounds := getTimeSortedPostAccessibleBounds(2, len(pl.Posts), getPostListCreateAtFunc(pl))
|
||||
require.Equal(t, accessibleBounds{start: 0, end: 2}, bounds)
|
||||
})
|
||||
|
||||
t.Run("posts-slice: odd number of posts and reverse time selects right boundaries", func(t *testing.T) {
|
||||
posts := []*model.Post{postFromCreateAt(4), postFromCreateAt(3), postFromCreateAt(2), postFromCreateAt(1), postFromCreateAt(0)}
|
||||
bounds := getTimeSortedPostAccessibleBounds(2, len(posts), func(i int) int64 { return posts[i].CreateAt })
|
||||
require.Equal(t, accessibleBounds{start: 0, end: 2}, bounds)
|
||||
})
|
||||
}
|
||||
|
||||
func TestFilterInaccessiblePosts(t *testing.T) {
|
||||
mainHelper.Parallel(t)
|
||||
th := Setup(t)
|
||||
|
||||
// Set up license with PostHistory limits to enable post filtering
|
||||
cloudLicenseWithLimits := model.NewTestLicense("cloud")
|
||||
cloudLicenseWithLimits.Limits = &model.LicenseLimits{PostHistory: 100}
|
||||
th.App.Srv().SetLicense(cloudLicenseWithLimits)
|
||||
|
||||
err := th.App.Srv().Store().System().Save(&model.System{
|
||||
Name: model.SystemLastAccessiblePostTime,
|
||||
Value: "2",
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
postFromCreateAt := func(at int64) *model.Post {
|
||||
return &model.Post{CreateAt: at}
|
||||
}
|
||||
|
||||
t.Run("ascending order returns correct posts", func(t *testing.T) {
|
||||
postList := &model.PostList{
|
||||
Posts: map[string]*model.Post{
|
||||
"post_a": postFromCreateAt(0),
|
||||
"post_b": postFromCreateAt(1),
|
||||
"post_c": postFromCreateAt(2),
|
||||
"post_d": postFromCreateAt(3),
|
||||
"post_e": postFromCreateAt(4),
|
||||
},
|
||||
Order: []string{"post_a", "post_b", "post_c", "post_d", "post_e"},
|
||||
}
|
||||
appErr := th.App.filterInaccessiblePosts(postList, filterPostOptions{assumeSortedCreatedAt: true})
|
||||
|
||||
require.Nil(t, appErr)
|
||||
|
||||
assert.Equal(t, map[string]*model.Post{
|
||||
"post_c": postFromCreateAt(2),
|
||||
"post_d": postFromCreateAt(3),
|
||||
"post_e": postFromCreateAt(4),
|
||||
}, postList.Posts)
|
||||
|
||||
assert.Equal(t, []string{
|
||||
"post_c",
|
||||
"post_d",
|
||||
"post_e",
|
||||
}, postList.Order)
|
||||
assert.Equal(t, int64(1), postList.FirstInaccessiblePostTime)
|
||||
})
|
||||
|
||||
t.Run("descending order returns correct posts", func(t *testing.T) {
|
||||
postList := &model.PostList{
|
||||
Posts: map[string]*model.Post{
|
||||
"post_a": postFromCreateAt(0),
|
||||
"post_b": postFromCreateAt(1),
|
||||
"post_c": postFromCreateAt(2),
|
||||
"post_d": postFromCreateAt(3),
|
||||
"post_e": postFromCreateAt(4),
|
||||
},
|
||||
Order: []string{"post_e", "post_d", "post_c", "post_b", "post_a"},
|
||||
}
|
||||
appErr := th.App.filterInaccessiblePosts(postList, filterPostOptions{assumeSortedCreatedAt: true})
|
||||
|
||||
require.Nil(t, appErr)
|
||||
|
||||
assert.Equal(t, map[string]*model.Post{
|
||||
"post_c": postFromCreateAt(2),
|
||||
"post_d": postFromCreateAt(3),
|
||||
"post_e": postFromCreateAt(4),
|
||||
}, postList.Posts)
|
||||
|
||||
assert.Equal(t, []string{
|
||||
"post_e",
|
||||
"post_d",
|
||||
"post_c",
|
||||
}, postList.Order)
|
||||
|
||||
assert.Equal(t, int64(1), postList.FirstInaccessiblePostTime)
|
||||
})
|
||||
|
||||
t.Run("handles mixed create at ordering correctly if correct options given", func(t *testing.T) {
|
||||
postList := &model.PostList{
|
||||
Posts: map[string]*model.Post{
|
||||
"post_a": postFromCreateAt(0),
|
||||
"post_b": postFromCreateAt(1),
|
||||
"post_c": postFromCreateAt(2),
|
||||
"post_d": postFromCreateAt(3),
|
||||
"post_e": postFromCreateAt(4),
|
||||
},
|
||||
Order: []string{"post_e", "post_b", "post_a", "post_d", "post_c"},
|
||||
}
|
||||
appErr := th.App.filterInaccessiblePosts(postList, filterPostOptions{assumeSortedCreatedAt: false})
|
||||
|
||||
require.Nil(t, appErr)
|
||||
|
||||
assert.Equal(t, map[string]*model.Post{
|
||||
"post_c": postFromCreateAt(2),
|
||||
"post_d": postFromCreateAt(3),
|
||||
"post_e": postFromCreateAt(4),
|
||||
}, postList.Posts)
|
||||
|
||||
assert.Equal(t, []string{
|
||||
"post_e",
|
||||
"post_d",
|
||||
"post_c",
|
||||
}, postList.Order)
|
||||
})
|
||||
|
||||
t.Run("handles posts missing from order when doing linear search", func(t *testing.T) {
|
||||
postList := &model.PostList{
|
||||
Posts: map[string]*model.Post{
|
||||
"post_a": postFromCreateAt(0),
|
||||
"post_b": postFromCreateAt(1),
|
||||
"post_c": postFromCreateAt(1),
|
||||
"post_d": postFromCreateAt(3),
|
||||
"post_e": postFromCreateAt(4),
|
||||
},
|
||||
Order: []string{"post_e", "post_a", "post_d", "post_b"},
|
||||
}
|
||||
appErr := th.App.filterInaccessiblePosts(postList, filterPostOptions{assumeSortedCreatedAt: false})
|
||||
|
||||
require.Nil(t, appErr)
|
||||
|
||||
assert.Equal(t, map[string]*model.Post{
|
||||
"post_d": postFromCreateAt(3),
|
||||
"post_e": postFromCreateAt(4),
|
||||
}, postList.Posts)
|
||||
|
||||
assert.Equal(t, []string{
|
||||
"post_e",
|
||||
"post_d",
|
||||
}, postList.Order)
|
||||
})
|
||||
}
|
||||
|
||||
func TestGetFilteredAccessiblePosts(t *testing.T) {
|
||||
mainHelper.Parallel(t)
|
||||
th := Setup(t)
|
||||
|
||||
entryLicenseWithLimits := model.NewTestLicenseSKU(model.LicenseShortSkuMattermostEntry)
|
||||
entryLicenseWithLimits.Limits = &model.LicenseLimits{PostHistory: 100}
|
||||
th.App.Srv().SetLicense(entryLicenseWithLimits)
|
||||
|
||||
err := th.App.Srv().Store().System().Save(&model.System{
|
||||
Name: model.SystemLastAccessiblePostTime,
|
||||
Value: "2",
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
postFromCreateAt := func(at int64) *model.Post {
|
||||
return &model.Post{CreateAt: at}
|
||||
}
|
||||
|
||||
t.Run("ascending order returns correct posts", func(t *testing.T) {
|
||||
posts := []*model.Post{postFromCreateAt(0), postFromCreateAt(1), postFromCreateAt(2), postFromCreateAt(3), postFromCreateAt(4)}
|
||||
filteredPosts, firstInaccessiblePostTime, appErr := th.App.getFilteredAccessiblePosts(posts, filterPostOptions{assumeSortedCreatedAt: true})
|
||||
|
||||
assert.Nil(t, appErr)
|
||||
assert.Equal(t, []*model.Post{postFromCreateAt(2), postFromCreateAt(3), postFromCreateAt(4)}, filteredPosts)
|
||||
assert.Equal(t, int64(1), firstInaccessiblePostTime)
|
||||
})
|
||||
|
||||
t.Run("descending order returns correct posts", func(t *testing.T) {
|
||||
posts := []*model.Post{postFromCreateAt(4), postFromCreateAt(3), postFromCreateAt(2), postFromCreateAt(1), postFromCreateAt(0)}
|
||||
filteredPosts, firstInaccessiblePostTime, appErr := th.App.getFilteredAccessiblePosts(posts, filterPostOptions{assumeSortedCreatedAt: true})
|
||||
|
||||
assert.Nil(t, appErr)
|
||||
assert.Equal(t, []*model.Post{postFromCreateAt(4), postFromCreateAt(3), postFromCreateAt(2)}, filteredPosts)
|
||||
assert.Equal(t, int64(1), firstInaccessiblePostTime)
|
||||
})
|
||||
|
||||
t.Run("handles mixed create at ordering correctly if correct options given", func(t *testing.T) {
|
||||
posts := []*model.Post{postFromCreateAt(4), postFromCreateAt(1), postFromCreateAt(0), postFromCreateAt(3), postFromCreateAt(2)}
|
||||
filteredPosts, _, appErr := th.App.getFilteredAccessiblePosts(posts, filterPostOptions{assumeSortedCreatedAt: false})
|
||||
|
||||
assert.Nil(t, appErr)
|
||||
assert.Equal(t, []*model.Post{postFromCreateAt(4), postFromCreateAt(3), postFromCreateAt(2)}, filteredPosts)
|
||||
})
|
||||
}
|
||||
|
||||
func TestIsInaccessiblePost(t *testing.T) {
|
||||
mainHelper.Parallel(t)
|
||||
th := Setup(t)
|
||||
|
||||
// Set up license with PostHistory limits to enable post filtering
|
||||
entryLicenseWithLimits := model.NewTestLicenseSKU(model.LicenseShortSkuMattermostEntry)
|
||||
entryLicenseWithLimits.Limits = &model.LicenseLimits{PostHistory: 100}
|
||||
th.App.Srv().SetLicense(entryLicenseWithLimits)
|
||||
|
||||
err := th.App.Srv().Store().System().Save(&model.System{
|
||||
Name: model.SystemLastAccessiblePostTime,
|
||||
Value: "2",
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
post := &model.Post{CreateAt: 3}
|
||||
firstInaccessiblePostTime, appErr := th.App.isInaccessiblePost(post)
|
||||
assert.Nil(t, appErr)
|
||||
assert.Equal(t, int64(0), firstInaccessiblePostTime)
|
||||
|
||||
post = &model.Post{CreateAt: 1}
|
||||
firstInaccessiblePostTime, appErr = th.App.isInaccessiblePost(post)
|
||||
assert.Nil(t, appErr)
|
||||
assert.Equal(t, int64(1), firstInaccessiblePostTime)
|
||||
}
|
||||
|
||||
func Test_getInaccessibleRange(t *testing.T) {
|
||||
mainHelper.Parallel(t)
|
||||
type test struct {
|
||||
label string
|
||||
bounds accessibleBounds
|
||||
listLength int
|
||||
expectedStart int
|
||||
expectedEnd int
|
||||
}
|
||||
tests := []test{
|
||||
{
|
||||
label: "inaccessible at end",
|
||||
bounds: accessibleBounds{start: 0, end: 3},
|
||||
listLength: 6,
|
||||
expectedStart: 4,
|
||||
expectedEnd: 5,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.label, func(t *testing.T) {
|
||||
start, end := test.bounds.getInaccessibleRange(test.listLength)
|
||||
|
||||
assert.Equal(t, test.expectedStart, start)
|
||||
assert.Equal(t, test.expectedEnd, end)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestRevealBurnOnReadPostsForUser(t *testing.T) {
|
||||
th := Setup(t).InitBasic(t)
|
||||
|
||||
// Enable BurnOnRead feature
|
||||
th.App.Srv().SetLicense(model.NewTestLicenseSKU(model.LicenseShortSkuEnterpriseAdvanced))
|
||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||
cfg.FeatureFlags.BurnOnRead = true
|
||||
cfg.ServiceSettings.EnableBurnOnRead = new(true)
|
||||
})
|
||||
|
||||
t.Run("skips deleted burn-on-read post", func(t *testing.T) {
|
||||
deletedPost := &model.Post{
|
||||
Id: model.NewId(),
|
||||
UserId: th.BasicUser.Id,
|
||||
ChannelId: th.BasicChannel.Id,
|
||||
Message: "deleted burn on read message",
|
||||
Type: model.PostTypeBurnOnRead,
|
||||
DeleteAt: model.GetMillis(),
|
||||
CreateAt: model.GetMillis(),
|
||||
}
|
||||
|
||||
postList := model.NewPostList()
|
||||
postList.AddPost(deletedPost)
|
||||
|
||||
resultList, appErr := th.App.revealBurnOnReadPostsForUser(th.Context, postList, th.BasicUser2.Id)
|
||||
|
||||
require.Nil(t, appErr)
|
||||
require.NotNil(t, resultList)
|
||||
// The deleted post should remain in BurnOnReadPosts but not be processed
|
||||
assert.Contains(t, resultList.BurnOnReadPosts, deletedPost.Id)
|
||||
// Verify the post was not modified (still has DeleteAt set)
|
||||
assert.Equal(t, deletedPost.DeleteAt, resultList.BurnOnReadPosts[deletedPost.Id].DeleteAt)
|
||||
assert.Equal(t, deletedPost.Message, resultList.BurnOnReadPosts[deletedPost.Id].Message)
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user