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