github.com/coincircle/mattermost-server@v4.8.1-0.20180321182714-9d701c704416+incompatible/api/command_join_test.go (about) 1 // Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved. 2 // See License.txt for license information. 3 4 package api 5 6 import ( 7 "strings" 8 "testing" 9 10 "github.com/mattermost/mattermost-server/model" 11 ) 12 13 // also used to test /open (see command_open_test.go) 14 func testJoinCommands(t *testing.T, alias string) { 15 th := Setup().InitBasic() 16 defer th.TearDown() 17 18 Client := th.BasicClient 19 team := th.BasicTeam 20 user2 := th.BasicUser2 21 22 channel0 := &model.Channel{DisplayName: "00", Name: "00" + model.NewId() + "a", Type: model.CHANNEL_OPEN, TeamId: team.Id} 23 channel0 = Client.Must(Client.CreateChannel(channel0)).Data.(*model.Channel) 24 25 channel1 := &model.Channel{DisplayName: "AA", Name: "aa" + model.NewId() + "a", Type: model.CHANNEL_OPEN, TeamId: team.Id} 26 channel1 = Client.Must(Client.CreateChannel(channel1)).Data.(*model.Channel) 27 Client.Must(Client.LeaveChannel(channel1.Id)) 28 29 channel2 := &model.Channel{DisplayName: "BB", Name: "bb" + model.NewId() + "a", Type: model.CHANNEL_OPEN, TeamId: team.Id} 30 channel2 = Client.Must(Client.CreateChannel(channel2)).Data.(*model.Channel) 31 Client.Must(Client.LeaveChannel(channel2.Id)) 32 33 channel3 := Client.Must(Client.CreateDirectChannel(user2.Id)).Data.(*model.Channel) 34 35 rs5 := Client.Must(Client.Command(channel0.Id, "/"+alias+" "+channel2.Name)).Data.(*model.CommandResponse) 36 if !strings.HasSuffix(rs5.GotoLocation, "/"+team.Name+"/channels/"+channel2.Name) { 37 t.Fatal("failed to join channel") 38 } 39 40 rs6 := Client.Must(Client.Command(channel0.Id, "/"+alias+" "+channel3.Name)).Data.(*model.CommandResponse) 41 if strings.HasSuffix(rs6.GotoLocation, "/"+team.Name+"/channels/"+channel3.Name) { 42 t.Fatal("should not have joined direct message channel") 43 } 44 45 c1 := Client.Must(Client.GetChannels("")).Data.(*model.ChannelList) 46 47 found := false 48 for _, c := range *c1 { 49 if c.Id == channel2.Id { 50 found = true 51 } 52 } 53 54 if !found { 55 t.Fatal("did not join channel") 56 } 57 } 58 59 func TestJoinCommands(t *testing.T) { 60 testJoinCommands(t, "join") 61 }