[MM-55595] Use annotated logger in search layer (#25468)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
5a4dba8809
Коммит
b2ec1ff8ae
@@ -9,6 +9,7 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/mattermost/mattermost/server/public/model"
|
||||
"github.com/mattermost/mattermost/server/public/shared/request"
|
||||
"github.com/mattermost/mattermost/server/v8/channels/store"
|
||||
)
|
||||
|
||||
@@ -77,7 +78,8 @@ var searchChannelStoreTests = []searchTest{
|
||||
|
||||
func TestSearchChannelStore(t *testing.T, s store.Store, testEngine *SearchTestEngine) {
|
||||
th := &SearchTestHelper{
|
||||
Store: s,
|
||||
Context: request.TestContext(t),
|
||||
Store: s,
|
||||
}
|
||||
err := th.SetupBasicFixtures()
|
||||
require.NoError(t, err)
|
||||
@@ -94,11 +96,11 @@ func testAutocompleteChannelByName(t *testing.T, th *SearchTestHelper) {
|
||||
require.NoError(t, err)
|
||||
defer th.deleteChannel(private)
|
||||
|
||||
res, err := th.Store.Channel().AutocompleteInTeam(th.Team.Id, th.User.Id, "channel-a", false, false)
|
||||
res, err := th.Store.Channel().AutocompleteInTeam(th.Context, th.Team.Id, th.User.Id, "channel-a", false, false)
|
||||
require.NoError(t, err)
|
||||
th.checkChannelIdsMatch(t, []string{th.ChannelBasic.Id, alternate.Id, private.Id}, res)
|
||||
|
||||
res2, err := th.Store.Channel().Autocomplete(th.User.Id, "channel-a", false, false)
|
||||
res2, err := th.Store.Channel().Autocomplete(th.Context, th.User.Id, "channel-a", false, false)
|
||||
require.NoError(t, err)
|
||||
th.checkChannelIdsMatchWithTeamData(t, []string{th.ChannelBasic.Id, alternate.Id, private.Id, th.ChannelAnotherTeam.Id}, res2)
|
||||
}
|
||||
@@ -107,7 +109,7 @@ func testAutocompleteChannelByNamePostgres(t *testing.T, th *SearchTestHelper) {
|
||||
alternate, err := th.createChannel(th.Team.Id, "channel-alternate", "Channel Alternate", "Channel Alternate", model.ChannelTypeOpen, th.User, false)
|
||||
require.NoError(t, err)
|
||||
defer th.deleteChannel(alternate)
|
||||
res, err := th.Store.Channel().AutocompleteInTeam(th.Team.Id, th.User.Id, "channel-a", false, false)
|
||||
res, err := th.Store.Channel().AutocompleteInTeam(th.Context, th.Team.Id, th.User.Id, "channel-a", false, false)
|
||||
require.NoError(t, err)
|
||||
th.checkChannelIdsMatch(t, []string{th.ChannelBasic.Id, th.ChannelPrivate.Id, alternate.Id}, res)
|
||||
}
|
||||
@@ -121,11 +123,11 @@ func testAutocompleteChannelByDisplayName(t *testing.T, th *SearchTestHelper) {
|
||||
require.NoError(t, err)
|
||||
defer th.deleteChannel(private)
|
||||
|
||||
res, err := th.Store.Channel().AutocompleteInTeam(th.Team.Id, th.User.Id, "ChannelA", false, false)
|
||||
res, err := th.Store.Channel().AutocompleteInTeam(th.Context, th.Team.Id, th.User.Id, "ChannelA", false, false)
|
||||
require.NoError(t, err)
|
||||
th.checkChannelIdsMatch(t, []string{th.ChannelBasic.Id, alternate.Id, private.Id}, res)
|
||||
|
||||
res2, err := th.Store.Channel().Autocomplete(th.User.Id, "ChannelA", false, false)
|
||||
res2, err := th.Store.Channel().Autocomplete(th.Context, th.User.Id, "ChannelA", false, false)
|
||||
require.NoError(t, err)
|
||||
th.checkChannelIdsMatchWithTeamData(t, []string{th.ChannelBasic.Id, alternate.Id, private.Id, th.ChannelAnotherTeam.Id}, res2)
|
||||
}
|
||||
@@ -134,7 +136,7 @@ func testAutocompleteChannelByNameSplittedWithDashChar(t *testing.T, th *SearchT
|
||||
alternate, err := th.createChannel(th.Team.Id, "channel-alternate", "ChannelAlternate", "", model.ChannelTypeOpen, th.User, false)
|
||||
require.NoError(t, err)
|
||||
defer th.deleteChannel(alternate)
|
||||
res, err := th.Store.Channel().AutocompleteInTeam(th.Team.Id, th.User.Id, "channel-a", false, false)
|
||||
res, err := th.Store.Channel().AutocompleteInTeam(th.Context, th.Team.Id, th.User.Id, "channel-a", false, false)
|
||||
require.NoError(t, err)
|
||||
th.checkChannelIdsMatch(t, []string{th.ChannelBasic.Id, alternate.Id}, res)
|
||||
}
|
||||
@@ -143,7 +145,7 @@ func testAutocompleteChannelByNameSplittedWithDashCharPostgres(t *testing.T, th
|
||||
alternate, err := th.createChannel(th.Team.Id, "channel-alternate", "ChannelAlternate", "", model.ChannelTypeOpen, th.User, false)
|
||||
require.NoError(t, err)
|
||||
defer th.deleteChannel(alternate)
|
||||
res, err := th.Store.Channel().AutocompleteInTeam(th.Team.Id, th.User.Id, "channel-a", false, false)
|
||||
res, err := th.Store.Channel().AutocompleteInTeam(th.Context, th.Team.Id, th.User.Id, "channel-a", false, false)
|
||||
require.NoError(t, err)
|
||||
th.checkChannelIdsMatch(t, []string{th.ChannelBasic.Id, th.ChannelPrivate.Id, alternate.Id}, res)
|
||||
}
|
||||
@@ -152,11 +154,11 @@ func testAutocompleteChannelByNameSplittedWithUnderscoreChar(t *testing.T, th *S
|
||||
alternate, err := th.createChannel(th.Team.Id, "channel_alternate", "ChannelAlternate", "", model.ChannelTypeOpen, th.User, false)
|
||||
require.NoError(t, err)
|
||||
defer th.deleteChannel(alternate)
|
||||
res, err := th.Store.Channel().AutocompleteInTeam(th.Team.Id, th.User.Id, "channel_a", false, false)
|
||||
res, err := th.Store.Channel().AutocompleteInTeam(th.Context, th.Team.Id, th.User.Id, "channel_a", false, false)
|
||||
require.NoError(t, err)
|
||||
th.checkChannelIdsMatch(t, []string{alternate.Id}, res)
|
||||
|
||||
res2, err := th.Store.Channel().Autocomplete(th.User.Id, "channel_a", false, false)
|
||||
res2, err := th.Store.Channel().Autocomplete(th.Context, th.User.Id, "channel_a", false, false)
|
||||
require.NoError(t, err)
|
||||
th.checkChannelIdsMatchWithTeamData(t, []string{alternate.Id}, res2)
|
||||
}
|
||||
@@ -166,7 +168,7 @@ func testAutocompleteChannelByDisplayNameSplittedByWhitespaces(t *testing.T, th
|
||||
require.NoError(t, err)
|
||||
|
||||
defer th.deleteChannel(alternate)
|
||||
res, err := th.Store.Channel().AutocompleteInTeam(th.Team.Id, th.User.Id, "Channel A", false, false)
|
||||
res, err := th.Store.Channel().AutocompleteInTeam(th.Context, th.Team.Id, th.User.Id, "Channel A", false, false)
|
||||
require.NoError(t, err)
|
||||
th.checkChannelIdsMatch(t, []string{alternate.Id}, res)
|
||||
}
|
||||
@@ -177,7 +179,7 @@ func testAutocompleteAllChannelsIfTermIsEmpty(t *testing.T, th *SearchTestHelper
|
||||
require.NoError(t, err)
|
||||
defer th.deleteChannel(alternate)
|
||||
defer th.deleteChannel(other)
|
||||
res, err := th.Store.Channel().AutocompleteInTeam(th.Team.Id, th.User.Id, "", false, false)
|
||||
res, err := th.Store.Channel().AutocompleteInTeam(th.Context, th.Team.Id, th.User.Id, "", false, false)
|
||||
require.NoError(t, err)
|
||||
th.checkChannelIdsMatch(t, []string{th.ChannelBasic.Id, th.ChannelPrivate.Id, alternate.Id, other.Id}, res)
|
||||
}
|
||||
@@ -186,17 +188,17 @@ func testSearchChannelsInCaseInsensitiveManner(t *testing.T, th *SearchTestHelpe
|
||||
alternate, err := th.createChannel(th.Team.Id, "channel-alternate", "ChannelAlternate", "", model.ChannelTypeOpen, th.User, false)
|
||||
require.NoError(t, err)
|
||||
defer th.deleteChannel(alternate)
|
||||
res, err := th.Store.Channel().AutocompleteInTeam(th.Team.Id, th.User.Id, "channela", false, false)
|
||||
res, err := th.Store.Channel().AutocompleteInTeam(th.Context, th.Team.Id, th.User.Id, "channela", false, false)
|
||||
require.NoError(t, err)
|
||||
th.checkChannelIdsMatch(t, []string{th.ChannelBasic.Id, alternate.Id}, res)
|
||||
res, err = th.Store.Channel().AutocompleteInTeam(th.Team.Id, th.User.Id, "ChAnNeL-a", false, false)
|
||||
res, err = th.Store.Channel().AutocompleteInTeam(th.Context, th.Team.Id, th.User.Id, "ChAnNeL-a", false, false)
|
||||
require.NoError(t, err)
|
||||
th.checkChannelIdsMatch(t, []string{th.ChannelBasic.Id, alternate.Id}, res)
|
||||
|
||||
res2, err := th.Store.Channel().Autocomplete(th.User.Id, "channela", false, false)
|
||||
res2, err := th.Store.Channel().Autocomplete(th.Context, th.User.Id, "channela", false, false)
|
||||
require.NoError(t, err)
|
||||
th.checkChannelIdsMatchWithTeamData(t, []string{th.ChannelAnotherTeam.Id, th.ChannelBasic.Id, alternate.Id}, res2)
|
||||
res2, err = th.Store.Channel().Autocomplete(th.User.Id, "ChAnNeL-a", false, false)
|
||||
res2, err = th.Store.Channel().Autocomplete(th.Context, th.User.Id, "ChAnNeL-a", false, false)
|
||||
require.NoError(t, err)
|
||||
th.checkChannelIdsMatchWithTeamData(t, []string{th.ChannelAnotherTeam.Id, th.ChannelBasic.Id, alternate.Id}, res2)
|
||||
}
|
||||
@@ -205,10 +207,10 @@ func testSearchChannelsInCaseInsensitiveMannerPostgres(t *testing.T, th *SearchT
|
||||
alternate, err := th.createChannel(th.Team.Id, "channel-alternate", "ChannelAlternate", "", model.ChannelTypeOpen, th.User, false)
|
||||
require.NoError(t, err)
|
||||
defer th.deleteChannel(alternate)
|
||||
res, err := th.Store.Channel().AutocompleteInTeam(th.Team.Id, th.User.Id, "channela", false, false)
|
||||
res, err := th.Store.Channel().AutocompleteInTeam(th.Context, th.Team.Id, th.User.Id, "channela", false, false)
|
||||
require.NoError(t, err)
|
||||
th.checkChannelIdsMatch(t, []string{th.ChannelBasic.Id, alternate.Id}, res)
|
||||
res, err = th.Store.Channel().AutocompleteInTeam(th.Team.Id, th.User.Id, "ChAnNeL-a", false, false)
|
||||
res, err = th.Store.Channel().AutocompleteInTeam(th.Context, th.Team.Id, th.User.Id, "ChAnNeL-a", false, false)
|
||||
require.NoError(t, err)
|
||||
th.checkChannelIdsMatch(t, []string{th.ChannelBasic.Id, th.ChannelPrivate.Id, alternate.Id}, res)
|
||||
}
|
||||
@@ -217,17 +219,17 @@ func testSearchShouldSupportHavingHyphenAsLastCharacter(t *testing.T, th *Search
|
||||
alternate, err := th.createChannel(th.Team.Id, "channel-alternate", "ChannelAlternate", "", model.ChannelTypeOpen, th.User, false)
|
||||
require.NoError(t, err)
|
||||
defer th.deleteChannel(alternate)
|
||||
res, err := th.Store.Channel().AutocompleteInTeam(th.Team.Id, th.User.Id, "channel-", false, false)
|
||||
res, err := th.Store.Channel().AutocompleteInTeam(th.Context, th.Team.Id, th.User.Id, "channel-", false, false)
|
||||
require.NoError(t, err)
|
||||
th.checkChannelIdsMatch(t, []string{th.ChannelBasic.Id, th.ChannelPrivate.Id, alternate.Id}, res)
|
||||
|
||||
res2, err := th.Store.Channel().Autocomplete(th.User.Id, "channel-", false, false)
|
||||
res2, err := th.Store.Channel().Autocomplete(th.Context, th.User.Id, "channel-", false, false)
|
||||
require.NoError(t, err)
|
||||
th.checkChannelIdsMatchWithTeamData(t, []string{th.ChannelAnotherTeam.Id, th.ChannelBasic.Id, th.ChannelPrivate.Id, alternate.Id}, res2)
|
||||
}
|
||||
|
||||
func testSearchShouldSupportAutocompleteWithArchivedChannels(t *testing.T, th *SearchTestHelper) {
|
||||
res, err := th.Store.Channel().AutocompleteInTeam(th.Team.Id, th.User.Id, "channel-", true, false)
|
||||
res, err := th.Store.Channel().AutocompleteInTeam(th.Context, th.Team.Id, th.User.Id, "channel-", true, false)
|
||||
require.NoError(t, err)
|
||||
th.checkChannelIdsMatch(t, []string{th.ChannelBasic.Id, th.ChannelPrivate.Id, th.ChannelDeleted.Id}, res)
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/mattermost/mattermost/server/public/model"
|
||||
"github.com/mattermost/mattermost/server/public/shared/request"
|
||||
"github.com/mattermost/mattermost/server/v8/channels/store"
|
||||
)
|
||||
|
||||
@@ -186,7 +187,8 @@ var searchFileInfoStoreTests = []searchTest{
|
||||
|
||||
func TestSearchFileInfoStore(t *testing.T, s store.Store, testEngine *SearchTestEngine) {
|
||||
th := &SearchTestHelper{
|
||||
Store: s,
|
||||
Context: request.TestContext(t),
|
||||
Store: s,
|
||||
}
|
||||
err := th.SetupBasicFixtures()
|
||||
require.NoError(t, err)
|
||||
@@ -217,7 +219,7 @@ func testFileInfoSearchFileInfosIncludingDMs(t *testing.T, th *SearchTestHelper)
|
||||
|
||||
t.Run("by-name", func(t *testing.T) {
|
||||
params := &model.SearchParams{Terms: "test"}
|
||||
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.FileInfos, 2)
|
||||
@@ -227,7 +229,7 @@ func testFileInfoSearchFileInfosIncludingDMs(t *testing.T, th *SearchTestHelper)
|
||||
|
||||
t.Run("by-content", func(t *testing.T) {
|
||||
params := &model.SearchParams{Terms: "contenttest"}
|
||||
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.FileInfos, 2)
|
||||
@@ -258,13 +260,13 @@ func testFileInfoSearchFileInfosWithPagination(t *testing.T, th *SearchTestHelpe
|
||||
|
||||
t.Run("by-name", func(t *testing.T) {
|
||||
params := &model.SearchParams{Terms: "test"}
|
||||
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 1)
|
||||
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 1)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.FileInfos, 1)
|
||||
th.checkFileInfoInSearchResults(t, p2.Id, results.FileInfos)
|
||||
|
||||
results, err = th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 1, 1)
|
||||
results, err = th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 1, 1)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.FileInfos, 1)
|
||||
@@ -273,13 +275,13 @@ func testFileInfoSearchFileInfosWithPagination(t *testing.T, th *SearchTestHelpe
|
||||
|
||||
t.Run("by-content", func(t *testing.T) {
|
||||
params := &model.SearchParams{Terms: "contenttest"}
|
||||
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 1)
|
||||
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 1)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.FileInfos, 1)
|
||||
th.checkFileInfoInSearchResults(t, p2.Id, results.FileInfos)
|
||||
|
||||
results, err = th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 1, 1)
|
||||
results, err = th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 1, 1)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.FileInfos, 1)
|
||||
@@ -300,7 +302,7 @@ func testFileInfoSearchExactPhraseInQuotes(t *testing.T, th *SearchTestHelper) {
|
||||
|
||||
t.Run("by-name", func(t *testing.T) {
|
||||
params := &model.SearchParams{Terms: "\"channel test 1 2 3\""}
|
||||
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.FileInfos, 1)
|
||||
@@ -309,7 +311,7 @@ func testFileInfoSearchExactPhraseInQuotes(t *testing.T, th *SearchTestHelper) {
|
||||
|
||||
t.Run("by-content", func(t *testing.T) {
|
||||
params := &model.SearchParams{Terms: "\"channel content test 1 2 3\""}
|
||||
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.FileInfos, 1)
|
||||
@@ -331,7 +333,7 @@ func testFileInfoSearchEmailAddresses(t *testing.T, th *SearchTestHelper) {
|
||||
t.Run("by-name", func(t *testing.T) {
|
||||
t.Run("Should search email addresses enclosed by quotes", func(t *testing.T) {
|
||||
params := &model.SearchParams{Terms: "\"test@test.com\""}
|
||||
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.FileInfos, 1)
|
||||
@@ -340,7 +342,7 @@ func testFileInfoSearchEmailAddresses(t *testing.T, th *SearchTestHelper) {
|
||||
|
||||
t.Run("Should search email addresses without quotes", func(t *testing.T) {
|
||||
params := &model.SearchParams{Terms: "test@test.com"}
|
||||
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.FileInfos, 1)
|
||||
@@ -350,7 +352,7 @@ func testFileInfoSearchEmailAddresses(t *testing.T, th *SearchTestHelper) {
|
||||
t.Run("by-content", func(t *testing.T) {
|
||||
t.Run("Should search email addresses enclosed by quotes", func(t *testing.T) {
|
||||
params := &model.SearchParams{Terms: "\"test@content.com\""}
|
||||
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.FileInfos, 1)
|
||||
@@ -359,7 +361,7 @@ func testFileInfoSearchEmailAddresses(t *testing.T, th *SearchTestHelper) {
|
||||
|
||||
t.Run("Should search email addresses without quotes", func(t *testing.T) {
|
||||
params := &model.SearchParams{Terms: "test@content.com"}
|
||||
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.FileInfos, 1)
|
||||
@@ -379,7 +381,7 @@ func testFileInfoSearchMarkdownUnderscores(t *testing.T, th *SearchTestHelper) {
|
||||
|
||||
t.Run("Should search the start inside the markdown underscore", func(t *testing.T) {
|
||||
params := &model.SearchParams{Terms: "start"}
|
||||
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.FileInfos, 1)
|
||||
@@ -388,7 +390,7 @@ func testFileInfoSearchMarkdownUnderscores(t *testing.T, th *SearchTestHelper) {
|
||||
|
||||
t.Run("Should search a word in the middle of the markdown underscore", func(t *testing.T) {
|
||||
params := &model.SearchParams{Terms: "middle"}
|
||||
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.FileInfos, 1)
|
||||
@@ -397,7 +399,7 @@ func testFileInfoSearchMarkdownUnderscores(t *testing.T, th *SearchTestHelper) {
|
||||
|
||||
t.Run("Should search in the end of the markdown underscore", func(t *testing.T) {
|
||||
params := &model.SearchParams{Terms: "end"}
|
||||
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.FileInfos, 1)
|
||||
@@ -406,7 +408,7 @@ func testFileInfoSearchMarkdownUnderscores(t *testing.T, th *SearchTestHelper) {
|
||||
|
||||
t.Run("Should search inside markdown underscore", func(t *testing.T) {
|
||||
params := &model.SearchParams{Terms: "another"}
|
||||
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.FileInfos, 1)
|
||||
@@ -428,7 +430,7 @@ func testFileInfoSearchNonLatinWords(t *testing.T, th *SearchTestHelper) {
|
||||
|
||||
t.Run("Should search one word", func(t *testing.T) {
|
||||
params := &model.SearchParams{Terms: "你"}
|
||||
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.FileInfos, 1)
|
||||
@@ -436,7 +438,7 @@ func testFileInfoSearchNonLatinWords(t *testing.T, th *SearchTestHelper) {
|
||||
})
|
||||
t.Run("Should search two words", func(t *testing.T) {
|
||||
params := &model.SearchParams{Terms: "你好"}
|
||||
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.FileInfos, 1)
|
||||
@@ -444,7 +446,7 @@ func testFileInfoSearchNonLatinWords(t *testing.T, th *SearchTestHelper) {
|
||||
})
|
||||
t.Run("Should search with wildcard", func(t *testing.T) {
|
||||
params := &model.SearchParams{Terms: "你*"}
|
||||
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.FileInfos, 2)
|
||||
@@ -459,7 +461,7 @@ func testFileInfoSearchNonLatinWords(t *testing.T, th *SearchTestHelper) {
|
||||
|
||||
t.Run("Should search one word", func(t *testing.T) {
|
||||
params := &model.SearchParams{Terms: "слово"}
|
||||
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.FileInfos, 1)
|
||||
@@ -467,7 +469,7 @@ func testFileInfoSearchNonLatinWords(t *testing.T, th *SearchTestHelper) {
|
||||
})
|
||||
t.Run("Should search using wildcard", func(t *testing.T) {
|
||||
params := &model.SearchParams{Terms: "слов*"}
|
||||
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.FileInfos, 1)
|
||||
@@ -484,7 +486,7 @@ func testFileInfoSearchNonLatinWords(t *testing.T, th *SearchTestHelper) {
|
||||
|
||||
t.Run("Should search one word", func(t *testing.T) {
|
||||
params := &model.SearchParams{Terms: "本"}
|
||||
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.FileInfos, 2)
|
||||
@@ -493,7 +495,7 @@ func testFileInfoSearchNonLatinWords(t *testing.T, th *SearchTestHelper) {
|
||||
})
|
||||
t.Run("Should search two words", func(t *testing.T) {
|
||||
params := &model.SearchParams{Terms: "本木"}
|
||||
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.FileInfos, 1)
|
||||
@@ -501,7 +503,7 @@ func testFileInfoSearchNonLatinWords(t *testing.T, th *SearchTestHelper) {
|
||||
})
|
||||
t.Run("Should search with wildcard", func(t *testing.T) {
|
||||
params := &model.SearchParams{Terms: "本*"}
|
||||
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.FileInfos, 2)
|
||||
@@ -519,7 +521,7 @@ func testFileInfoSearchNonLatinWords(t *testing.T, th *SearchTestHelper) {
|
||||
|
||||
t.Run("Should search one word", func(t *testing.T) {
|
||||
params := &model.SearchParams{Terms: "불"}
|
||||
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.FileInfos, 1)
|
||||
@@ -527,7 +529,7 @@ func testFileInfoSearchNonLatinWords(t *testing.T, th *SearchTestHelper) {
|
||||
})
|
||||
t.Run("Should search two words", func(t *testing.T) {
|
||||
params := &model.SearchParams{Terms: "불다"}
|
||||
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.FileInfos, 1)
|
||||
@@ -535,7 +537,7 @@ func testFileInfoSearchNonLatinWords(t *testing.T, th *SearchTestHelper) {
|
||||
})
|
||||
t.Run("Should search with wildcard", func(t *testing.T) {
|
||||
params := &model.SearchParams{Terms: "불*"}
|
||||
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.FileInfos, 2)
|
||||
@@ -557,7 +559,7 @@ func testFileInfoSearchAlternativeSpellings(t *testing.T, th *SearchTestHelper)
|
||||
defer th.deleteUserFileInfos(th.User.Id)
|
||||
|
||||
params := &model.SearchParams{Terms: "Straße"}
|
||||
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.FileInfos, 2)
|
||||
@@ -565,7 +567,7 @@ func testFileInfoSearchAlternativeSpellings(t *testing.T, th *SearchTestHelper)
|
||||
th.checkFileInfoInSearchResults(t, p2.Id, results.FileInfos)
|
||||
|
||||
params = &model.SearchParams{Terms: "Strasse"}
|
||||
results, err = th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err = th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.FileInfos, 2)
|
||||
@@ -585,7 +587,7 @@ func testFileInfoSearchAlternativeSpellingsAccents(t *testing.T, th *SearchTestH
|
||||
defer th.deleteUserFileInfos(th.User.Id)
|
||||
|
||||
params := &model.SearchParams{Terms: "café"}
|
||||
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.FileInfos, 2)
|
||||
@@ -593,7 +595,7 @@ func testFileInfoSearchAlternativeSpellingsAccents(t *testing.T, th *SearchTestH
|
||||
th.checkFileInfoInSearchResults(t, p2.Id, results.FileInfos)
|
||||
|
||||
params = &model.SearchParams{Terms: "café"}
|
||||
results, err = th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err = th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.FileInfos, 2)
|
||||
@@ -601,7 +603,7 @@ func testFileInfoSearchAlternativeSpellingsAccents(t *testing.T, th *SearchTestH
|
||||
th.checkFileInfoInSearchResults(t, p2.Id, results.FileInfos)
|
||||
|
||||
params = &model.SearchParams{Terms: "cafe"}
|
||||
results, err = th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err = th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.FileInfos, 0)
|
||||
@@ -620,7 +622,7 @@ func testFileInfoSearchOrExcludeFileInfosBySpecificUser(t *testing.T, th *Search
|
||||
defer th.deleteUserFileInfos(th.User2.Id)
|
||||
|
||||
params := &model.SearchParams{Terms: "fromuser", FromUsers: []string{th.User.Id}}
|
||||
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.FileInfos, 1)
|
||||
@@ -643,7 +645,7 @@ func testFileInfoSearchOrExcludeFileInfosInChannel(t *testing.T, th *SearchTestH
|
||||
defer th.deleteUserFileInfos(th.User2.Id)
|
||||
|
||||
params := &model.SearchParams{Terms: "fromuser", InChannels: []string{th.ChannelBasic.Id}}
|
||||
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.FileInfos, 1)
|
||||
@@ -678,7 +680,7 @@ func testFileInfoSearchOrExcludeFileInfosInDMGM(t *testing.T, th *SearchTestHelp
|
||||
Terms: "fromuser",
|
||||
InChannels: []string{direct.Id, group.Id},
|
||||
}
|
||||
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.FileInfos, 2)
|
||||
@@ -691,7 +693,7 @@ func testFileInfoSearchOrExcludeFileInfosInDMGM(t *testing.T, th *SearchTestHelp
|
||||
Terms: "fromuser",
|
||||
InChannels: []string{direct.Id},
|
||||
}
|
||||
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.FileInfos, 1)
|
||||
@@ -703,7 +705,7 @@ func testFileInfoSearchOrExcludeFileInfosInDMGM(t *testing.T, th *SearchTestHelp
|
||||
Terms: "fromuser",
|
||||
InChannels: []string{group.Id},
|
||||
}
|
||||
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.FileInfos, 1)
|
||||
@@ -730,7 +732,7 @@ func testFileInfoSearchOrExcludeByExtensions(t *testing.T, th *SearchTestHelper)
|
||||
InChannels: []string{th.ChannelBasic.Id},
|
||||
Extensions: []string{"jpg"},
|
||||
}
|
||||
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.FileInfos, 1)
|
||||
@@ -743,7 +745,7 @@ func testFileInfoSearchOrExcludeByExtensions(t *testing.T, th *SearchTestHelper)
|
||||
InChannels: []string{th.ChannelBasic.Id},
|
||||
Extensions: []string{"jpg", "bmp"},
|
||||
}
|
||||
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.FileInfos, 2)
|
||||
@@ -757,7 +759,7 @@ func testFileInfoSearchOrExcludeByExtensions(t *testing.T, th *SearchTestHelper)
|
||||
InChannels: []string{th.ChannelBasic.Id},
|
||||
ExcludedExtensions: []string{"jpg"},
|
||||
}
|
||||
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.FileInfos, 2)
|
||||
@@ -771,7 +773,7 @@ func testFileInfoSearchOrExcludeByExtensions(t *testing.T, th *SearchTestHelper)
|
||||
InChannels: []string{th.ChannelBasic.Id},
|
||||
ExcludedExtensions: []string{"jpg", "bmp"},
|
||||
}
|
||||
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.FileInfos, 1)
|
||||
@@ -802,7 +804,7 @@ func testFileInfoFilterFilesInSpecificDate(t *testing.T, th *SearchTestHelper) {
|
||||
Terms: "test",
|
||||
OnDate: "2020-03-22",
|
||||
}
|
||||
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.FileInfos, 1)
|
||||
@@ -813,7 +815,7 @@ func testFileInfoFilterFilesInSpecificDate(t *testing.T, th *SearchTestHelper) {
|
||||
Terms: "test",
|
||||
ExcludedDate: "2020-03-22",
|
||||
}
|
||||
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.FileInfos, 2)
|
||||
@@ -845,7 +847,7 @@ func testFileInfoFilterFilesBeforeSpecificDate(t *testing.T, th *SearchTestHelpe
|
||||
Terms: "test",
|
||||
BeforeDate: "2020-03-23",
|
||||
}
|
||||
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.FileInfos, 2)
|
||||
@@ -858,7 +860,7 @@ func testFileInfoFilterFilesBeforeSpecificDate(t *testing.T, th *SearchTestHelpe
|
||||
Terms: "test",
|
||||
ExcludedBeforeDate: "2020-03-23",
|
||||
}
|
||||
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.FileInfos, 1)
|
||||
@@ -889,7 +891,7 @@ func testFileInfoFilterFilesAfterSpecificDate(t *testing.T, th *SearchTestHelper
|
||||
Terms: "test",
|
||||
AfterDate: "2020-03-23",
|
||||
}
|
||||
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.FileInfos, 1)
|
||||
@@ -901,7 +903,7 @@ func testFileInfoFilterFilesAfterSpecificDate(t *testing.T, th *SearchTestHelper
|
||||
Terms: "test",
|
||||
ExcludedAfterDate: "2020-03-23",
|
||||
}
|
||||
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.FileInfos, 2)
|
||||
@@ -930,7 +932,7 @@ func testFileInfoFilterFilesWithATerm(t *testing.T, th *SearchTestHelper) {
|
||||
Terms: "one",
|
||||
ExcludedTerms: "five eight",
|
||||
}
|
||||
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.FileInfos, 1)
|
||||
@@ -942,7 +944,7 @@ func testFileInfoFilterFilesWithATerm(t *testing.T, th *SearchTestHelper) {
|
||||
Terms: "one",
|
||||
ExcludedTerms: "\"eight nine\"",
|
||||
}
|
||||
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.FileInfos, 2)
|
||||
@@ -969,7 +971,7 @@ func testFileInfoSearchUsingBooleanOperators(t *testing.T, th *SearchTestHelper)
|
||||
Terms: "one two",
|
||||
OrTerms: true,
|
||||
}
|
||||
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.FileInfos, 2)
|
||||
@@ -982,7 +984,7 @@ func testFileInfoSearchUsingBooleanOperators(t *testing.T, th *SearchTestHelper)
|
||||
Terms: "one two",
|
||||
OrTerms: false,
|
||||
}
|
||||
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.FileInfos, 1)
|
||||
@@ -1015,7 +1017,7 @@ func testFileInfoSearchUsingCombinedFilters(t *testing.T, th *SearchTestHelper)
|
||||
FromUsers: []string{th.User2.Id},
|
||||
InChannels: []string{th.ChannelPrivate.Id},
|
||||
}
|
||||
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.FileInfos, 1)
|
||||
@@ -1028,7 +1030,7 @@ func testFileInfoSearchUsingCombinedFilters(t *testing.T, th *SearchTestHelper)
|
||||
ExcludedUsers: []string{th.User2.Id},
|
||||
InChannels: []string{th.ChannelPrivate.Id},
|
||||
}
|
||||
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.FileInfos, 1)
|
||||
@@ -1042,7 +1044,7 @@ func testFileInfoSearchUsingCombinedFilters(t *testing.T, th *SearchTestHelper)
|
||||
ExcludedAfterDate: "2020-03-11",
|
||||
InChannels: []string{th.ChannelPrivate.Id},
|
||||
}
|
||||
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.FileInfos, 1)
|
||||
@@ -1054,7 +1056,7 @@ func testFileInfoSearchUsingCombinedFilters(t *testing.T, th *SearchTestHelper)
|
||||
AfterDate: "2020-03-11",
|
||||
ExcludedChannels: []string{th.ChannelPrivate.Id},
|
||||
}
|
||||
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.FileInfos, 1)
|
||||
@@ -1081,7 +1083,7 @@ func testFileInfoSearchIgnoringStopWords(t *testing.T, th *SearchTestHelper) {
|
||||
params := &model.SearchParams{
|
||||
Terms: "the search",
|
||||
}
|
||||
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.FileInfos, 1)
|
||||
@@ -1092,7 +1094,7 @@ func testFileInfoSearchIgnoringStopWords(t *testing.T, th *SearchTestHelper) {
|
||||
params := &model.SearchParams{
|
||||
Terms: "a avoid",
|
||||
}
|
||||
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.FileInfos, 1)
|
||||
@@ -1103,7 +1105,7 @@ func testFileInfoSearchIgnoringStopWords(t *testing.T, th *SearchTestHelper) {
|
||||
params := &model.SearchParams{
|
||||
Terms: "in where you",
|
||||
}
|
||||
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.FileInfos, 1)
|
||||
@@ -1111,14 +1113,14 @@ func testFileInfoSearchIgnoringStopWords(t *testing.T, th *SearchTestHelper) {
|
||||
})
|
||||
|
||||
t.Run("Should avoid stop words 'where', 'is' and 'the'", func(t *testing.T) {
|
||||
results, err := th.Store.FileInfo().Search([]*model.SearchParams{{Terms: "is the car"}}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{{Terms: "is the car"}}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, results.FileInfos, 1)
|
||||
th.checkFileInfoInSearchResults(t, p4.Id, results.FileInfos)
|
||||
})
|
||||
|
||||
t.Run("Should remove all terms and return empty list", func(t *testing.T) {
|
||||
results, err := th.Store.FileInfo().Search([]*model.SearchParams{{Terms: "is the"}}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{{Terms: "is the"}}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
require.Empty(t, results.FileInfos)
|
||||
})
|
||||
@@ -1140,7 +1142,7 @@ func testFileInfoSupportStemming(t *testing.T, th *SearchTestHelper) {
|
||||
params := &model.SearchParams{
|
||||
Terms: "search",
|
||||
}
|
||||
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.FileInfos, 2)
|
||||
@@ -1165,7 +1167,7 @@ func testFileInfoSupportWildcards(t *testing.T, th *SearchTestHelper) {
|
||||
params := &model.SearchParams{
|
||||
Terms: "search*",
|
||||
}
|
||||
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.FileInfos, 2)
|
||||
@@ -1177,7 +1179,7 @@ func testFileInfoSupportWildcards(t *testing.T, th *SearchTestHelper) {
|
||||
params := &model.SearchParams{
|
||||
Terms: "sear* post",
|
||||
}
|
||||
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.FileInfos, 1)
|
||||
@@ -1201,7 +1203,7 @@ func testFileInfoNotSupportPrecedingWildcards(t *testing.T, th *SearchTestHelper
|
||||
params := &model.SearchParams{
|
||||
Terms: "*earch",
|
||||
}
|
||||
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.FileInfos, 0)
|
||||
@@ -1221,7 +1223,7 @@ func testFileInfoSearchDiscardWildcardAlone(t *testing.T, th *SearchTestHelper)
|
||||
params := &model.SearchParams{
|
||||
Terms: "qwerty *",
|
||||
}
|
||||
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.FileInfos, 1)
|
||||
@@ -1243,7 +1245,7 @@ func testFileInfoSupportTermsWithDash(t *testing.T, th *SearchTestHelper) {
|
||||
params := &model.SearchParams{
|
||||
Terms: "term-with-dash",
|
||||
}
|
||||
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.FileInfos, 1)
|
||||
@@ -1254,7 +1256,7 @@ func testFileInfoSupportTermsWithDash(t *testing.T, th *SearchTestHelper) {
|
||||
params := &model.SearchParams{
|
||||
Terms: "\"term-with-dash\"",
|
||||
}
|
||||
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.FileInfos, 1)
|
||||
@@ -1277,7 +1279,7 @@ func testFileInfoSupportTermsWithUnderscore(t *testing.T, th *SearchTestHelper)
|
||||
params := &model.SearchParams{
|
||||
Terms: "term_with_underscore",
|
||||
}
|
||||
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.FileInfos, 1)
|
||||
@@ -1288,7 +1290,7 @@ func testFileInfoSupportTermsWithUnderscore(t *testing.T, th *SearchTestHelper)
|
||||
params := &model.SearchParams{
|
||||
Terms: "\"term_with_underscore\"",
|
||||
}
|
||||
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.FileInfos, 1)
|
||||
@@ -1317,7 +1319,7 @@ func testFileInfoSearchInDeletedOrArchivedChannels(t *testing.T, th *SearchTestH
|
||||
|
||||
t.Run("Doesn't include posts in deleted channels", func(t *testing.T) {
|
||||
params := &model.SearchParams{Terms: "message", IncludeDeletedChannels: false}
|
||||
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.FileInfos, 2)
|
||||
@@ -1327,7 +1329,7 @@ func testFileInfoSearchInDeletedOrArchivedChannels(t *testing.T, th *SearchTestH
|
||||
|
||||
t.Run("Include posts in deleted channels", func(t *testing.T) {
|
||||
params := &model.SearchParams{Terms: "message", IncludeDeletedChannels: true}
|
||||
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.FileInfos, 3)
|
||||
@@ -1338,7 +1340,7 @@ func testFileInfoSearchInDeletedOrArchivedChannels(t *testing.T, th *SearchTestH
|
||||
|
||||
t.Run("Include posts in deleted channels using multiple terms", func(t *testing.T) {
|
||||
params := &model.SearchParams{Terms: "message channel", IncludeDeletedChannels: true}
|
||||
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.FileInfos, 3)
|
||||
@@ -1353,7 +1355,7 @@ func testFileInfoSearchInDeletedOrArchivedChannels(t *testing.T, th *SearchTestH
|
||||
IncludeDeletedChannels: true,
|
||||
OrTerms: true,
|
||||
}
|
||||
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.FileInfos, 3)
|
||||
@@ -1371,7 +1373,7 @@ func testFileInfoSearchInDeletedOrArchivedChannels(t *testing.T, th *SearchTestH
|
||||
Terms: "#hashtag",
|
||||
IncludeDeletedChannels: false,
|
||||
}
|
||||
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params1, params2}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params1, params2}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.Nil(t, results)
|
||||
require.Error(t, err)
|
||||
})
|
||||
@@ -1390,7 +1392,7 @@ func testFileInfoSearchTermsWithDashes(t *testing.T, th *SearchTestHelper) {
|
||||
|
||||
t.Run("Search for terms with dash", func(t *testing.T) {
|
||||
params := &model.SearchParams{Terms: "with-dash-term"}
|
||||
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.FileInfos, 1)
|
||||
@@ -1399,7 +1401,7 @@ func testFileInfoSearchTermsWithDashes(t *testing.T, th *SearchTestHelper) {
|
||||
|
||||
t.Run("Search for terms with quoted dash", func(t *testing.T) {
|
||||
params := &model.SearchParams{Terms: "\"with-dash-term\""}
|
||||
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.FileInfos, 1)
|
||||
@@ -1408,7 +1410,7 @@ func testFileInfoSearchTermsWithDashes(t *testing.T, th *SearchTestHelper) {
|
||||
|
||||
t.Run("Search for multiple terms with one having dash", func(t *testing.T) {
|
||||
params := &model.SearchParams{Terms: "with-dash-term message"}
|
||||
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.FileInfos, 1)
|
||||
@@ -1417,7 +1419,7 @@ func testFileInfoSearchTermsWithDashes(t *testing.T, th *SearchTestHelper) {
|
||||
|
||||
t.Run("Search for multiple OR terms with one having dash", func(t *testing.T) {
|
||||
params := &model.SearchParams{Terms: "with-dash-term message", OrTerms: true}
|
||||
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.FileInfos, 2)
|
||||
@@ -1439,7 +1441,7 @@ func testFileInfoSearchTermsWithDots(t *testing.T, th *SearchTestHelper) {
|
||||
|
||||
t.Run("Search for terms with dots", func(t *testing.T) {
|
||||
params := &model.SearchParams{Terms: "with.dots.term"}
|
||||
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.FileInfos, 1)
|
||||
@@ -1448,7 +1450,7 @@ func testFileInfoSearchTermsWithDots(t *testing.T, th *SearchTestHelper) {
|
||||
|
||||
t.Run("Search for terms with quoted dots", func(t *testing.T) {
|
||||
params := &model.SearchParams{Terms: "\"with.dots.term\""}
|
||||
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.FileInfos, 1)
|
||||
@@ -1457,7 +1459,7 @@ func testFileInfoSearchTermsWithDots(t *testing.T, th *SearchTestHelper) {
|
||||
|
||||
t.Run("Search for multiple terms with one having dots", func(t *testing.T) {
|
||||
params := &model.SearchParams{Terms: "with.dots.term message"}
|
||||
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.FileInfos, 1)
|
||||
@@ -1466,7 +1468,7 @@ func testFileInfoSearchTermsWithDots(t *testing.T, th *SearchTestHelper) {
|
||||
|
||||
t.Run("Search for multiple OR terms with one having dots", func(t *testing.T) {
|
||||
params := &model.SearchParams{Terms: "with.dots.term message", OrTerms: true}
|
||||
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.FileInfos, 2)
|
||||
@@ -1488,7 +1490,7 @@ func testFileInfoSearchTermsWithUnderscores(t *testing.T, th *SearchTestHelper)
|
||||
|
||||
t.Run("Search for terms with underscores", func(t *testing.T) {
|
||||
params := &model.SearchParams{Terms: "with_underscores_term"}
|
||||
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.FileInfos, 1)
|
||||
@@ -1497,7 +1499,7 @@ func testFileInfoSearchTermsWithUnderscores(t *testing.T, th *SearchTestHelper)
|
||||
|
||||
t.Run("Search for terms with quoted underscores", func(t *testing.T) {
|
||||
params := &model.SearchParams{Terms: "\"with_underscores_term\""}
|
||||
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.FileInfos, 1)
|
||||
@@ -1506,7 +1508,7 @@ func testFileInfoSearchTermsWithUnderscores(t *testing.T, th *SearchTestHelper)
|
||||
|
||||
t.Run("Search for multiple terms with one having underscores", func(t *testing.T) {
|
||||
params := &model.SearchParams{Terms: "with_underscores_term message"}
|
||||
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.FileInfos, 1)
|
||||
@@ -1515,7 +1517,7 @@ func testFileInfoSearchTermsWithUnderscores(t *testing.T, th *SearchTestHelper)
|
||||
|
||||
t.Run("Search for multiple OR terms with one having underscores", func(t *testing.T) {
|
||||
params := &model.SearchParams{Terms: "with_underscores_term message", OrTerms: true}
|
||||
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.FileInfos, 2)
|
||||
@@ -1542,7 +1544,7 @@ func testFileInfoSupportStemmingAndWildcards(t *testing.T, th *SearchTestHelper)
|
||||
|
||||
t.Run("Should stem appr", func(t *testing.T) {
|
||||
params := &model.SearchParams{Terms: "appr*"}
|
||||
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.FileInfos, 3)
|
||||
@@ -1553,7 +1555,7 @@ func testFileInfoSupportStemmingAndWildcards(t *testing.T, th *SearchTestHelper)
|
||||
|
||||
t.Run("Should stem approve", func(t *testing.T) {
|
||||
params := &model.SearchParams{Terms: "approve*"}
|
||||
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.FileInfos, 1)
|
||||
@@ -1576,7 +1578,7 @@ func testFileInfoSupportWildcardOutsideQuotes(t *testing.T, th *SearchTestHelper
|
||||
|
||||
t.Run("Should return results without quotes", func(t *testing.T) {
|
||||
params := &model.SearchParams{Terms: "hell*"}
|
||||
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.FileInfos, 2)
|
||||
@@ -1586,7 +1588,7 @@ func testFileInfoSupportWildcardOutsideQuotes(t *testing.T, th *SearchTestHelper
|
||||
|
||||
t.Run("Should return just one result with quotes", func(t *testing.T) {
|
||||
params := &model.SearchParams{Terms: "\"hell\"*"}
|
||||
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.FileInfos, 1)
|
||||
@@ -1604,21 +1606,21 @@ func testFileInfoSlashShouldNotBeCharSeparator(t *testing.T, th *SearchTestHelpe
|
||||
defer th.deleteUserFileInfos(th.User.Id)
|
||||
|
||||
params := &model.SearchParams{Terms: "gamma"}
|
||||
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.FileInfos, 1)
|
||||
th.checkFileInfoInSearchResults(t, p1.Id, results.FileInfos)
|
||||
|
||||
params = &model.SearchParams{Terms: "beta"}
|
||||
results, err = th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err = th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.FileInfos, 1)
|
||||
th.checkFileInfoInSearchResults(t, p1.Id, results.FileInfos)
|
||||
|
||||
params = &model.SearchParams{Terms: "alpha"}
|
||||
results, err = th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err = th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.FileInfos, 1)
|
||||
@@ -1637,7 +1639,7 @@ func testFileInfoSearchEmailsWithoutQuotes(t *testing.T, th *SearchTestHelper) {
|
||||
defer th.deleteUserFileInfos(th.User.Id)
|
||||
|
||||
params := &model.SearchParams{Terms: "test@test.com"}
|
||||
results, err := th.Store.FileInfo().Search([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.FileInfos, 1)
|
||||
|
||||
@@ -12,10 +12,12 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/mattermost/mattermost/server/public/model"
|
||||
"github.com/mattermost/mattermost/server/public/shared/request"
|
||||
"github.com/mattermost/mattermost/server/v8/channels/store"
|
||||
)
|
||||
|
||||
type SearchTestHelper struct {
|
||||
Context *request.Context
|
||||
Store store.Store
|
||||
Team *model.Team
|
||||
AnotherTeam *model.Team
|
||||
@@ -293,7 +295,7 @@ func (th *SearchTestHelper) createDirectChannel(teamID, displayName string, user
|
||||
m2.UserId = users[1].Id
|
||||
m2.NotifyProps = model.GetDefaultChannelNotifyProps()
|
||||
|
||||
channel, err := th.Store.Channel().SaveDirectChannel(channel, m1, m2)
|
||||
channel, err := th.Store.Channel().SaveDirectChannel(th.Context, channel, m1, m2)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -329,12 +331,12 @@ func (th *SearchTestHelper) createGroupChannel(teamID, displayName string, users
|
||||
}
|
||||
|
||||
func (th *SearchTestHelper) deleteChannel(channel *model.Channel) error {
|
||||
err := th.Store.Channel().PermanentDeleteMembersByChannel(channel.Id)
|
||||
err := th.Store.Channel().PermanentDeleteMembersByChannel(th.Context, channel.Id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return th.Store.Channel().PermanentDelete(channel.Id)
|
||||
return th.Store.Channel().PermanentDelete(th.Context, channel.Id)
|
||||
}
|
||||
|
||||
func (th *SearchTestHelper) deleteChannels(channels []*model.Channel) error {
|
||||
@@ -393,7 +395,7 @@ func (th *SearchTestHelper) createFileInfo(creatorID, postID, channelID, name, c
|
||||
creationTime = createAt
|
||||
}
|
||||
fileInfoModel := th.createFileInfoModel(creatorID, postID, channelID, name, content, extension, mimeType, creationTime, size)
|
||||
return th.Store.FileInfo().Save(fileInfoModel)
|
||||
return th.Store.FileInfo().Save(th.Context, fileInfoModel)
|
||||
}
|
||||
|
||||
func (th *SearchTestHelper) createReply(userID, message, hashtags string, parent *model.Post, createAt int64, pinned bool) (*model.Post, error) {
|
||||
@@ -403,7 +405,7 @@ func (th *SearchTestHelper) createReply(userID, message, hashtags string, parent
|
||||
}
|
||||
|
||||
func (th *SearchTestHelper) deleteUserPosts(userID string) error {
|
||||
err := th.Store.Post().PermanentDeleteByUser(userID)
|
||||
err := th.Store.Post().PermanentDeleteByUser(th.Context, userID)
|
||||
if err != nil {
|
||||
return errors.New(err.Error())
|
||||
}
|
||||
@@ -411,7 +413,7 @@ func (th *SearchTestHelper) deleteUserPosts(userID string) error {
|
||||
}
|
||||
|
||||
func (th *SearchTestHelper) deleteUserFileInfos(userID string) error {
|
||||
if _, err := th.Store.FileInfo().PermanentDeleteByUser(userID); err != nil {
|
||||
if _, err := th.Store.FileInfo().PermanentDeleteByUser(th.Context, userID); err != nil {
|
||||
return errors.New(err.Error())
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/mattermost/mattermost/server/public/model"
|
||||
"github.com/mattermost/mattermost/server/public/shared/request"
|
||||
"github.com/mattermost/mattermost/server/v8/channels/store"
|
||||
)
|
||||
|
||||
@@ -278,7 +279,8 @@ var searchPostStoreTests = []searchTest{
|
||||
|
||||
func TestSearchPostStore(t *testing.T, s store.Store, testEngine *SearchTestEngine) {
|
||||
th := &SearchTestHelper{
|
||||
Store: s,
|
||||
Context: request.TestContext(t),
|
||||
Store: s,
|
||||
}
|
||||
err := th.SetupBasicFixtures()
|
||||
require.NoError(t, err)
|
||||
@@ -301,7 +303,7 @@ func testSearchPostsIncludingDMs(t *testing.T, th *SearchTestHelper) {
|
||||
defer th.deleteUserPosts(th.User.Id)
|
||||
|
||||
params := &model.SearchParams{Terms: "test"}
|
||||
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.Posts, 2)
|
||||
@@ -323,13 +325,13 @@ func testSearchPostsWithPagination(t *testing.T, th *SearchTestHelper) {
|
||||
defer th.deleteUserPosts(th.User.Id)
|
||||
|
||||
params := &model.SearchParams{Terms: "test"}
|
||||
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 1)
|
||||
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 1)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.Posts, 1)
|
||||
th.checkPostInSearchResults(t, p2.Id, results.Posts)
|
||||
|
||||
results, err = th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 1, 1)
|
||||
results, err = th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 1, 1)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.Posts, 1)
|
||||
@@ -344,7 +346,7 @@ func testSearchReturnPinnedAndUnpinned(t *testing.T, th *SearchTestHelper) {
|
||||
defer th.deleteUserPosts(th.User.Id)
|
||||
|
||||
params := &model.SearchParams{Terms: "test"}
|
||||
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.Posts, 2)
|
||||
@@ -444,7 +446,7 @@ func testSearchANDORQuotesCombinations(t *testing.T, th *SearchTestHelper) {
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
params := &model.SearchParams{Terms: tc.terms, OrTerms: tc.orTerms}
|
||||
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.Posts, tc.expectedLen)
|
||||
@@ -464,7 +466,7 @@ func testSearchEmailAddresses(t *testing.T, th *SearchTestHelper) {
|
||||
|
||||
t.Run("Should search email addresses enclosed by quotes", func(t *testing.T) {
|
||||
params := &model.SearchParams{Terms: "\"test@test.com\""}
|
||||
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.Posts, 1)
|
||||
@@ -473,7 +475,7 @@ func testSearchEmailAddresses(t *testing.T, th *SearchTestHelper) {
|
||||
|
||||
t.Run("Should search email addresses without quotes", func(t *testing.T) {
|
||||
params := &model.SearchParams{Terms: "test@test.com"}
|
||||
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.Posts, 1)
|
||||
@@ -489,7 +491,7 @@ func testSearchEmailAddressesWithQuotes(t *testing.T, th *SearchTestHelper) {
|
||||
defer th.deleteUserPosts(th.User.Id)
|
||||
|
||||
params := &model.SearchParams{Terms: "\"test@test.com\""}
|
||||
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.Posts, 1)
|
||||
@@ -503,7 +505,7 @@ func testSearchMarkdownUnderscores(t *testing.T, th *SearchTestHelper) {
|
||||
|
||||
t.Run("Should search the start inside the markdown underscore", func(t *testing.T) {
|
||||
params := &model.SearchParams{Terms: "start"}
|
||||
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.Posts, 1)
|
||||
@@ -512,7 +514,7 @@ func testSearchMarkdownUnderscores(t *testing.T, th *SearchTestHelper) {
|
||||
|
||||
t.Run("Should search a word in the middle of the markdown underscore", func(t *testing.T) {
|
||||
params := &model.SearchParams{Terms: "middle"}
|
||||
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.Posts, 1)
|
||||
@@ -521,7 +523,7 @@ func testSearchMarkdownUnderscores(t *testing.T, th *SearchTestHelper) {
|
||||
|
||||
t.Run("Should search in the end of the markdown underscore", func(t *testing.T) {
|
||||
params := &model.SearchParams{Terms: "end"}
|
||||
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.Posts, 1)
|
||||
@@ -530,7 +532,7 @@ func testSearchMarkdownUnderscores(t *testing.T, th *SearchTestHelper) {
|
||||
|
||||
t.Run("Should search inside markdown underscore", func(t *testing.T) {
|
||||
params := &model.SearchParams{Terms: "another"}
|
||||
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.Posts, 1)
|
||||
@@ -548,7 +550,7 @@ func testSearchNonLatinWords(t *testing.T, th *SearchTestHelper) {
|
||||
|
||||
t.Run("Should search one word", func(t *testing.T) {
|
||||
params := &model.SearchParams{Terms: "你"}
|
||||
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.Posts, 1)
|
||||
@@ -556,7 +558,7 @@ func testSearchNonLatinWords(t *testing.T, th *SearchTestHelper) {
|
||||
})
|
||||
t.Run("Should search two words", func(t *testing.T) {
|
||||
params := &model.SearchParams{Terms: "你好"}
|
||||
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.Posts, 1)
|
||||
@@ -564,7 +566,7 @@ func testSearchNonLatinWords(t *testing.T, th *SearchTestHelper) {
|
||||
})
|
||||
t.Run("Should search with wildcard", func(t *testing.T) {
|
||||
params := &model.SearchParams{Terms: "你*"}
|
||||
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.Posts, 2)
|
||||
@@ -579,7 +581,7 @@ func testSearchNonLatinWords(t *testing.T, th *SearchTestHelper) {
|
||||
|
||||
t.Run("Should search one word", func(t *testing.T) {
|
||||
params := &model.SearchParams{Terms: "слово"}
|
||||
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.Posts, 1)
|
||||
@@ -587,7 +589,7 @@ func testSearchNonLatinWords(t *testing.T, th *SearchTestHelper) {
|
||||
})
|
||||
t.Run("Should search using wildcard", func(t *testing.T) {
|
||||
params := &model.SearchParams{Terms: "слов*"}
|
||||
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.Posts, 1)
|
||||
@@ -604,7 +606,7 @@ func testSearchNonLatinWords(t *testing.T, th *SearchTestHelper) {
|
||||
|
||||
t.Run("Should search one word", func(t *testing.T) {
|
||||
params := &model.SearchParams{Terms: "本"}
|
||||
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.Posts, 2)
|
||||
@@ -613,7 +615,7 @@ func testSearchNonLatinWords(t *testing.T, th *SearchTestHelper) {
|
||||
})
|
||||
t.Run("Should search two words", func(t *testing.T) {
|
||||
params := &model.SearchParams{Terms: "本木"}
|
||||
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.Posts, 1)
|
||||
@@ -621,7 +623,7 @@ func testSearchNonLatinWords(t *testing.T, th *SearchTestHelper) {
|
||||
})
|
||||
t.Run("Should search with wildcard", func(t *testing.T) {
|
||||
params := &model.SearchParams{Terms: "本*"}
|
||||
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.Posts, 2)
|
||||
@@ -639,7 +641,7 @@ func testSearchNonLatinWords(t *testing.T, th *SearchTestHelper) {
|
||||
|
||||
t.Run("Should search one word", func(t *testing.T) {
|
||||
params := &model.SearchParams{Terms: "불"}
|
||||
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.Posts, 1)
|
||||
@@ -647,7 +649,7 @@ func testSearchNonLatinWords(t *testing.T, th *SearchTestHelper) {
|
||||
})
|
||||
t.Run("Should search two words", func(t *testing.T) {
|
||||
params := &model.SearchParams{Terms: "불다"}
|
||||
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.Posts, 1)
|
||||
@@ -655,7 +657,7 @@ func testSearchNonLatinWords(t *testing.T, th *SearchTestHelper) {
|
||||
})
|
||||
t.Run("Should search with wildcard", func(t *testing.T) {
|
||||
params := &model.SearchParams{Terms: "불*"}
|
||||
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.Posts, 2)
|
||||
@@ -673,7 +675,7 @@ func testSearchAlternativeSpellings(t *testing.T, th *SearchTestHelper) {
|
||||
defer th.deleteUserPosts(th.User.Id)
|
||||
|
||||
params := &model.SearchParams{Terms: "Straße"}
|
||||
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.Posts, 2)
|
||||
@@ -681,7 +683,7 @@ func testSearchAlternativeSpellings(t *testing.T, th *SearchTestHelper) {
|
||||
th.checkPostInSearchResults(t, p2.Id, results.Posts)
|
||||
|
||||
params = &model.SearchParams{Terms: "Strasse"}
|
||||
results, err = th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err = th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.Posts, 2)
|
||||
@@ -697,7 +699,7 @@ func testSearchAlternativeSpellingsAccents(t *testing.T, th *SearchTestHelper) {
|
||||
defer th.deleteUserPosts(th.User.Id)
|
||||
|
||||
params := &model.SearchParams{Terms: "café"}
|
||||
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.Posts, 2)
|
||||
@@ -705,7 +707,7 @@ func testSearchAlternativeSpellingsAccents(t *testing.T, th *SearchTestHelper) {
|
||||
th.checkPostInSearchResults(t, p2.Id, results.Posts)
|
||||
|
||||
params = &model.SearchParams{Terms: "café"}
|
||||
results, err = th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err = th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.Posts, 2)
|
||||
@@ -713,7 +715,7 @@ func testSearchAlternativeSpellingsAccents(t *testing.T, th *SearchTestHelper) {
|
||||
th.checkPostInSearchResults(t, p2.Id, results.Posts)
|
||||
|
||||
params = &model.SearchParams{Terms: "cafe"}
|
||||
results, err = th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err = th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.Posts, 0)
|
||||
@@ -731,7 +733,7 @@ func testSearchOrExcludePostsBySpecificUser(t *testing.T, th *SearchTestHelper)
|
||||
Terms: "fromuser",
|
||||
FromUsers: []string{th.User.Id},
|
||||
}
|
||||
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.Posts, 1)
|
||||
@@ -750,7 +752,7 @@ func testSearchOrExcludePostsInChannel(t *testing.T, th *SearchTestHelper) {
|
||||
Terms: "fromuser",
|
||||
InChannels: []string{th.ChannelBasic.Id},
|
||||
}
|
||||
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.Posts, 1)
|
||||
@@ -778,7 +780,7 @@ func testSearchOrExcludePostsInDMGM(t *testing.T, th *SearchTestHelper) {
|
||||
Terms: "fromuser",
|
||||
InChannels: []string{direct.Id, group.Id},
|
||||
}
|
||||
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.Posts, 2)
|
||||
@@ -791,7 +793,7 @@ func testSearchOrExcludePostsInDMGM(t *testing.T, th *SearchTestHelper) {
|
||||
Terms: "fromuser",
|
||||
InChannels: []string{direct.Id},
|
||||
}
|
||||
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.Posts, 1)
|
||||
@@ -803,7 +805,7 @@ func testSearchOrExcludePostsInDMGM(t *testing.T, th *SearchTestHelper) {
|
||||
Terms: "fromuser",
|
||||
InChannels: []string{group.Id},
|
||||
}
|
||||
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.Posts, 1)
|
||||
@@ -828,7 +830,7 @@ func testFilterMessagesInSpecificDate(t *testing.T, th *SearchTestHelper) {
|
||||
Terms: "test",
|
||||
OnDate: "2020-03-22",
|
||||
}
|
||||
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.Posts, 1)
|
||||
@@ -839,7 +841,7 @@ func testFilterMessagesInSpecificDate(t *testing.T, th *SearchTestHelper) {
|
||||
Terms: "test",
|
||||
ExcludedDate: "2020-03-22",
|
||||
}
|
||||
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.Posts, 2)
|
||||
@@ -865,7 +867,7 @@ func testFilterMessagesBeforeSpecificDate(t *testing.T, th *SearchTestHelper) {
|
||||
Terms: "test",
|
||||
BeforeDate: "2020-03-23",
|
||||
}
|
||||
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.Posts, 2)
|
||||
@@ -878,7 +880,7 @@ func testFilterMessagesBeforeSpecificDate(t *testing.T, th *SearchTestHelper) {
|
||||
Terms: "test",
|
||||
ExcludedBeforeDate: "2020-03-23",
|
||||
}
|
||||
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.Posts, 1)
|
||||
@@ -903,7 +905,7 @@ func testFilterMessagesAfterSpecificDate(t *testing.T, th *SearchTestHelper) {
|
||||
Terms: "test",
|
||||
AfterDate: "2020-03-23",
|
||||
}
|
||||
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.Posts, 1)
|
||||
@@ -915,7 +917,7 @@ func testFilterMessagesAfterSpecificDate(t *testing.T, th *SearchTestHelper) {
|
||||
Terms: "test",
|
||||
ExcludedAfterDate: "2020-03-23",
|
||||
}
|
||||
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.Posts, 2)
|
||||
@@ -938,7 +940,7 @@ func testFilterMessagesWithATerm(t *testing.T, th *SearchTestHelper) {
|
||||
Terms: "one",
|
||||
ExcludedTerms: "five eight",
|
||||
}
|
||||
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.Posts, 1)
|
||||
@@ -950,7 +952,7 @@ func testFilterMessagesWithATerm(t *testing.T, th *SearchTestHelper) {
|
||||
Terms: "one",
|
||||
ExcludedTerms: "\"eight nine\"",
|
||||
}
|
||||
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.Posts, 2)
|
||||
@@ -973,7 +975,7 @@ func testSearchUsingBooleanOperators(t *testing.T, th *SearchTestHelper) {
|
||||
Terms: "one two",
|
||||
OrTerms: true,
|
||||
}
|
||||
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.Posts, 2)
|
||||
@@ -986,7 +988,7 @@ func testSearchUsingBooleanOperators(t *testing.T, th *SearchTestHelper) {
|
||||
Terms: "one two",
|
||||
OrTerms: false,
|
||||
}
|
||||
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.Posts, 1)
|
||||
@@ -1013,7 +1015,7 @@ func testSearchUsingCombinedFilters(t *testing.T, th *SearchTestHelper) {
|
||||
FromUsers: []string{th.User2.Id},
|
||||
InChannels: []string{th.ChannelPrivate.Id},
|
||||
}
|
||||
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.Posts, 1)
|
||||
@@ -1026,7 +1028,7 @@ func testSearchUsingCombinedFilters(t *testing.T, th *SearchTestHelper) {
|
||||
ExcludedUsers: []string{th.User2.Id},
|
||||
InChannels: []string{th.ChannelPrivate.Id},
|
||||
}
|
||||
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.Posts, 1)
|
||||
@@ -1040,7 +1042,7 @@ func testSearchUsingCombinedFilters(t *testing.T, th *SearchTestHelper) {
|
||||
ExcludedAfterDate: "2020-03-11",
|
||||
InChannels: []string{th.ChannelPrivate.Id},
|
||||
}
|
||||
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.Posts, 1)
|
||||
@@ -1052,7 +1054,7 @@ func testSearchUsingCombinedFilters(t *testing.T, th *SearchTestHelper) {
|
||||
AfterDate: "2020-03-11",
|
||||
ExcludedChannels: []string{th.ChannelPrivate.Id},
|
||||
}
|
||||
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.Posts, 1)
|
||||
@@ -1075,7 +1077,7 @@ func testSearchIgnoringStopWords(t *testing.T, th *SearchTestHelper) {
|
||||
params := &model.SearchParams{
|
||||
Terms: "the search",
|
||||
}
|
||||
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.Posts, 1)
|
||||
@@ -1086,7 +1088,7 @@ func testSearchIgnoringStopWords(t *testing.T, th *SearchTestHelper) {
|
||||
params := &model.SearchParams{
|
||||
Terms: "a avoid",
|
||||
}
|
||||
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.Posts, 1)
|
||||
@@ -1097,7 +1099,7 @@ func testSearchIgnoringStopWords(t *testing.T, th *SearchTestHelper) {
|
||||
params := &model.SearchParams{
|
||||
Terms: "in where you",
|
||||
}
|
||||
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.Posts, 1)
|
||||
@@ -1130,7 +1132,7 @@ func testSupportStemming(t *testing.T, th *SearchTestHelper) {
|
||||
params := &model.SearchParams{
|
||||
Terms: "search",
|
||||
}
|
||||
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.Posts, 2)
|
||||
@@ -1151,7 +1153,7 @@ func testSupportWildcards(t *testing.T, th *SearchTestHelper) {
|
||||
params := &model.SearchParams{
|
||||
Terms: "search*",
|
||||
}
|
||||
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.Posts, 2)
|
||||
@@ -1163,7 +1165,7 @@ func testSupportWildcards(t *testing.T, th *SearchTestHelper) {
|
||||
params := &model.SearchParams{
|
||||
Terms: "sear* post",
|
||||
}
|
||||
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.Posts, 1)
|
||||
@@ -1183,7 +1185,7 @@ func testNotSupportPrecedingWildcards(t *testing.T, th *SearchTestHelper) {
|
||||
params := &model.SearchParams{
|
||||
Terms: "*earch",
|
||||
}
|
||||
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.Posts, 0)
|
||||
@@ -1199,7 +1201,7 @@ func testSearchDiscardWildcardAlone(t *testing.T, th *SearchTestHelper) {
|
||||
params := &model.SearchParams{
|
||||
Terms: "qwerty *",
|
||||
}
|
||||
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.Posts, 1)
|
||||
@@ -1217,7 +1219,7 @@ func testSupportTermsWithDash(t *testing.T, th *SearchTestHelper) {
|
||||
params := &model.SearchParams{
|
||||
Terms: "term-with-dash",
|
||||
}
|
||||
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.Posts, 1)
|
||||
@@ -1228,7 +1230,7 @@ func testSupportTermsWithDash(t *testing.T, th *SearchTestHelper) {
|
||||
params := &model.SearchParams{
|
||||
Terms: "\"term-with-dash\"",
|
||||
}
|
||||
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.Posts, 1)
|
||||
@@ -1247,7 +1249,7 @@ func testSupportTermsWithUnderscore(t *testing.T, th *SearchTestHelper) {
|
||||
params := &model.SearchParams{
|
||||
Terms: "term_with_underscore",
|
||||
}
|
||||
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.Posts, 1)
|
||||
@@ -1258,7 +1260,7 @@ func testSupportTermsWithUnderscore(t *testing.T, th *SearchTestHelper) {
|
||||
params := &model.SearchParams{
|
||||
Terms: "\"term_with_underscore\"",
|
||||
}
|
||||
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.Posts, 1)
|
||||
@@ -1280,7 +1282,7 @@ func testSearchOrExcludePostsWithHashtags(t *testing.T, th *SearchTestHelper) {
|
||||
Terms: "#hashtag",
|
||||
IsHashtag: true,
|
||||
}
|
||||
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.Posts, 2)
|
||||
@@ -1293,7 +1295,7 @@ func testSearchOrExcludePostsWithHashtags(t *testing.T, th *SearchTestHelper) {
|
||||
Terms: "#hashtag",
|
||||
IsHashtag: false,
|
||||
}
|
||||
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.Posts, 2)
|
||||
@@ -1319,7 +1321,7 @@ func testSearchHashtagWithMarkdown(t *testing.T, th *SearchTestHelper) {
|
||||
Terms: "#hashtag",
|
||||
IsHashtag: true,
|
||||
}
|
||||
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.Posts, 5)
|
||||
@@ -1342,7 +1344,7 @@ func testSearchWithMultipleHashtags(t *testing.T, th *SearchTestHelper) {
|
||||
Terms: "#hashone #hashtwo",
|
||||
IsHashtag: true,
|
||||
}
|
||||
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.Posts, 1)
|
||||
@@ -1355,7 +1357,7 @@ func testSearchWithMultipleHashtags(t *testing.T, th *SearchTestHelper) {
|
||||
IsHashtag: true,
|
||||
OrTerms: true,
|
||||
}
|
||||
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.Posts, 2)
|
||||
@@ -1373,7 +1375,7 @@ func testSearchPostsWithDotsInHashtags(t *testing.T, th *SearchTestHelper) {
|
||||
Terms: "#hashtag.dot",
|
||||
IsHashtag: true,
|
||||
}
|
||||
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.Posts, 1)
|
||||
@@ -1394,7 +1396,7 @@ func testSearchHashtagCaseInsensitive(t *testing.T, th *SearchTestHelper) {
|
||||
Terms: "#hashtag",
|
||||
IsHashtag: true,
|
||||
}
|
||||
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.Posts, 3)
|
||||
@@ -1408,7 +1410,7 @@ func testSearchHashtagCaseInsensitive(t *testing.T, th *SearchTestHelper) {
|
||||
Terms: "#HASHTAG",
|
||||
IsHashtag: true,
|
||||
}
|
||||
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.Posts, 3)
|
||||
@@ -1422,7 +1424,7 @@ func testSearchHashtagCaseInsensitive(t *testing.T, th *SearchTestHelper) {
|
||||
Terms: "#HaShTaG",
|
||||
IsHashtag: true,
|
||||
}
|
||||
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.Posts, 3)
|
||||
@@ -1443,7 +1445,7 @@ func testSearchHashtagWithDash(t *testing.T, th *SearchTestHelper) {
|
||||
Terms: "#hashtag-test",
|
||||
IsHashtag: true,
|
||||
}
|
||||
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.Posts, 1)
|
||||
@@ -1461,7 +1463,7 @@ func testSearchHashtagWithNumbers(t *testing.T, th *SearchTestHelper) {
|
||||
Terms: "#h4sht4g",
|
||||
IsHashtag: true,
|
||||
}
|
||||
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.Posts, 1)
|
||||
@@ -1479,7 +1481,7 @@ func testSearchHashtagWithDots(t *testing.T, th *SearchTestHelper) {
|
||||
Terms: "#hashtag.test",
|
||||
IsHashtag: true,
|
||||
}
|
||||
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.Posts, 1)
|
||||
@@ -1497,7 +1499,7 @@ func testSearchHashtagWithUnderscores(t *testing.T, th *SearchTestHelper) {
|
||||
Terms: "#hashtag_test",
|
||||
IsHashtag: true,
|
||||
}
|
||||
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.Posts, 1)
|
||||
@@ -1519,7 +1521,7 @@ func testSearchHashtagWithDashAndNumbers(t *testing.T, th *SearchTestHelper) {
|
||||
Terms: "#hashtag-1-finals23",
|
||||
IsHashtag: true,
|
||||
}
|
||||
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.Posts, 2)
|
||||
@@ -1543,7 +1545,7 @@ func testSearchShouldExcludeSystemMessages(t *testing.T, th *SearchTestHelper) {
|
||||
defer th.deleteUserPosts(th.User.Id)
|
||||
|
||||
params := &model.SearchParams{Terms: "test system"}
|
||||
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.Posts, 0)
|
||||
@@ -1559,7 +1561,7 @@ func testSearchShouldBeAbleToMatchByMentions(t *testing.T, th *SearchTestHelper)
|
||||
defer th.deleteUserPosts(th.User.Id)
|
||||
|
||||
params := &model.SearchParams{Terms: "@testuser"}
|
||||
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.Posts, 3)
|
||||
@@ -1579,7 +1581,7 @@ func testSearchInDeletedOrArchivedChannels(t *testing.T, th *SearchTestHelper) {
|
||||
|
||||
t.Run("Doesn't include posts in deleted channels", func(t *testing.T) {
|
||||
params := &model.SearchParams{Terms: "message", IncludeDeletedChannels: false}
|
||||
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.Posts, 2)
|
||||
@@ -1589,7 +1591,7 @@ func testSearchInDeletedOrArchivedChannels(t *testing.T, th *SearchTestHelper) {
|
||||
|
||||
t.Run("Include posts in deleted channels", func(t *testing.T) {
|
||||
params := &model.SearchParams{Terms: "message", IncludeDeletedChannels: true}
|
||||
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.Posts, 3)
|
||||
@@ -1600,7 +1602,7 @@ func testSearchInDeletedOrArchivedChannels(t *testing.T, th *SearchTestHelper) {
|
||||
|
||||
t.Run("Include posts in deleted channels using multiple terms", func(t *testing.T) {
|
||||
params := &model.SearchParams{Terms: "message channel", IncludeDeletedChannels: true}
|
||||
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.Posts, 3)
|
||||
@@ -1615,7 +1617,7 @@ func testSearchInDeletedOrArchivedChannels(t *testing.T, th *SearchTestHelper) {
|
||||
IncludeDeletedChannels: true,
|
||||
OrTerms: true,
|
||||
}
|
||||
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.Posts, 3)
|
||||
@@ -1633,7 +1635,7 @@ func testSearchInDeletedOrArchivedChannels(t *testing.T, th *SearchTestHelper) {
|
||||
Terms: "#hashtag",
|
||||
IncludeDeletedChannels: false,
|
||||
}
|
||||
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params1, params2}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params1, params2}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.Nil(t, results)
|
||||
require.Error(t, err)
|
||||
})
|
||||
@@ -1648,7 +1650,7 @@ func testSearchTermsWithDashes(t *testing.T, th *SearchTestHelper) {
|
||||
|
||||
t.Run("Search for terms with dash", func(t *testing.T) {
|
||||
params := &model.SearchParams{Terms: "with-dash-term"}
|
||||
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.Posts, 1)
|
||||
@@ -1657,7 +1659,7 @@ func testSearchTermsWithDashes(t *testing.T, th *SearchTestHelper) {
|
||||
|
||||
t.Run("Search for terms with quoted dash", func(t *testing.T) {
|
||||
params := &model.SearchParams{Terms: "\"with-dash-term\""}
|
||||
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.Posts, 1)
|
||||
@@ -1666,7 +1668,7 @@ func testSearchTermsWithDashes(t *testing.T, th *SearchTestHelper) {
|
||||
|
||||
t.Run("Search for multiple terms with one having dash", func(t *testing.T) {
|
||||
params := &model.SearchParams{Terms: "with-dash-term message"}
|
||||
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.Posts, 1)
|
||||
@@ -1675,7 +1677,7 @@ func testSearchTermsWithDashes(t *testing.T, th *SearchTestHelper) {
|
||||
|
||||
t.Run("Search for multiple OR terms with one having dash", func(t *testing.T) {
|
||||
params := &model.SearchParams{Terms: "with-dash-term message", OrTerms: true}
|
||||
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.Posts, 2)
|
||||
@@ -1693,7 +1695,7 @@ func testSearchTermsWithDots(t *testing.T, th *SearchTestHelper) {
|
||||
|
||||
t.Run("Search for terms with dots", func(t *testing.T) {
|
||||
params := &model.SearchParams{Terms: "with.dots.term"}
|
||||
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.Posts, 1)
|
||||
@@ -1702,7 +1704,7 @@ func testSearchTermsWithDots(t *testing.T, th *SearchTestHelper) {
|
||||
|
||||
t.Run("Search for terms with quoted dots", func(t *testing.T) {
|
||||
params := &model.SearchParams{Terms: "\"with.dots.term\""}
|
||||
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.Posts, 1)
|
||||
@@ -1711,7 +1713,7 @@ func testSearchTermsWithDots(t *testing.T, th *SearchTestHelper) {
|
||||
|
||||
t.Run("Search for multiple terms with one having dots", func(t *testing.T) {
|
||||
params := &model.SearchParams{Terms: "with.dots.term message"}
|
||||
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.Posts, 1)
|
||||
@@ -1720,7 +1722,7 @@ func testSearchTermsWithDots(t *testing.T, th *SearchTestHelper) {
|
||||
|
||||
t.Run("Search for multiple OR terms with one having dots", func(t *testing.T) {
|
||||
params := &model.SearchParams{Terms: "with.dots.term message", OrTerms: true}
|
||||
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.Posts, 2)
|
||||
@@ -1738,7 +1740,7 @@ func testSearchTermsWithUnderscores(t *testing.T, th *SearchTestHelper) {
|
||||
|
||||
t.Run("Search for terms with underscores", func(t *testing.T) {
|
||||
params := &model.SearchParams{Terms: "with_underscores_term"}
|
||||
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.Posts, 1)
|
||||
@@ -1747,7 +1749,7 @@ func testSearchTermsWithUnderscores(t *testing.T, th *SearchTestHelper) {
|
||||
|
||||
t.Run("Search for terms with quoted underscores", func(t *testing.T) {
|
||||
params := &model.SearchParams{Terms: "\"with_underscores_term\""}
|
||||
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.Posts, 1)
|
||||
@@ -1756,7 +1758,7 @@ func testSearchTermsWithUnderscores(t *testing.T, th *SearchTestHelper) {
|
||||
|
||||
t.Run("Search for multiple terms with one having underscores", func(t *testing.T) {
|
||||
params := &model.SearchParams{Terms: "with_underscores_term message"}
|
||||
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.Posts, 1)
|
||||
@@ -1765,7 +1767,7 @@ func testSearchTermsWithUnderscores(t *testing.T, th *SearchTestHelper) {
|
||||
|
||||
t.Run("Search for multiple OR terms with one having underscores", func(t *testing.T) {
|
||||
params := &model.SearchParams{Terms: "with_underscores_term message", OrTerms: true}
|
||||
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.Posts, 2)
|
||||
@@ -1787,7 +1789,7 @@ func testSearchBotAccountsPosts(t *testing.T, th *SearchTestHelper) {
|
||||
defer th.deleteUserPosts(bot.UserId)
|
||||
|
||||
params := &model.SearchParams{Terms: "bot"}
|
||||
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.Posts, 2)
|
||||
@@ -1806,7 +1808,7 @@ func testSupportStemmingAndWildcards(t *testing.T, th *SearchTestHelper) {
|
||||
|
||||
t.Run("Should stem appr", func(t *testing.T) {
|
||||
params := &model.SearchParams{Terms: "appr*"}
|
||||
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.Posts, 3)
|
||||
@@ -1817,7 +1819,7 @@ func testSupportStemmingAndWildcards(t *testing.T, th *SearchTestHelper) {
|
||||
|
||||
t.Run("Should stem approve", func(t *testing.T) {
|
||||
params := &model.SearchParams{Terms: "approve*"}
|
||||
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.Posts, 1)
|
||||
@@ -1834,7 +1836,7 @@ func testSupportWildcardOutsideQuotes(t *testing.T, th *SearchTestHelper) {
|
||||
|
||||
t.Run("Should return results without quotes", func(t *testing.T) {
|
||||
params := &model.SearchParams{Terms: "hell*"}
|
||||
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.Posts, 2)
|
||||
@@ -1844,7 +1846,7 @@ func testSupportWildcardOutsideQuotes(t *testing.T, th *SearchTestHelper) {
|
||||
|
||||
t.Run("Should return just one result with quotes", func(t *testing.T) {
|
||||
params := &model.SearchParams{Terms: "\"hell\"*"}
|
||||
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.Posts, 1)
|
||||
@@ -1862,7 +1864,7 @@ func testHashtagSearchShouldSupportThreeOrMoreCharacters(t *testing.T, th *Searc
|
||||
defer th.deleteUserPosts(th.User.Id)
|
||||
|
||||
params := &model.SearchParams{Terms: "#123", IsHashtag: true}
|
||||
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.Posts, 1)
|
||||
@@ -1875,21 +1877,21 @@ func testSlashShouldNotBeCharSeparator(t *testing.T, th *SearchTestHelper) {
|
||||
defer th.deleteUserPosts(th.User.Id)
|
||||
|
||||
params := &model.SearchParams{Terms: "gamma"}
|
||||
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.Posts, 1)
|
||||
th.checkPostInSearchResults(t, p1.Id, results.Posts)
|
||||
|
||||
params = &model.SearchParams{Terms: "beta"}
|
||||
results, err = th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err = th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.Posts, 1)
|
||||
th.checkPostInSearchResults(t, p1.Id, results.Posts)
|
||||
|
||||
params = &model.SearchParams{Terms: "alpha"}
|
||||
results, err = th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err = th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.Posts, 1)
|
||||
@@ -1904,7 +1906,7 @@ func testSupportSearchInComments(t *testing.T, th *SearchTestHelper) {
|
||||
defer th.deleteUserPosts(th.User.Id)
|
||||
|
||||
params := &model.SearchParams{Terms: "reply"}
|
||||
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.Posts, 1)
|
||||
@@ -1917,7 +1919,7 @@ func testSupportSearchTermsWithinLinks(t *testing.T, th *SearchTestHelper) {
|
||||
defer th.deleteUserPosts(th.User.Id)
|
||||
|
||||
params := &model.SearchParams{Terms: "wikipedia"}
|
||||
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.Posts, 1)
|
||||
@@ -1930,7 +1932,7 @@ func testShouldNotReturnLinksEmbeddedInMarkdown(t *testing.T, th *SearchTestHelp
|
||||
defer th.deleteUserPosts(th.User.Id)
|
||||
|
||||
params := &model.SearchParams{Terms: "wikipedia"}
|
||||
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.Posts, 0)
|
||||
@@ -1939,7 +1941,7 @@ func testShouldNotReturnLinksEmbeddedInMarkdown(t *testing.T, th *SearchTestHelp
|
||||
func testSearchAcrossTeams(t *testing.T, th *SearchTestHelper) {
|
||||
err := th.addUserToChannels(th.User, []string{th.ChannelAnotherTeam.Id})
|
||||
require.NoError(t, err)
|
||||
defer th.Store.Channel().RemoveMember(th.ChannelAnotherTeam.Id, th.User.Id)
|
||||
defer th.Store.Channel().RemoveMember(th.Context, th.ChannelAnotherTeam.Id, th.User.Id)
|
||||
|
||||
_, err = th.createPost(th.User.Id, th.ChannelAnotherTeam.Id, "text to search", "", model.PostTypeDefault, 0, false)
|
||||
require.NoError(t, err)
|
||||
@@ -1948,7 +1950,7 @@ func testSearchAcrossTeams(t *testing.T, th *SearchTestHelper) {
|
||||
require.NoError(t, err)
|
||||
|
||||
params := &model.SearchParams{Terms: "search"}
|
||||
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, "", 0, 20)
|
||||
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, "", 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.Posts, 2)
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/mattermost/mattermost/server/public/model"
|
||||
"github.com/mattermost/mattermost/server/public/shared/request"
|
||||
"github.com/mattermost/mattermost/server/v8/channels/store"
|
||||
)
|
||||
|
||||
@@ -161,7 +162,8 @@ var searchUserStoreTests = []searchTest{
|
||||
|
||||
func TestSearchUserStore(t *testing.T, s store.Store, testEngine *SearchTestEngine) {
|
||||
th := &SearchTestHelper{
|
||||
Store: s,
|
||||
Context: request.TestContext(t),
|
||||
Store: s,
|
||||
}
|
||||
err := th.SetupBasicFixtures()
|
||||
require.NoError(t, err)
|
||||
@@ -174,13 +176,13 @@ func testGetAllUsersInChannelWithEmptyTerm(t *testing.T, th *SearchTestHelper) {
|
||||
AllowFullNames: true,
|
||||
Limit: model.UserSearchDefaultLimit,
|
||||
}
|
||||
users, err := th.Store.User().AutocompleteUsersInChannel(th.Team.Id, th.ChannelBasic.Id, "", options)
|
||||
users, err := th.Store.User().AutocompleteUsersInChannel(th.Context, th.Team.Id, th.ChannelBasic.Id, "", options)
|
||||
require.NoError(t, err)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{th.User}, users.InChannel)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{th.User2}, users.OutOfChannel)
|
||||
|
||||
t.Run("Should be able to correctly honor limit when autocompleting", func(t *testing.T) {
|
||||
result, err := th.Store.User().AutocompleteUsersInChannel(th.Team.Id, th.ChannelBasic.Id, "", options)
|
||||
result, err := th.Store.User().AutocompleteUsersInChannel(th.Context, th.Team.Id, th.ChannelBasic.Id, "", options)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, result.InChannel, 1)
|
||||
require.Len(t, result.OutOfChannel, 1)
|
||||
@@ -188,7 +190,7 @@ func testGetAllUsersInChannelWithEmptyTerm(t *testing.T, th *SearchTestHelper) {
|
||||
|
||||
t.Run("Return all users in team", func(t *testing.T) {
|
||||
options := createDefaultOptions(true, false, false)
|
||||
users, err := th.Store.User().AutocompleteUsersInChannel(th.Team.Id, th.ChannelBasic.Id, "", options)
|
||||
users, err := th.Store.User().AutocompleteUsersInChannel(th.Context, th.Team.Id, th.ChannelBasic.Id, "", options)
|
||||
require.NoError(t, err)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{th.User}, users.InChannel)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{th.User2}, users.OutOfChannel)
|
||||
@@ -204,7 +206,7 @@ func testGetAllUsersInChannelWithEmptyTerm(t *testing.T, th *SearchTestHelper) {
|
||||
defer th.deleteUser(userGuest)
|
||||
|
||||
// In case teamId and channelId are empty our current logic goes through Search
|
||||
users, err := th.Store.User().Search("", "", options)
|
||||
users, err := th.Store.User().Search(th.Context, "", "", options)
|
||||
require.NoError(t, err)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{th.User, th.User2, th.UserAnotherTeam,
|
||||
userAlternate, userGuest}, users)
|
||||
@@ -229,7 +231,7 @@ func testHonorChannelRestrictionsAutocompletingUsers(t *testing.T, th *SearchTes
|
||||
t.Run("Autocomplete users with channel restrictions", func(t *testing.T) {
|
||||
options := createDefaultOptions(true, false, false)
|
||||
options.ViewRestrictions = &model.ViewUsersRestrictions{Channels: []string{th.ChannelBasic.Id}}
|
||||
users, err := th.Store.User().AutocompleteUsersInChannel(th.Team.Id, th.ChannelBasic.Id, "", options)
|
||||
users, err := th.Store.User().AutocompleteUsersInChannel(th.Context, th.Team.Id, th.ChannelBasic.Id, "", options)
|
||||
require.NoError(t, err)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{th.User, userAlternate, guest}, users.InChannel)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{}, users.OutOfChannel)
|
||||
@@ -237,7 +239,7 @@ func testHonorChannelRestrictionsAutocompletingUsers(t *testing.T, th *SearchTes
|
||||
t.Run("Autocomplete users with term and channel restrictions", func(t *testing.T) {
|
||||
options := createDefaultOptions(true, false, false)
|
||||
options.ViewRestrictions = &model.ViewUsersRestrictions{Channels: []string{th.ChannelBasic.Id}}
|
||||
users, err := th.Store.User().AutocompleteUsersInChannel(th.Team.Id, th.ChannelBasic.Id, "alt", options)
|
||||
users, err := th.Store.User().AutocompleteUsersInChannel(th.Context, th.Team.Id, th.ChannelBasic.Id, "alt", options)
|
||||
require.NoError(t, err)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{userAlternate}, users.InChannel)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{}, users.OutOfChannel)
|
||||
@@ -245,7 +247,7 @@ func testHonorChannelRestrictionsAutocompletingUsers(t *testing.T, th *SearchTes
|
||||
t.Run("Autocomplete users with all channels restricted", func(t *testing.T) {
|
||||
options := createDefaultOptions(true, false, false)
|
||||
options.ViewRestrictions = &model.ViewUsersRestrictions{Teams: []string{}, Channels: []string{}}
|
||||
users, err := th.Store.User().AutocompleteUsersInChannel(th.Team.Id, th.ChannelBasic.Id, "", options)
|
||||
users, err := th.Store.User().AutocompleteUsersInChannel(th.Context, th.Team.Id, th.ChannelBasic.Id, "", options)
|
||||
require.NoError(t, err)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{}, users.InChannel)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{}, users.OutOfChannel)
|
||||
@@ -253,7 +255,7 @@ func testHonorChannelRestrictionsAutocompletingUsers(t *testing.T, th *SearchTes
|
||||
t.Run("Autocomplete users with all channels restricted but with empty team", func(t *testing.T) {
|
||||
options := createDefaultOptions(true, false, false)
|
||||
options.ViewRestrictions = &model.ViewUsersRestrictions{Teams: []string{}, Channels: []string{}}
|
||||
users, err := th.Store.User().AutocompleteUsersInChannel("", th.ChannelBasic.Id, "", options)
|
||||
users, err := th.Store.User().AutocompleteUsersInChannel(th.Context, "", th.ChannelBasic.Id, "", options)
|
||||
require.NoError(t, err)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{}, users.InChannel)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{}, users.OutOfChannel)
|
||||
@@ -262,7 +264,7 @@ func testHonorChannelRestrictionsAutocompletingUsers(t *testing.T, th *SearchTes
|
||||
options := createDefaultOptions(true, false, false)
|
||||
options.ViewRestrictions = &model.ViewUsersRestrictions{Channels: []string{th.ChannelBasic.Id}}
|
||||
// In case teamId and channelId are empty our current logic goes through Search
|
||||
users, err := th.Store.User().Search("", "", options)
|
||||
users, err := th.Store.User().Search(th.Context, "", "", options)
|
||||
require.NoError(t, err)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{userAlternate, guest, th.User}, users)
|
||||
})
|
||||
@@ -272,7 +274,7 @@ func testHonorTeamRestrictionsAutocompletingUsers(t *testing.T, th *SearchTestHe
|
||||
t.Run("Should return results for users in the team", func(t *testing.T) {
|
||||
options := createDefaultOptions(true, false, false)
|
||||
options.ViewRestrictions = &model.ViewUsersRestrictions{Teams: []string{th.Team.Id}}
|
||||
users, err := th.Store.User().AutocompleteUsersInChannel(th.Team.Id, th.ChannelBasic.Id, "", options)
|
||||
users, err := th.Store.User().AutocompleteUsersInChannel(th.Context, th.Team.Id, th.ChannelBasic.Id, "", options)
|
||||
require.NoError(t, err)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{th.User}, users.InChannel)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{th.User2}, users.OutOfChannel)
|
||||
@@ -280,7 +282,7 @@ func testHonorTeamRestrictionsAutocompletingUsers(t *testing.T, th *SearchTestHe
|
||||
t.Run("Should return empty because we're filtering all the teams", func(t *testing.T) {
|
||||
options := createDefaultOptions(true, false, false)
|
||||
options.ViewRestrictions = &model.ViewUsersRestrictions{Teams: []string{}, Channels: []string{}}
|
||||
users, err := th.Store.User().AutocompleteUsersInChannel(th.Team.Id, th.ChannelBasic.Id, "", options)
|
||||
users, err := th.Store.User().AutocompleteUsersInChannel(th.Context, th.Team.Id, th.ChannelBasic.Id, "", options)
|
||||
require.NoError(t, err)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{}, users.InChannel)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{}, users.OutOfChannel)
|
||||
@@ -288,11 +290,11 @@ func testHonorTeamRestrictionsAutocompletingUsers(t *testing.T, th *SearchTestHe
|
||||
t.Run("Should return empty when searching in one team and filtering by another", func(t *testing.T) {
|
||||
options := createDefaultOptions(true, false, false)
|
||||
options.ViewRestrictions = &model.ViewUsersRestrictions{Teams: []string{th.AnotherTeam.Id}}
|
||||
users, err := th.Store.User().Search(th.Team.Id, "", options)
|
||||
users, err := th.Store.User().Search(th.Context, th.Team.Id, "", options)
|
||||
require.NoError(t, err)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{}, users)
|
||||
|
||||
acusers, err := th.Store.User().AutocompleteUsersInChannel(th.Team.Id, th.ChannelBasic.Id, "", options)
|
||||
acusers, err := th.Store.User().AutocompleteUsersInChannel(th.Context, th.Team.Id, th.ChannelBasic.Id, "", options)
|
||||
require.NoError(t, err)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{}, acusers.InChannel)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{}, acusers.OutOfChannel)
|
||||
@@ -302,7 +304,7 @@ func testShouldReturnNothingWithoutProperAccess(t *testing.T, th *SearchTestHelp
|
||||
t.Run("Should return results users for the defined channel in the list", func(t *testing.T) {
|
||||
options := createDefaultOptions(true, false, false)
|
||||
options.ListOfAllowedChannels = []string{th.ChannelBasic.Id}
|
||||
users, err := th.Store.User().AutocompleteUsersInChannel(th.Team.Id, th.ChannelBasic.Id, "", options)
|
||||
users, err := th.Store.User().AutocompleteUsersInChannel(th.Context, th.Team.Id, th.ChannelBasic.Id, "", options)
|
||||
require.NoError(t, err)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{th.User}, users.InChannel)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{}, users.OutOfChannel)
|
||||
@@ -310,7 +312,7 @@ func testShouldReturnNothingWithoutProperAccess(t *testing.T, th *SearchTestHelp
|
||||
t.Run("Should return empty because we're filtering all the channels", func(t *testing.T) {
|
||||
options := createDefaultOptions(true, false, false)
|
||||
options.ListOfAllowedChannels = []string{}
|
||||
users, err := th.Store.User().AutocompleteUsersInChannel(th.Team.Id, th.ChannelBasic.Id, "", options)
|
||||
users, err := th.Store.User().AutocompleteUsersInChannel(th.Context, th.Team.Id, th.ChannelBasic.Id, "", options)
|
||||
require.NoError(t, err)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{}, users.InChannel)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{}, users.OutOfChannel)
|
||||
@@ -325,7 +327,7 @@ func testAutocompleteUserByUsername(t *testing.T, th *SearchTestHelper) {
|
||||
err = th.addUserToChannels(userAlternate, []string{th.ChannelBasic.Id})
|
||||
require.NoError(t, err)
|
||||
options := createDefaultOptions(false, false, false)
|
||||
users, err := th.Store.User().AutocompleteUsersInChannel(th.Team.Id, th.ChannelBasic.Id, "basicusername", options)
|
||||
users, err := th.Store.User().AutocompleteUsersInChannel(th.Context, th.Team.Id, th.ChannelBasic.Id, "basicusername", options)
|
||||
require.NoError(t, err)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{th.User}, users.InChannel)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{th.User2}, users.OutOfChannel)
|
||||
@@ -340,14 +342,14 @@ func testAutocompleteUserByFirstName(t *testing.T, th *SearchTestHelper) {
|
||||
require.NoError(t, err)
|
||||
t.Run("Should autocomplete users when the first name is unique", func(t *testing.T) {
|
||||
options := createDefaultOptions(true, false, false)
|
||||
users, err := th.Store.User().AutocompleteUsersInChannel(th.Team.Id, th.ChannelBasic.Id, "altfirstname", options)
|
||||
users, err := th.Store.User().AutocompleteUsersInChannel(th.Context, th.Team.Id, th.ChannelBasic.Id, "altfirstname", options)
|
||||
require.NoError(t, err)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{userAlternate}, users.InChannel)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{}, users.OutOfChannel)
|
||||
})
|
||||
t.Run("Should autocomplete users for in the channel and out of the channel with the same first name", func(t *testing.T) {
|
||||
options := createDefaultOptions(true, false, false)
|
||||
users, err := th.Store.User().AutocompleteUsersInChannel(th.Team.Id, th.ChannelBasic.Id, "basicfirstname", options)
|
||||
users, err := th.Store.User().AutocompleteUsersInChannel(th.Context, th.Team.Id, th.ChannelBasic.Id, "basicfirstname", options)
|
||||
require.NoError(t, err)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{th.User}, users.InChannel)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{th.User2}, users.OutOfChannel)
|
||||
@@ -363,14 +365,14 @@ func testAutocompleteUserByLastName(t *testing.T, th *SearchTestHelper) {
|
||||
require.NoError(t, err)
|
||||
t.Run("Should return results when the last name is unique", func(t *testing.T) {
|
||||
options := createDefaultOptions(true, false, false)
|
||||
users, err := th.Store.User().AutocompleteUsersInChannel(th.Team.Id, th.ChannelBasic.Id, "altlastname", options)
|
||||
users, err := th.Store.User().AutocompleteUsersInChannel(th.Context, th.Team.Id, th.ChannelBasic.Id, "altlastname", options)
|
||||
require.NoError(t, err)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{userAlternate}, users.InChannel)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{}, users.OutOfChannel)
|
||||
})
|
||||
t.Run("Should return results for in the channel and out of the channel with the same last name", func(t *testing.T) {
|
||||
options := createDefaultOptions(true, false, false)
|
||||
users, err := th.Store.User().AutocompleteUsersInChannel(th.Team.Id, th.ChannelBasic.Id, "basiclastname", options)
|
||||
users, err := th.Store.User().AutocompleteUsersInChannel(th.Context, th.Team.Id, th.ChannelBasic.Id, "basiclastname", options)
|
||||
require.NoError(t, err)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{th.User}, users.InChannel)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{th.User2}, users.OutOfChannel)
|
||||
@@ -386,14 +388,14 @@ func testAutocompleteUserByNickName(t *testing.T, th *SearchTestHelper) {
|
||||
require.NoError(t, err)
|
||||
t.Run("Should return results when the nickname is unique", func(t *testing.T) {
|
||||
options := createDefaultOptions(true, false, false)
|
||||
users, err := th.Store.User().AutocompleteUsersInChannel(th.Team.Id, th.ChannelBasic.Id, "alternatenickname", options)
|
||||
users, err := th.Store.User().AutocompleteUsersInChannel(th.Context, th.Team.Id, th.ChannelBasic.Id, "alternatenickname", options)
|
||||
require.NoError(t, err)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{userAlternate}, users.InChannel)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{}, users.OutOfChannel)
|
||||
})
|
||||
t.Run("Should return users that share the same part of the nickname", func(t *testing.T) {
|
||||
options := createDefaultOptions(true, false, false)
|
||||
users, err := th.Store.User().AutocompleteUsersInChannel(th.Team.Id, th.ChannelBasic.Id, "basicnickname", options)
|
||||
users, err := th.Store.User().AutocompleteUsersInChannel(th.Context, th.Team.Id, th.ChannelBasic.Id, "basicnickname", options)
|
||||
require.NoError(t, err)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{th.User}, users.InChannel)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{th.User2}, users.OutOfChannel)
|
||||
@@ -403,7 +405,7 @@ func testAutocompleteUserByEmail(t *testing.T, th *SearchTestHelper) {
|
||||
userAlternate, err := th.createUser("alternateusername", "alternatenickname", "firstname", "altlastname")
|
||||
require.NoError(t, err)
|
||||
userAlternate.Email = "useralt@test.email.com"
|
||||
_, err = th.Store.User().Update(userAlternate, false)
|
||||
_, err = th.Store.User().Update(th.Context, userAlternate, false)
|
||||
require.NoError(t, err)
|
||||
defer th.deleteUser(userAlternate)
|
||||
err = th.addUserToTeams(userAlternate, []string{th.Team.Id})
|
||||
@@ -412,47 +414,47 @@ func testAutocompleteUserByEmail(t *testing.T, th *SearchTestHelper) {
|
||||
require.NoError(t, err)
|
||||
t.Run("Should autocomplete users when the email is unique", func(t *testing.T) {
|
||||
options := createDefaultOptions(false, true, false)
|
||||
users, err := th.Store.User().AutocompleteUsersInChannel(th.Team.Id, th.ChannelBasic.Id, "useralt@test.email.com", options)
|
||||
users, err := th.Store.User().AutocompleteUsersInChannel(th.Context, th.Team.Id, th.ChannelBasic.Id, "useralt@test.email.com", options)
|
||||
require.NoError(t, err)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{userAlternate}, users.InChannel)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{}, users.OutOfChannel)
|
||||
})
|
||||
t.Run("Should autocomplete users that share the same email user prefix", func(t *testing.T) {
|
||||
options := createDefaultOptions(false, true, false)
|
||||
users, err := th.Store.User().AutocompleteUsersInChannel(th.Team.Id, th.ChannelBasic.Id, "success_", options)
|
||||
users, err := th.Store.User().AutocompleteUsersInChannel(th.Context, th.Team.Id, th.ChannelBasic.Id, "success_", options)
|
||||
require.NoError(t, err)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{th.User}, users.InChannel)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{th.User2}, users.OutOfChannel)
|
||||
})
|
||||
t.Run("Should autocomplete users that share the same email domain", func(t *testing.T) {
|
||||
options := createDefaultOptions(false, true, false)
|
||||
users, err := th.Store.User().AutocompleteUsersInChannel(th.Team.Id, th.ChannelBasic.Id, "simulator.amazon.com", options)
|
||||
users, err := th.Store.User().AutocompleteUsersInChannel(th.Context, th.Team.Id, th.ChannelBasic.Id, "simulator.amazon.com", options)
|
||||
require.NoError(t, err)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{th.User}, users.InChannel)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{th.User2}, users.OutOfChannel)
|
||||
})
|
||||
t.Run("Should search users when the email is unique", func(t *testing.T) {
|
||||
options := createDefaultOptions(false, true, false)
|
||||
users, err := th.Store.User().Search(th.Team.Id, "useralt@test.email.com", options)
|
||||
users, err := th.Store.User().Search(th.Context, th.Team.Id, "useralt@test.email.com", options)
|
||||
require.NoError(t, err)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{userAlternate}, users)
|
||||
})
|
||||
t.Run("Should search users that share the same email user prefix", func(t *testing.T) {
|
||||
options := createDefaultOptions(false, true, false)
|
||||
users, err := th.Store.User().Search(th.Team.Id, "success_", options)
|
||||
users, err := th.Store.User().Search(th.Context, th.Team.Id, "success_", options)
|
||||
require.NoError(t, err)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{th.User}, users)
|
||||
})
|
||||
t.Run("Should search users that share the same email domain", func(t *testing.T) {
|
||||
options := createDefaultOptions(false, true, false)
|
||||
users, err := th.Store.User().Search(th.Team.Id, "simulator.amazon.com", options)
|
||||
users, err := th.Store.User().Search(th.Context, th.Team.Id, "simulator.amazon.com", options)
|
||||
require.NoError(t, err)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{th.User}, users)
|
||||
})
|
||||
}
|
||||
func testShouldNotMatchSpecificQueriesEmail(t *testing.T, th *SearchTestHelper) {
|
||||
options := createDefaultOptions(false, false, false)
|
||||
users, err := th.Store.User().AutocompleteUsersInChannel(th.Team.Id, th.ChannelBasic.Id, "success_", options)
|
||||
users, err := th.Store.User().AutocompleteUsersInChannel(th.Context, th.Team.Id, th.ChannelBasic.Id, "success_", options)
|
||||
require.NoError(t, err)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{}, users.InChannel)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{}, users.OutOfChannel)
|
||||
@@ -467,21 +469,21 @@ func testAutocompleteUserByUsernameWithDot(t *testing.T, th *SearchTestHelper) {
|
||||
require.NoError(t, err)
|
||||
t.Run("Should return results when searching for the whole username with Dot", func(t *testing.T) {
|
||||
options := createDefaultOptions(false, false, false)
|
||||
users, err := th.Store.User().AutocompleteUsersInChannel(th.Team.Id, th.ChannelBasic.Id, "alternate.username", options)
|
||||
users, err := th.Store.User().AutocompleteUsersInChannel(th.Context, th.Team.Id, th.ChannelBasic.Id, "alternate.username", options)
|
||||
require.NoError(t, err)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{userAlternate}, users.InChannel)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{}, users.OutOfChannel)
|
||||
})
|
||||
t.Run("Should return results when searching for part of the username including the Dot", func(t *testing.T) {
|
||||
options := createDefaultOptions(false, false, false)
|
||||
users, err := th.Store.User().AutocompleteUsersInChannel(th.Team.Id, th.ChannelBasic.Id, ".username", options)
|
||||
users, err := th.Store.User().AutocompleteUsersInChannel(th.Context, th.Team.Id, th.ChannelBasic.Id, ".username", options)
|
||||
require.NoError(t, err)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{userAlternate}, users.InChannel)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{}, users.OutOfChannel)
|
||||
})
|
||||
t.Run("Should return results when searching for part of the username not including the Dot", func(t *testing.T) {
|
||||
options := createDefaultOptions(false, false, false)
|
||||
users, err := th.Store.User().AutocompleteUsersInChannel(th.Team.Id, th.ChannelBasic.Id, "username", options)
|
||||
users, err := th.Store.User().AutocompleteUsersInChannel(th.Context, th.Team.Id, th.ChannelBasic.Id, "username", options)
|
||||
require.NoError(t, err)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{userAlternate}, users.InChannel)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{}, users.OutOfChannel)
|
||||
@@ -497,21 +499,21 @@ func testAutocompleteUserByUsernameWithUnderscore(t *testing.T, th *SearchTestHe
|
||||
require.NoError(t, err)
|
||||
t.Run("Should return results when searching for the whole username with underscore", func(t *testing.T) {
|
||||
options := createDefaultOptions(false, false, false)
|
||||
users, err := th.Store.User().AutocompleteUsersInChannel(th.Team.Id, th.ChannelBasic.Id, "alternate_username", options)
|
||||
users, err := th.Store.User().AutocompleteUsersInChannel(th.Context, th.Team.Id, th.ChannelBasic.Id, "alternate_username", options)
|
||||
require.NoError(t, err)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{userAlternate}, users.InChannel)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{}, users.OutOfChannel)
|
||||
})
|
||||
t.Run("Should return results when searching for part of the username including the underscore", func(t *testing.T) {
|
||||
options := createDefaultOptions(false, false, false)
|
||||
users, err := th.Store.User().AutocompleteUsersInChannel(th.Team.Id, th.ChannelBasic.Id, "_username", options)
|
||||
users, err := th.Store.User().AutocompleteUsersInChannel(th.Context, th.Team.Id, th.ChannelBasic.Id, "_username", options)
|
||||
require.NoError(t, err)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{userAlternate}, users.InChannel)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{}, users.OutOfChannel)
|
||||
})
|
||||
t.Run("Should return results when searching for part of the username not including the underscore", func(t *testing.T) {
|
||||
options := createDefaultOptions(false, false, false)
|
||||
users, err := th.Store.User().AutocompleteUsersInChannel(th.Team.Id, th.ChannelBasic.Id, "username", options)
|
||||
users, err := th.Store.User().AutocompleteUsersInChannel(th.Context, th.Team.Id, th.ChannelBasic.Id, "username", options)
|
||||
require.NoError(t, err)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{userAlternate}, users.InChannel)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{}, users.OutOfChannel)
|
||||
@@ -527,21 +529,21 @@ func testAutocompleteUserByUsernameWithHyphen(t *testing.T, th *SearchTestHelper
|
||||
require.NoError(t, err)
|
||||
t.Run("Should return results when searching for the whole username with hyphen", func(t *testing.T) {
|
||||
options := createDefaultOptions(false, false, false)
|
||||
users, err := th.Store.User().AutocompleteUsersInChannel(th.Team.Id, th.ChannelBasic.Id, "alternate-username", options)
|
||||
users, err := th.Store.User().AutocompleteUsersInChannel(th.Context, th.Team.Id, th.ChannelBasic.Id, "alternate-username", options)
|
||||
require.NoError(t, err)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{userAlternate}, users.InChannel)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{}, users.OutOfChannel)
|
||||
})
|
||||
t.Run("Should return results when searching for part of the username including the hyphen", func(t *testing.T) {
|
||||
options := createDefaultOptions(false, false, false)
|
||||
users, err := th.Store.User().AutocompleteUsersInChannel(th.Team.Id, th.ChannelBasic.Id, "-username", options)
|
||||
users, err := th.Store.User().AutocompleteUsersInChannel(th.Context, th.Team.Id, th.ChannelBasic.Id, "-username", options)
|
||||
require.NoError(t, err)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{userAlternate}, users.InChannel)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{}, users.OutOfChannel)
|
||||
})
|
||||
t.Run("Should return results when searching for part of the username not including the hyphen", func(t *testing.T) {
|
||||
options := createDefaultOptions(false, false, false)
|
||||
users, err := th.Store.User().AutocompleteUsersInChannel(th.Team.Id, th.ChannelBasic.Id, "username", options)
|
||||
users, err := th.Store.User().AutocompleteUsersInChannel(th.Context, th.Team.Id, th.ChannelBasic.Id, "username", options)
|
||||
require.NoError(t, err)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{userAlternate}, users.InChannel)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{}, users.OutOfChannel)
|
||||
@@ -558,14 +560,14 @@ func testShouldEscapePercentageCharacter(t *testing.T, th *SearchTestHelper) {
|
||||
require.NoError(t, err)
|
||||
t.Run("Should autocomplete users escaping percentage symbol", func(t *testing.T) {
|
||||
options := createDefaultOptions(false, false, false)
|
||||
users, err := th.Store.User().AutocompleteUsersInChannel(th.Team.Id, th.ChannelBasic.Id, "alternate%", options)
|
||||
users, err := th.Store.User().AutocompleteUsersInChannel(th.Context, th.Team.Id, th.ChannelBasic.Id, "alternate%", options)
|
||||
require.NoError(t, err)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{userAlternate}, users.InChannel)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{}, users.OutOfChannel)
|
||||
})
|
||||
t.Run("Should search users escaping percentage symbol", func(t *testing.T) {
|
||||
options := createDefaultOptions(false, false, false)
|
||||
users, err := th.Store.User().Search(th.Team.Id, "alternate%", options)
|
||||
users, err := th.Store.User().Search(th.Context, th.Team.Id, "alternate%", options)
|
||||
require.NoError(t, err)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{userAlternate}, users)
|
||||
})
|
||||
@@ -580,14 +582,14 @@ func testShouldEscapeUnderscoreCharacter(t *testing.T, th *SearchTestHelper) {
|
||||
require.NoError(t, err)
|
||||
t.Run("Should autocomplete users escaping underscore symbol", func(t *testing.T) {
|
||||
options := createDefaultOptions(false, false, false)
|
||||
users, err := th.Store.User().AutocompleteUsersInChannel(th.Team.Id, th.ChannelBasic.Id, "alternate_", options)
|
||||
users, err := th.Store.User().AutocompleteUsersInChannel(th.Context, th.Team.Id, th.ChannelBasic.Id, "alternate_", options)
|
||||
require.NoError(t, err)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{userAlternate}, users.InChannel)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{}, users.OutOfChannel)
|
||||
})
|
||||
t.Run("Should search users escaping underscore symbol", func(t *testing.T) {
|
||||
options := createDefaultOptions(false, false, false)
|
||||
users, err := th.Store.User().Search(th.Team.Id, "alternate_", options)
|
||||
users, err := th.Store.User().Search(th.Context, th.Team.Id, "alternate_", options)
|
||||
require.NoError(t, err)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{userAlternate}, users)
|
||||
})
|
||||
@@ -597,7 +599,7 @@ func testShouldBeAbleToSearchInactiveUsers(t *testing.T, th *SearchTestHelper) {
|
||||
userAlternate, err := th.createUser("basicusernamealternate", "alternatenickname", "firstname", "altlastname")
|
||||
require.NoError(t, err)
|
||||
userAlternate.DeleteAt = model.GetMillis()
|
||||
_, err = th.Store.User().Update(userAlternate, true)
|
||||
_, err = th.Store.User().Update(th.Context, userAlternate, true)
|
||||
require.NoError(t, err)
|
||||
defer th.deleteUser(userAlternate)
|
||||
err = th.addUserToTeams(userAlternate, []string{th.Team.Id})
|
||||
@@ -606,27 +608,27 @@ func testShouldBeAbleToSearchInactiveUsers(t *testing.T, th *SearchTestHelper) {
|
||||
require.NoError(t, err)
|
||||
t.Run("Should autocomplete inactive users if we allow it", func(t *testing.T) {
|
||||
options := createDefaultOptions(false, false, true)
|
||||
users, err := th.Store.User().AutocompleteUsersInChannel(th.Team.Id, th.ChannelBasic.Id, "basicusername", options)
|
||||
users, err := th.Store.User().AutocompleteUsersInChannel(th.Context, th.Team.Id, th.ChannelBasic.Id, "basicusername", options)
|
||||
require.NoError(t, err)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{th.User, userAlternate}, users.InChannel)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{th.User2}, users.OutOfChannel)
|
||||
})
|
||||
t.Run("Should search inactive users if we allow it", func(t *testing.T) {
|
||||
options := createDefaultOptions(false, false, true)
|
||||
users, err := th.Store.User().Search(th.Team.Id, "basicusername", options)
|
||||
users, err := th.Store.User().Search(th.Context, th.Team.Id, "basicusername", options)
|
||||
require.NoError(t, err)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{th.User, th.User2, userAlternate}, users)
|
||||
})
|
||||
t.Run("Shouldn't autocomplete inactive users if we don't allow it", func(t *testing.T) {
|
||||
options := createDefaultOptions(false, false, false)
|
||||
users, err := th.Store.User().AutocompleteUsersInChannel(th.Team.Id, th.ChannelBasic.Id, "basicusername", options)
|
||||
users, err := th.Store.User().AutocompleteUsersInChannel(th.Context, th.Team.Id, th.ChannelBasic.Id, "basicusername", options)
|
||||
require.NoError(t, err)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{th.User}, users.InChannel)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{th.User2}, users.OutOfChannel)
|
||||
})
|
||||
t.Run("Shouldn't search inactive users if we don't allow it", func(t *testing.T) {
|
||||
options := createDefaultOptions(false, false, false)
|
||||
users, err := th.Store.User().Search(th.Team.Id, "basicusername", options)
|
||||
users, err := th.Store.User().Search(th.Context, th.Team.Id, "basicusername", options)
|
||||
require.NoError(t, err)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{th.User, th.User2}, users)
|
||||
})
|
||||
@@ -636,13 +638,13 @@ func testShouldBeAbleToSearchFilteringByRole(t *testing.T, th *SearchTestHelper)
|
||||
userAlternate, err := th.createUser("basicusernamealternate", "alternatenickname", "firstname", "altlastname")
|
||||
require.NoError(t, err)
|
||||
userAlternate.Roles = "system_admin system_user"
|
||||
_, err = th.Store.User().Update(userAlternate, true)
|
||||
_, err = th.Store.User().Update(th.Context, userAlternate, true)
|
||||
require.NoError(t, err)
|
||||
defer th.deleteUser(userAlternate)
|
||||
userAlternate2, err := th.createUser("basicusernamealternate2", "alternatenickname2", "firstname2", "altlastname2")
|
||||
require.NoError(t, err)
|
||||
userAlternate2.Roles = "system_user"
|
||||
_, err = th.Store.User().Update(userAlternate2, true)
|
||||
_, err = th.Store.User().Update(th.Context, userAlternate2, true)
|
||||
require.NoError(t, err)
|
||||
defer th.deleteUser(userAlternate2)
|
||||
err = th.addUserToTeams(userAlternate, []string{th.Team.Id})
|
||||
@@ -654,7 +656,7 @@ func testShouldBeAbleToSearchFilteringByRole(t *testing.T, th *SearchTestHelper)
|
||||
t.Run("Should autocomplete users filtering by roles", func(t *testing.T) {
|
||||
options := createDefaultOptions(false, false, true)
|
||||
options.Role = "system_admin"
|
||||
users, err := th.Store.User().AutocompleteUsersInChannel(th.Team.Id, th.ChannelBasic.Id, "", options)
|
||||
users, err := th.Store.User().AutocompleteUsersInChannel(th.Context, th.Team.Id, th.ChannelBasic.Id, "", options)
|
||||
require.NoError(t, err)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{userAlternate}, users.InChannel)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{}, users.OutOfChannel)
|
||||
@@ -662,7 +664,7 @@ func testShouldBeAbleToSearchFilteringByRole(t *testing.T, th *SearchTestHelper)
|
||||
t.Run("Should search users filtering by roles", func(t *testing.T) {
|
||||
options := createDefaultOptions(false, false, true)
|
||||
options.Role = "system_admin"
|
||||
users, err := th.Store.User().Search(th.Team.Id, "", options)
|
||||
users, err := th.Store.User().Search(th.Context, th.Team.Id, "", options)
|
||||
require.NoError(t, err)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{userAlternate}, users)
|
||||
})
|
||||
@@ -671,14 +673,14 @@ func testShouldBeAbleToSearchFilteringByRole(t *testing.T, th *SearchTestHelper)
|
||||
func testShouldIgnoreLeadingAtSymbols(t *testing.T, th *SearchTestHelper) {
|
||||
t.Run("Should autocomplete ignoring the @ symbol at the beginning", func(t *testing.T) {
|
||||
options := createDefaultOptions(false, false, false)
|
||||
users, err := th.Store.User().AutocompleteUsersInChannel(th.Team.Id, th.ChannelBasic.Id, "@basicusername", options)
|
||||
users, err := th.Store.User().AutocompleteUsersInChannel(th.Context, th.Team.Id, th.ChannelBasic.Id, "@basicusername", options)
|
||||
require.NoError(t, err)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{th.User}, users.InChannel)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{th.User2}, users.OutOfChannel)
|
||||
})
|
||||
t.Run("Should search ignoring the @ symbol at the beginning", func(t *testing.T) {
|
||||
options := createDefaultOptions(false, false, false)
|
||||
users, err := th.Store.User().Search(th.Team.Id, "@basicusername", options)
|
||||
users, err := th.Store.User().Search(th.Context, th.Team.Id, "@basicusername", options)
|
||||
require.NoError(t, err)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{th.User, th.User2}, users)
|
||||
})
|
||||
@@ -686,7 +688,7 @@ func testShouldIgnoreLeadingAtSymbols(t *testing.T, th *SearchTestHelper) {
|
||||
|
||||
func testSearchUsersShouldBeCaseInsensitive(t *testing.T, th *SearchTestHelper) {
|
||||
options := createDefaultOptions(false, false, false)
|
||||
users, err := th.Store.User().AutocompleteUsersInChannel(th.Team.Id, th.ChannelBasic.Id, "BaSiCUsErNaMe", options)
|
||||
users, err := th.Store.User().AutocompleteUsersInChannel(th.Context, th.Team.Id, th.ChannelBasic.Id, "BaSiCUsErNaMe", options)
|
||||
require.NoError(t, err)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{th.User}, users.InChannel)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{th.User2}, users.OutOfChannel)
|
||||
@@ -703,14 +705,14 @@ func testSearchOneTwoCharUsernamesAndFirstLastNames(t *testing.T, th *SearchTest
|
||||
require.NoError(t, err)
|
||||
t.Run("Should support two characters in the full name", func(t *testing.T) {
|
||||
options := createDefaultOptions(true, false, false)
|
||||
users, err := th.Store.User().AutocompleteUsersInChannel(th.Team.Id, th.ChannelBasic.Id, "zi", options)
|
||||
users, err := th.Store.User().AutocompleteUsersInChannel(th.Context, th.Team.Id, th.ChannelBasic.Id, "zi", options)
|
||||
require.NoError(t, err)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{userAlternate}, users.InChannel)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{}, users.OutOfChannel)
|
||||
})
|
||||
t.Run("Should support two characters in the username", func(t *testing.T) {
|
||||
options := createDefaultOptions(true, false, false)
|
||||
users, err := th.Store.User().AutocompleteUsersInChannel(th.Team.Id, th.ChannelBasic.Id, "ho", options)
|
||||
users, err := th.Store.User().AutocompleteUsersInChannel(th.Context, th.Team.Id, th.ChannelBasic.Id, "ho", options)
|
||||
require.NoError(t, err)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{userAlternate}, users.InChannel)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{}, users.OutOfChannel)
|
||||
@@ -728,14 +730,14 @@ func testShouldSupportKoreanCharacters(t *testing.T, th *SearchTestHelper) {
|
||||
require.NoError(t, err)
|
||||
t.Run("Should support hanja korean characters", func(t *testing.T) {
|
||||
options := createDefaultOptions(true, false, false)
|
||||
users, err := th.Store.User().AutocompleteUsersInChannel(th.Team.Id, th.ChannelBasic.Id, "서강준", options)
|
||||
users, err := th.Store.User().AutocompleteUsersInChannel(th.Context, th.Team.Id, th.ChannelBasic.Id, "서강준", options)
|
||||
require.NoError(t, err)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{userAlternate}, users.InChannel)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{}, users.OutOfChannel)
|
||||
})
|
||||
t.Run("Should support hangul korean characters", func(t *testing.T) {
|
||||
options := createDefaultOptions(true, false, false)
|
||||
users, err := th.Store.User().AutocompleteUsersInChannel(th.Team.Id, th.ChannelBasic.Id, "안신원", options)
|
||||
users, err := th.Store.User().AutocompleteUsersInChannel(th.Context, th.Team.Id, th.ChannelBasic.Id, "안신원", options)
|
||||
require.NoError(t, err)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{userAlternate}, users.InChannel)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{}, users.OutOfChannel)
|
||||
@@ -751,7 +753,7 @@ func testSearchWithHyphenAtTheEndOfTheTerm(t *testing.T, th *SearchTestHelper) {
|
||||
err = th.addUserToChannels(userAlternate, []string{th.ChannelBasic.Id})
|
||||
require.NoError(t, err)
|
||||
options := createDefaultOptions(true, false, false)
|
||||
users, err := th.Store.User().AutocompleteUsersInChannel(th.Team.Id, th.ChannelBasic.Id, "alternate-", options)
|
||||
users, err := th.Store.User().AutocompleteUsersInChannel(th.Context, th.Team.Id, th.ChannelBasic.Id, "alternate-", options)
|
||||
require.NoError(t, err)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{userAlternate}, users.InChannel)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{}, users.OutOfChannel)
|
||||
@@ -760,39 +762,39 @@ func testSearchWithHyphenAtTheEndOfTheTerm(t *testing.T, th *SearchTestHelper) {
|
||||
func testSearchUsersInTeam(t *testing.T, th *SearchTestHelper) {
|
||||
t.Run("Should return all the team users", func(t *testing.T) {
|
||||
options := createDefaultOptions(false, false, false)
|
||||
users, err := th.Store.User().Search(th.Team.Id, "", options)
|
||||
users, err := th.Store.User().Search(th.Context, th.Team.Id, "", options)
|
||||
require.NoError(t, err)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{th.User, th.User2}, users)
|
||||
})
|
||||
t.Run("Should return all the team users with no team id", func(t *testing.T) {
|
||||
options := createDefaultOptions(false, false, false)
|
||||
users, err := th.Store.User().Search("", "basicusername", options)
|
||||
users, err := th.Store.User().Search(th.Context, "", "basicusername", options)
|
||||
require.NoError(t, err)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{th.User, th.User2, th.UserAnotherTeam}, users)
|
||||
})
|
||||
t.Run("Should return all the team users filtered by username", func(t *testing.T) {
|
||||
options := createDefaultOptions(false, false, false)
|
||||
users, err := th.Store.User().Search(th.Team.Id, "basicusername1", options)
|
||||
users, err := th.Store.User().Search(th.Context, th.Team.Id, "basicusername1", options)
|
||||
require.NoError(t, err)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{th.User}, users)
|
||||
})
|
||||
t.Run("Should not return spurious results", func(t *testing.T) {
|
||||
options := createDefaultOptions(false, false, false)
|
||||
users, err := th.Store.User().Search(th.Team.Id, "falseuser", options)
|
||||
users, err := th.Store.User().Search(th.Context, th.Team.Id, "falseuser", options)
|
||||
require.NoError(t, err)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{}, users)
|
||||
})
|
||||
t.Run("Should return all the team users filtered by username and with channel restrictions", func(t *testing.T) {
|
||||
options := createDefaultOptions(false, false, false)
|
||||
options.ViewRestrictions = &model.ViewUsersRestrictions{Channels: []string{th.ChannelBasic.Id}}
|
||||
users, err := th.Store.User().Search(th.Team.Id, "basicusername", options)
|
||||
users, err := th.Store.User().Search(th.Context, th.Team.Id, "basicusername", options)
|
||||
require.NoError(t, err)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{th.User}, users)
|
||||
})
|
||||
t.Run("Should return all the team users filtered by username and with all channel restricted", func(t *testing.T) {
|
||||
options := createDefaultOptions(false, false, false)
|
||||
options.ViewRestrictions = &model.ViewUsersRestrictions{Channels: []string{}}
|
||||
users, err := th.Store.User().Search(th.Team.Id, "basicusername1", options)
|
||||
users, err := th.Store.User().Search(th.Context, th.Team.Id, "basicusername1", options)
|
||||
require.NoError(t, err)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{}, users)
|
||||
})
|
||||
@@ -801,7 +803,7 @@ func testSearchUsersInTeam(t *testing.T, th *SearchTestHelper) {
|
||||
Limit: 1,
|
||||
}
|
||||
|
||||
users, err := th.Store.User().Search(th.Team.Id, "", optionsWithLimit)
|
||||
users, err := th.Store.User().Search(th.Context, th.Team.Id, "", optionsWithLimit)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, users, 1)
|
||||
})
|
||||
@@ -816,7 +818,7 @@ func testSearchUsersInTeamUsernameWithDot(t *testing.T, th *SearchTestHelper) {
|
||||
err = th.addUserToChannels(userAlternate, []string{th.ChannelBasic.Id})
|
||||
require.NoError(t, err)
|
||||
options := createDefaultOptions(true, false, false)
|
||||
users, err := th.Store.User().Search(th.Team.Id, "alternate.", options)
|
||||
users, err := th.Store.User().Search(th.Context, th.Team.Id, "alternate.", options)
|
||||
require.NoError(t, err)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{userAlternate}, users)
|
||||
}
|
||||
@@ -830,7 +832,7 @@ func testSearchUsersInTeamUsernameWithHyphen(t *testing.T, th *SearchTestHelper)
|
||||
err = th.addUserToChannels(userAlternate, []string{th.ChannelBasic.Id})
|
||||
require.NoError(t, err)
|
||||
options := createDefaultOptions(true, false, false)
|
||||
users, err := th.Store.User().Search(th.Team.Id, "alternate-", options)
|
||||
users, err := th.Store.User().Search(th.Context, th.Team.Id, "alternate-", options)
|
||||
require.NoError(t, err)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{userAlternate}, users)
|
||||
}
|
||||
@@ -844,7 +846,7 @@ func testSearchUsersInTeamUsernameWithUnderscore(t *testing.T, th *SearchTestHel
|
||||
err = th.addUserToChannels(userAlternate, []string{th.ChannelBasic.Id})
|
||||
require.NoError(t, err)
|
||||
options := createDefaultOptions(true, false, false)
|
||||
users, err := th.Store.User().Search(th.Team.Id, "alternate_", options)
|
||||
users, err := th.Store.User().Search(th.Context, th.Team.Id, "alternate_", options)
|
||||
require.NoError(t, err)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{userAlternate}, users)
|
||||
}
|
||||
@@ -852,19 +854,19 @@ func testSearchUsersInTeamUsernameWithUnderscore(t *testing.T, th *SearchTestHel
|
||||
func testSearchUsersByFullName(t *testing.T, th *SearchTestHelper) {
|
||||
t.Run("Should search users by full name", func(t *testing.T) {
|
||||
options := createDefaultOptions(true, false, false)
|
||||
users, err := th.Store.User().Search(th.Team.Id, "basicfirstname", options)
|
||||
users, err := th.Store.User().Search(th.Context, th.Team.Id, "basicfirstname", options)
|
||||
require.NoError(t, err)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{th.User, th.User2}, users)
|
||||
})
|
||||
t.Run("Should search user by full name", func(t *testing.T) {
|
||||
options := createDefaultOptions(true, false, false)
|
||||
users, err := th.Store.User().Search(th.Team.Id, "basicfirstname1", options)
|
||||
users, err := th.Store.User().Search(th.Context, th.Team.Id, "basicfirstname1", options)
|
||||
require.NoError(t, err)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{th.User}, users)
|
||||
})
|
||||
t.Run("Should return empty when search by full name and is deactivated", func(t *testing.T) {
|
||||
options := createDefaultOptions(false, false, false)
|
||||
users, err := th.Store.User().Search(th.Team.Id, "basicfirstname1", options)
|
||||
users, err := th.Store.User().Search(th.Context, th.Team.Id, "basicfirstname1", options)
|
||||
require.NoError(t, err)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{}, users)
|
||||
})
|
||||
@@ -878,7 +880,7 @@ func testSearchUserBySubstringInAnyName(t *testing.T, th *SearchTestHelper) {
|
||||
|
||||
// searching user without specifying team
|
||||
options := createDefaultOptions(true, false, false)
|
||||
users, err := th.Store.User().Search("", "hello", options)
|
||||
users, err := th.Store.User().Search(th.Context, "", "hello", options)
|
||||
require.NoError(t, err)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{userAlternate}, users)
|
||||
|
||||
@@ -890,7 +892,7 @@ func testSearchUserBySubstringInAnyName(t *testing.T, th *SearchTestHelper) {
|
||||
require.NoError(t, err)
|
||||
|
||||
options = createDefaultOptions(true, false, false)
|
||||
users, err = th.Store.User().Search(th.Team.Id, "hello", options)
|
||||
users, err = th.Store.User().Search(th.Context, th.Team.Id, "hello", options)
|
||||
require.NoError(t, err)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{userAlternate}, users)
|
||||
})
|
||||
@@ -900,7 +902,7 @@ func testSearchUserBySubstringInAnyName(t *testing.T, th *SearchTestHelper) {
|
||||
defer th.deleteUser(userAlternate)
|
||||
|
||||
options := createDefaultOptions(true, false, false)
|
||||
users, err := th.Store.User().Search("", "hello", options)
|
||||
users, err := th.Store.User().Search(th.Context, "", "hello", options)
|
||||
require.NoError(t, err)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{userAlternate}, users)
|
||||
|
||||
@@ -912,7 +914,7 @@ func testSearchUserBySubstringInAnyName(t *testing.T, th *SearchTestHelper) {
|
||||
require.NoError(t, err)
|
||||
|
||||
options = createDefaultOptions(true, false, false)
|
||||
users, err = th.Store.User().Search(th.Team.Id, "hello", options)
|
||||
users, err = th.Store.User().Search(th.Context, th.Team.Id, "hello", options)
|
||||
require.NoError(t, err)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{userAlternate}, users)
|
||||
})
|
||||
@@ -922,7 +924,7 @@ func testSearchUserBySubstringInAnyName(t *testing.T, th *SearchTestHelper) {
|
||||
defer th.deleteUser(userAlternate)
|
||||
|
||||
options := createDefaultOptions(true, false, false)
|
||||
users, err := th.Store.User().Search("", "hello", options)
|
||||
users, err := th.Store.User().Search(th.Context, "", "hello", options)
|
||||
require.NoError(t, err)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{userAlternate}, users)
|
||||
|
||||
@@ -934,7 +936,7 @@ func testSearchUserBySubstringInAnyName(t *testing.T, th *SearchTestHelper) {
|
||||
require.NoError(t, err)
|
||||
|
||||
options = createDefaultOptions(true, false, false)
|
||||
users, err = th.Store.User().Search(th.Team.Id, "hello", options)
|
||||
users, err = th.Store.User().Search(th.Context, th.Team.Id, "hello", options)
|
||||
require.NoError(t, err)
|
||||
th.assertUsersMatchInAnyOrder(t, []*model.User{userAlternate}, users)
|
||||
})
|
||||
|
||||
Ссылка в новой задаче
Block a user