github.com/haalcala/mattermost-server-change-repo/v5@v5.33.2/store/searchtest/channel_layer.go (about) 1 // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. 2 // See LICENSE.txt for license information. 3 4 package searchtest 5 6 import ( 7 "testing" 8 9 "github.com/stretchr/testify/require" 10 11 "github.com/mattermost/mattermost-server/v5/model" 12 "github.com/mattermost/mattermost-server/v5/store" 13 ) 14 15 var searchChannelStoreTests = []searchTest{ 16 { 17 Name: "Should be able to autocomplete a channel by name", 18 Fn: testAutocompleteChannelByName, 19 Tags: []string{EngineAll}, 20 }, 21 { 22 Name: "Should be able to autocomplete a channel by display name", 23 Fn: testAutocompleteChannelByDisplayName, 24 Tags: []string{EngineAll}, 25 }, 26 { 27 Name: "Should be able to autocomplete a channel by a part of its name when has parts splitted by - character", 28 Fn: testAutocompleteChannelByNameSplittedWithDashChar, 29 Tags: []string{EngineAll}, 30 }, 31 { 32 Name: "Should be able to autocomplete a channel by a part of its name when has parts splitted by _ character", 33 Fn: testAutocompleteChannelByNameSplittedWithUnderscoreChar, 34 Tags: []string{EngineMySql, EngineElasticSearch, EngineBleve}, 35 }, 36 { 37 Name: "Should be able to autocomplete a channel by a part of its display name when has parts splitted by whitespace character", 38 Fn: testAutocompleteChannelByDisplayNameSplittedByWhitespaces, 39 Tags: []string{EngineMySql, EngineElasticSearch, EngineBleve}, 40 }, 41 { 42 Name: "Should be able to autocomplete retrieving all channels if the term is empty", 43 Fn: testAutocompleteAllChannelsIfTermIsEmpty, 44 Tags: []string{EngineAll}, 45 }, 46 { 47 Name: "Should be able to autocomplete channels in a case insensitive manner", 48 Fn: testSearchChannelsInCaseInsensitiveManner, 49 Tags: []string{EngineAll}, 50 }, 51 { 52 Name: "Should autocomplete only returning public channels", 53 Fn: testSearchOnlyPublicChannels, 54 Tags: []string{EngineAll}, 55 }, 56 { 57 Name: "Should support to autocomplete having a hyphen as the last character", 58 Fn: testSearchShouldSupportHavingHyphenAsLastCharacter, 59 Tags: []string{EngineAll}, 60 }, 61 { 62 Name: "Should support to autocomplete with archived channels", 63 Fn: testSearchShouldSupportAutocompleteWithArchivedChannels, 64 Tags: []string{EngineAll}, 65 }, 66 } 67 68 func TestSearchChannelStore(t *testing.T, s store.Store, testEngine *SearchTestEngine) { 69 th := &SearchTestHelper{ 70 Store: s, 71 } 72 err := th.SetupBasicFixtures() 73 require.NoError(t, err) 74 defer th.CleanFixtures() 75 runTestSearch(t, testEngine, searchChannelStoreTests, th) 76 } 77 78 func testAutocompleteChannelByName(t *testing.T, th *SearchTestHelper) { 79 alternate, err := th.createChannel(th.Team.Id, "channel-alternate", "Channel Alternate", "", model.CHANNEL_OPEN, false) 80 require.NoError(t, err) 81 defer th.deleteChannel(alternate) 82 res, err := th.Store.Channel().AutocompleteInTeam(th.Team.Id, "channel-a", false) 83 require.NoError(t, err) 84 th.checkChannelIdsMatch(t, []string{th.ChannelBasic.Id, alternate.Id}, res) 85 } 86 87 func testAutocompleteChannelByDisplayName(t *testing.T, th *SearchTestHelper) { 88 alternate, err := th.createChannel(th.Team.Id, "channel-alternate", "ChannelAlternate", "", model.CHANNEL_OPEN, false) 89 require.NoError(t, err) 90 defer th.deleteChannel(alternate) 91 res, err := th.Store.Channel().AutocompleteInTeam(th.Team.Id, "ChannelA", false) 92 require.NoError(t, err) 93 th.checkChannelIdsMatch(t, []string{th.ChannelBasic.Id, alternate.Id}, res) 94 } 95 96 func testAutocompleteChannelByNameSplittedWithDashChar(t *testing.T, th *SearchTestHelper) { 97 alternate, err := th.createChannel(th.Team.Id, "channel-alternate", "ChannelAlternate", "", model.CHANNEL_OPEN, false) 98 require.NoError(t, err) 99 defer th.deleteChannel(alternate) 100 res, err := th.Store.Channel().AutocompleteInTeam(th.Team.Id, "channel-a", false) 101 require.NoError(t, err) 102 th.checkChannelIdsMatch(t, []string{th.ChannelBasic.Id, alternate.Id}, res) 103 } 104 105 func testAutocompleteChannelByNameSplittedWithUnderscoreChar(t *testing.T, th *SearchTestHelper) { 106 alternate, err := th.createChannel(th.Team.Id, "channel_alternate", "ChannelAlternate", "", model.CHANNEL_OPEN, false) 107 require.NoError(t, err) 108 defer th.deleteChannel(alternate) 109 res, err := th.Store.Channel().AutocompleteInTeam(th.Team.Id, "channel_a", false) 110 require.NoError(t, err) 111 th.checkChannelIdsMatch(t, []string{alternate.Id}, res) 112 } 113 114 func testAutocompleteChannelByDisplayNameSplittedByWhitespaces(t *testing.T, th *SearchTestHelper) { 115 alternate, err := th.createChannel(th.Team.Id, "channel-alternate", "Channel Alternate", "", model.CHANNEL_OPEN, false) 116 require.NoError(t, err) 117 118 defer th.deleteChannel(alternate) 119 res, err := th.Store.Channel().AutocompleteInTeam(th.Team.Id, "Channel A", false) 120 require.NoError(t, err) 121 th.checkChannelIdsMatch(t, []string{alternate.Id}, res) 122 } 123 func testAutocompleteAllChannelsIfTermIsEmpty(t *testing.T, th *SearchTestHelper) { 124 alternate, err := th.createChannel(th.Team.Id, "channel-alternate", "Channel Alternate", "", model.CHANNEL_OPEN, false) 125 require.NoError(t, err) 126 other, err := th.createChannel(th.Team.Id, "other-channel", "Other Channel", "", model.CHANNEL_OPEN, false) 127 require.NoError(t, err) 128 defer th.deleteChannel(alternate) 129 defer th.deleteChannel(other) 130 res, err := th.Store.Channel().AutocompleteInTeam(th.Team.Id, "", false) 131 require.NoError(t, err) 132 th.checkChannelIdsMatch(t, []string{th.ChannelBasic.Id, alternate.Id, other.Id}, res) 133 } 134 135 func testSearchChannelsInCaseInsensitiveManner(t *testing.T, th *SearchTestHelper) { 136 alternate, err := th.createChannel(th.Team.Id, "channel-alternate", "ChannelAlternate", "", model.CHANNEL_OPEN, false) 137 require.NoError(t, err) 138 defer th.deleteChannel(alternate) 139 res, err := th.Store.Channel().AutocompleteInTeam(th.Team.Id, "channela", false) 140 require.NoError(t, err) 141 th.checkChannelIdsMatch(t, []string{th.ChannelBasic.Id, alternate.Id}, res) 142 res, err = th.Store.Channel().AutocompleteInTeam(th.Team.Id, "ChAnNeL-a", false) 143 require.NoError(t, err) 144 th.checkChannelIdsMatch(t, []string{th.ChannelBasic.Id, alternate.Id}, res) 145 } 146 147 func testSearchOnlyPublicChannels(t *testing.T, th *SearchTestHelper) { 148 alternate, err := th.createChannel(th.Team.Id, "channel-alternate", "ChannelAlternate", "", model.CHANNEL_PRIVATE, false) 149 require.NoError(t, err) 150 defer th.deleteChannel(alternate) 151 res, err := th.Store.Channel().AutocompleteInTeam(th.Team.Id, "channel-a", false) 152 require.NoError(t, err) 153 th.checkChannelIdsMatch(t, []string{th.ChannelBasic.Id}, res) 154 } 155 156 func testSearchShouldSupportHavingHyphenAsLastCharacter(t *testing.T, th *SearchTestHelper) { 157 alternate, err := th.createChannel(th.Team.Id, "channel-alternate", "ChannelAlternate", "", model.CHANNEL_OPEN, false) 158 require.NoError(t, err) 159 defer th.deleteChannel(alternate) 160 res, err := th.Store.Channel().AutocompleteInTeam(th.Team.Id, "channel-", false) 161 require.NoError(t, err) 162 th.checkChannelIdsMatch(t, []string{th.ChannelBasic.Id, alternate.Id}, res) 163 } 164 165 func testSearchShouldSupportAutocompleteWithArchivedChannels(t *testing.T, th *SearchTestHelper) { 166 res, err := th.Store.Channel().AutocompleteInTeam(th.Team.Id, "channel-", true) 167 require.NoError(t, err) 168 th.checkChannelIdsMatch(t, []string{th.ChannelBasic.Id, th.ChannelDeleted.Id}, res) 169 }