github.com/gigforks/mattermost-server@v4.9.1-0.20180619094218-800d97fa55d0+incompatible/api/command_groupmsg_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 func TestGroupmsgCommands(t *testing.T) { 14 th := Setup().InitBasic() 15 defer th.TearDown() 16 17 Client := th.BasicClient 18 team := th.BasicTeam 19 user1 := th.BasicUser 20 user2 := th.BasicUser2 21 user3 := th.CreateUser(th.BasicClient) 22 user4 := th.CreateUser(th.BasicClient) 23 user5 := th.CreateUser(th.BasicClient) 24 user6 := th.CreateUser(th.BasicClient) 25 user7 := th.CreateUser(th.BasicClient) 26 user8 := th.CreateUser(th.BasicClient) 27 user9 := th.CreateUser(th.BasicClient) 28 th.LinkUserToTeam(user3, team) 29 th.LinkUserToTeam(user4, team) 30 31 rs1 := Client.Must(Client.Command("", "/groupmsg "+user2.Username+","+user3.Username)).Data.(*model.CommandResponse) 32 33 group1 := model.GetGroupNameFromUserIds([]string{user1.Id, user2.Id, user3.Id}) 34 35 if !strings.HasSuffix(rs1.GotoLocation, "/"+team.Name+"/channels/"+group1) { 36 t.Fatal("failed to create group channel") 37 } 38 39 rs2 := Client.Must(Client.Command("", "/groupmsg "+user3.Username+","+user4.Username+" foobar")).Data.(*model.CommandResponse) 40 group2 := model.GetGroupNameFromUserIds([]string{user1.Id, user3.Id, user4.Id}) 41 42 if !strings.HasSuffix(rs2.GotoLocation, "/"+team.Name+"/channels/"+group2) { 43 t.Fatal("failed to create second direct channel") 44 } 45 if result := Client.Must(Client.SearchPosts("foobar", false)).Data.(*model.PostList); len(result.Order) == 0 { 46 t.Fatal("post did not get sent to direct message") 47 } 48 49 rs3 := Client.Must(Client.Command("", "/groupmsg "+user2.Username+","+user3.Username)).Data.(*model.CommandResponse) 50 if !strings.HasSuffix(rs3.GotoLocation, "/"+team.Name+"/channels/"+group1) { 51 t.Fatal("failed to go back to existing group channel") 52 } 53 54 Client.Must(Client.Command("", "/groupmsg "+user2.Username+" foobar")) 55 Client.Must(Client.Command("", "/groupmsg "+user2.Username+","+user3.Username+","+user4.Username+","+user5.Username+","+user6.Username+","+user7.Username+","+user8.Username+","+user9.Username+" foobar")) 56 Client.Must(Client.Command("", "/groupmsg junk foobar")) 57 Client.Must(Client.Command("", "/groupmsg junk,junk2 foobar")) 58 }