summaryrefslogtreecommitdiffstats
path: root/api4/channel_test.go
diff options
context:
space:
mode:
authorChristopher Speller <crspeller@gmail.com>2018-03-26 12:41:06 -0700
committerGitHub <noreply@github.com>2018-03-26 12:41:06 -0700
commit4a69c277a620308959ad6870d4e7c8240f9a166d (patch)
tree11d3342d379e9dd937ecd14c05f94931da440f29 /api4/channel_test.go
parent2bf2b5b851dfc693e5afa9648b5bbb9e6321b7fe (diff)
downloadchat-4a69c277a620308959ad6870d4e7c8240f9a166d.tar.gz
chat-4a69c277a620308959ad6870d4e7c8240f9a166d.tar.bz2
chat-4a69c277a620308959ad6870d4e7c8240f9a166d.zip
Adding go client support and basic unit tests for channel autocomplete. (#8510)
Diffstat (limited to 'api4/channel_test.go')
-rw-r--r--api4/channel_test.go73
1 files changed, 73 insertions, 0 deletions
diff --git a/api4/channel_test.go b/api4/channel_test.go
index 51c32cf71..427607dc5 100644
--- a/api4/channel_test.go
+++ b/api4/channel_test.go
@@ -13,6 +13,7 @@ import (
"testing"
"github.com/mattermost/mattermost-server/model"
+ "github.com/mattermost/mattermost-server/utils"
)
func TestCreateChannel(t *testing.T) {
@@ -2015,3 +2016,75 @@ func TestRemoveChannelMember(t *testing.T) {
_, resp = th.SystemAdminClient.RemoveUserFromChannel(privateChannel.Id, user2.Id)
CheckNoError(t, resp)
}
+
+func TestAutocompleteChannels(t *testing.T) {
+ th := Setup().InitBasic()
+ defer th.TearDown()
+
+ // A private channel to make sure private channels are not used
+ utils.DisableDebugLogForTest()
+ ptown, _ := th.Client.CreateChannel(&model.Channel{
+ DisplayName: "Town",
+ Name: "town",
+ Type: model.CHANNEL_PRIVATE,
+ TeamId: th.BasicTeam.Id,
+ })
+ utils.EnableDebugLogForTest()
+ defer func() {
+ th.Client.DeleteChannel(ptown.Id)
+ }()
+
+ for _, tc := range []struct {
+ description string
+ teamId string
+ fragment string
+ expectedIncludes []string
+ expectedExcludes []string
+ }{
+ {
+ "Basic town-square",
+ th.BasicTeam.Id,
+ "town",
+ []string{"town-square"},
+ []string{"off-topic", "town"},
+ },
+ {
+ "Basic off-topic",
+ th.BasicTeam.Id,
+ "off-to",
+ []string{"off-topic"},
+ []string{"town-square", "town"},
+ },
+ {
+ "Basic town square and off topic",
+ th.BasicTeam.Id,
+ "to",
+ []string{"off-topic", "town-square"},
+ []string{"town"},
+ },
+ } {
+ if channels, resp := th.Client.AutocompleteChannelsForTeam(tc.teamId, tc.fragment); resp.Error != nil {
+ t.Fatal("Test case " + tc.description + " failed. Err: " + resp.Error.Error())
+ } else {
+ for _, expectedInclude := range tc.expectedIncludes {
+ found := false
+ for _, channel := range *channels {
+ if channel.Name == expectedInclude {
+ found = true
+ break
+ }
+ }
+ if !found {
+ t.Fatal("Test case " + tc.description + " failed. Expected but didn't find channel: " + expectedInclude)
+ }
+ }
+ for _, expectedExclude := range tc.expectedExcludes {
+ for _, channel := range *channels {
+ if channel.Name == expectedExclude {
+ t.Fatal("Test case " + tc.description + " failed. Found channel we didn't want: " + expectedExclude)
+ }
+ }
+ }
+ }
+ }
+}