github.com/coincircle/mattermost-server@v4.8.1-0.20180321182714-9d701c704416+incompatible/cmd/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 "testing" 8 9 "github.com/mattermost/mattermost-server/api" 10 "github.com/mattermost/mattermost-server/cmd" 11 "github.com/mattermost/mattermost-server/model" 12 ) 13 14 func TestCreateTeam(t *testing.T) { 15 th := api.Setup().InitSystemAdmin() 16 defer th.TearDown() 17 18 id := model.NewId() 19 name := "name" + id 20 displayName := "Name " + id 21 22 cmd.CheckCommand(t, "team", "create", "--name", name, "--display_name", displayName) 23 24 found := th.SystemAdminClient.Must(th.SystemAdminClient.FindTeamByName(name)).Data.(bool) 25 26 if !found { 27 t.Fatal("Failed to create Team") 28 } 29 } 30 31 func TestJoinTeam(t *testing.T) { 32 th := api.Setup().InitSystemAdmin().InitBasic() 33 defer th.TearDown() 34 35 cmd.CheckCommand(t, "team", "add", th.SystemAdminTeam.Name, th.BasicUser.Email) 36 37 profiles := th.SystemAdminClient.Must(th.SystemAdminClient.GetProfilesInTeam(th.SystemAdminTeam.Id, 0, 1000, "")).Data.(map[string]*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 := api.Setup().InitBasic() 55 defer th.TearDown() 56 57 cmd.CheckCommand(t, "team", "remove", th.BasicTeam.Name, th.BasicUser.Email) 58 59 profiles := th.BasicClient.Must(th.BasicClient.GetProfilesInTeam(th.BasicTeam.Id, 0, 1000, "")).Data.(map[string]*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 }