github.com/psyb0t/mattermost-server@v4.6.1-0.20180125161845-5503a1351abf+incompatible/cmd/platform/channel_test.go (about) 1 // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. 2 // See License.txt for license information. 3 4 package main 5 6 import ( 7 "strings" 8 "testing" 9 10 "github.com/mattermost/mattermost-server/api" 11 "github.com/mattermost/mattermost-server/model" 12 "github.com/stretchr/testify/require" 13 ) 14 15 func TestJoinChannel(t *testing.T) { 16 th := api.Setup().InitBasic() 17 defer th.TearDown() 18 19 channel := th.CreateChannel(th.BasicClient, th.BasicTeam) 20 21 checkCommand(t, "channel", "add", th.BasicTeam.Name+":"+channel.Name, th.BasicUser2.Email) 22 23 // Joining twice should succeed 24 checkCommand(t, "channel", "add", th.BasicTeam.Name+":"+channel.Name, th.BasicUser2.Email) 25 26 // should fail because channel does not exist 27 require.Error(t, runCommand(t, "channel", "add", th.BasicTeam.Name+":"+channel.Name+"asdf", th.BasicUser2.Email)) 28 } 29 30 func TestRemoveChannel(t *testing.T) { 31 th := api.Setup().InitBasic() 32 defer th.TearDown() 33 34 channel := th.CreateChannel(th.BasicClient, th.BasicTeam) 35 36 checkCommand(t, "channel", "add", th.BasicTeam.Name+":"+channel.Name, th.BasicUser2.Email) 37 38 // should fail because channel does not exist 39 require.Error(t, runCommand(t, "channel", "remove", th.BasicTeam.Name+":doesnotexist", th.BasicUser2.Email)) 40 41 checkCommand(t, "channel", "remove", th.BasicTeam.Name+":"+channel.Name, th.BasicUser2.Email) 42 43 // Leaving twice should succeed 44 checkCommand(t, "channel", "remove", th.BasicTeam.Name+":"+channel.Name, th.BasicUser2.Email) 45 } 46 47 func TestListChannels(t *testing.T) { 48 th := api.Setup().InitBasic() 49 defer th.TearDown() 50 51 channel := th.CreateChannel(th.BasicClient, th.BasicTeam) 52 th.BasicClient.Must(th.BasicClient.DeleteChannel(channel.Id)) 53 54 output := checkCommand(t, "channel", "list", th.BasicTeam.Name) 55 56 if !strings.Contains(string(output), "town-square") { 57 t.Fatal("should have channels") 58 } 59 60 if !strings.Contains(string(output), channel.Name+" (archived)") { 61 t.Fatal("should have archived channel") 62 } 63 } 64 65 func TestRestoreChannel(t *testing.T) { 66 th := api.Setup().InitBasic() 67 defer th.TearDown() 68 69 channel := th.CreateChannel(th.BasicClient, th.BasicTeam) 70 th.BasicClient.Must(th.BasicClient.DeleteChannel(channel.Id)) 71 72 checkCommand(t, "channel", "restore", th.BasicTeam.Name+":"+channel.Name) 73 74 // restoring twice should succeed 75 checkCommand(t, "channel", "restore", th.BasicTeam.Name+":"+channel.Name) 76 } 77 78 func TestCreateChannel(t *testing.T) { 79 th := api.Setup().InitBasic() 80 defer th.TearDown() 81 82 id := model.NewId() 83 name := "name" + id 84 85 checkCommand(t, "channel", "create", "--display_name", name, "--team", th.BasicTeam.Name, "--name", name) 86 87 name = name + "-private" 88 checkCommand(t, "channel", "create", "--display_name", name, "--team", th.BasicTeam.Name, "--private", "--name", name) 89 }