github.com/dschalla/mattermost-server@v4.8.1-rc1+incompatible/cmd/platform/team_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 "testing" 8 9 "github.com/mattermost/mattermost-server/api" 10 "github.com/mattermost/mattermost-server/model" 11 ) 12 13 func TestCreateTeam(t *testing.T) { 14 th := api.Setup().InitSystemAdmin() 15 defer th.TearDown() 16 17 id := model.NewId() 18 name := "name" + id 19 displayName := "Name " + id 20 21 checkCommand(t, "team", "create", "--name", name, "--display_name", displayName) 22 23 found := th.SystemAdminClient.Must(th.SystemAdminClient.FindTeamByName(name)).Data.(bool) 24 25 if !found { 26 t.Fatal("Failed to create Team") 27 } 28 } 29 30 func TestJoinTeam(t *testing.T) { 31 th := api.Setup().InitSystemAdmin().InitBasic() 32 defer th.TearDown() 33 34 checkCommand(t, "team", "add", th.SystemAdminTeam.Name, th.BasicUser.Email) 35 36 profiles := th.SystemAdminClient.Must(th.SystemAdminClient.GetProfilesInTeam(th.SystemAdminTeam.Id, 0, 1000, "")).Data.(map[string]*model.User) 37 38 found := false 39 40 for _, user := range profiles { 41 if user.Email == th.BasicUser.Email { 42 found = true 43 } 44 45 } 46 47 if !found { 48 t.Fatal("Failed to create User") 49 } 50 } 51 52 func TestLeaveTeam(t *testing.T) { 53 th := api.Setup().InitBasic() 54 defer th.TearDown() 55 56 checkCommand(t, "team", "remove", th.BasicTeam.Name, th.BasicUser.Email) 57 58 profiles := th.BasicClient.Must(th.BasicClient.GetProfilesInTeam(th.BasicTeam.Id, 0, 1000, "")).Data.(map[string]*model.User) 59 60 found := false 61 62 for _, user := range profiles { 63 if user.Email == th.BasicUser.Email { 64 found = true 65 } 66 67 } 68 69 if found { 70 t.Fatal("profile should not be on team") 71 } 72 73 if result := <-th.App.Srv.Store.Team().GetTeamsByUserId(th.BasicUser.Id); result.Err != nil { 74 teamMembers := result.Data.([]*model.TeamMember) 75 if len(teamMembers) > 0 { 76 t.Fatal("Shouldn't be in team") 77 } 78 } 79 }