github.com/qichengzx/mattermost-server@v4.5.1-0.20180604164826-2c75247c97d0+incompatible/cmd/mattermost/commands/team_test.go (about) 1 // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. 2 // See License.txt for license information. 3 4 package commands 5 6 import ( 7 "strings" 8 "testing" 9 10 "github.com/mattermost/mattermost-server/api4" 11 "github.com/mattermost/mattermost-server/model" 12 ) 13 14 func TestCreateTeam(t *testing.T) { 15 th := api4.Setup().InitSystemAdmin() 16 defer th.TearDown() 17 18 id := model.NewId() 19 name := "name" + id 20 displayName := "Name " + id 21 22 CheckCommand(t, "team", "create", "--name", name, "--display_name", displayName) 23 24 found := th.SystemAdminClient.Must(th.SystemAdminClient.TeamExists(name, "")).(bool) 25 26 if !found { 27 t.Fatal("Failed to create Team") 28 } 29 } 30 31 func TestJoinTeam(t *testing.T) { 32 th := api4.Setup().InitSystemAdmin().InitBasic() 33 defer th.TearDown() 34 35 CheckCommand(t, "team", "add", th.BasicTeam.Name, th.BasicUser.Email) 36 37 profiles := th.SystemAdminClient.Must(th.SystemAdminClient.GetUsersInTeam(th.BasicTeam.Id, 0, 1000, "")).([]*model.User) 38 39 found := false 40 41 for _, user := range profiles { 42 if user.Email == th.BasicUser.Email { 43 found = true 44 } 45 46 } 47 48 if !found { 49 t.Fatal("Failed to create User") 50 } 51 } 52 53 func TestLeaveTeam(t *testing.T) { 54 th := api4.Setup().InitBasic() 55 defer th.TearDown() 56 57 CheckCommand(t, "team", "remove", th.BasicTeam.Name, th.BasicUser.Email) 58 59 profiles := th.Client.Must(th.Client.GetUsersInTeam(th.BasicTeam.Id, 0, 1000, "")).([]*model.User) 60 61 found := false 62 63 for _, user := range profiles { 64 if user.Email == th.BasicUser.Email { 65 found = true 66 } 67 68 } 69 70 if found { 71 t.Fatal("profile should not be on team") 72 } 73 74 if result := <-th.App.Srv.Store.Team().GetTeamsByUserId(th.BasicUser.Id); result.Err != nil { 75 teamMembers := result.Data.([]*model.TeamMember) 76 if len(teamMembers) > 0 { 77 t.Fatal("Shouldn't be in team") 78 } 79 } 80 } 81 82 func TestListTeams(t *testing.T) { 83 th := api4.Setup().InitBasic() 84 defer th.TearDown() 85 86 id := model.NewId() 87 name := "name" + id 88 displayName := "Name " + id 89 90 CheckCommand(t, "team", "create", "--name", name, "--display_name", displayName) 91 92 output := CheckCommand(t, "team", "list", th.BasicTeam.Name, th.BasicUser.Email) 93 94 if !strings.Contains(string(output), name) { 95 t.Fatal("should have the created team") 96 } 97 }