github.com/jfrerich/mattermost-server@v5.8.0-rc2+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/model"
    11  	"github.com/stretchr/testify/require"
    12  )
    13  
    14  func TestCreateTeam(t *testing.T) {
    15  	th := Setup().InitBasic()
    16  	defer th.TearDown()
    17  
    18  	id := model.NewId()
    19  	name := "name" + id
    20  	displayName := "Name " + id
    21  
    22  	th.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 := Setup().InitBasic()
    33  	defer th.TearDown()
    34  
    35  	th.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 := Setup().InitBasic()
    55  	defer th.TearDown()
    56  
    57  	th.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 := Setup().InitBasic()
    84  	defer th.TearDown()
    85  
    86  	id := model.NewId()
    87  	name := "name" + id
    88  	displayName := "Name " + id
    89  
    90  	th.CheckCommand(t, "team", "create", "--name", name, "--display_name", displayName)
    91  
    92  	output := th.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  }
    98  
    99  func TestListArchivedTeams(t *testing.T) {
   100  	th := Setup().InitBasic()
   101  	defer th.TearDown()
   102  
   103  	id := model.NewId()
   104  	name := "name" + id
   105  	displayName := "Name " + id
   106  
   107  	th.CheckCommand(t, "team", "create", "--name", name, "--display_name", displayName)
   108  
   109  	th.CheckCommand(t, "team", "archive", name)
   110  
   111  	output := th.CheckCommand(t, "team", "list", th.BasicTeam.Name, th.BasicUser.Email)
   112  
   113  	if !strings.Contains(string(output), name+" (archived)") {
   114  		t.Fatal("should have archived team")
   115  	}
   116  }
   117  
   118  func TestSearchTeamsByName(t *testing.T) {
   119  	th := Setup().InitBasic()
   120  	defer th.TearDown()
   121  
   122  	id := model.NewId()
   123  	name := "name" + id
   124  	displayName := "Name " + id
   125  
   126  	th.CheckCommand(t, "team", "create", "--name", name, "--display_name", displayName)
   127  
   128  	output := th.CheckCommand(t, "team", "search", name)
   129  
   130  	if !strings.Contains(string(output), name) {
   131  		t.Fatal("should have the created team")
   132  	}
   133  }
   134  
   135  func TestSearchTeamsByDisplayName(t *testing.T) {
   136  	th := Setup().InitBasic()
   137  	defer th.TearDown()
   138  
   139  	id := model.NewId()
   140  	name := "name" + id
   141  	displayName := "Name " + id
   142  
   143  	th.CheckCommand(t, "team", "create", "--name", name, "--display_name", displayName)
   144  
   145  	output := th.CheckCommand(t, "team", "search", displayName)
   146  
   147  	if !strings.Contains(string(output), name) {
   148  		t.Fatal("should have the created team")
   149  	}
   150  }
   151  
   152  func TestSearchArchivedTeamsByName(t *testing.T) {
   153  	th := Setup().InitBasic()
   154  	defer th.TearDown()
   155  
   156  	id := model.NewId()
   157  	name := "name" + id
   158  	displayName := "Name " + id
   159  
   160  	th.CheckCommand(t, "team", "create", "--name", name, "--display_name", displayName)
   161  
   162  	th.CheckCommand(t, "team", "archive", name)
   163  
   164  	output := th.CheckCommand(t, "team", "search", name)
   165  
   166  	if !strings.Contains(string(output), "(archived)") {
   167  		t.Fatal("should have archived team")
   168  	}
   169  }
   170  
   171  func TestArchiveTeams(t *testing.T) {
   172  	th := Setup().InitBasic()
   173  	defer th.TearDown()
   174  
   175  	id := model.NewId()
   176  	name := "name" + id
   177  	displayName := "Name " + id
   178  
   179  	th.CheckCommand(t, "team", "create", "--name", name, "--display_name", displayName)
   180  
   181  	th.CheckCommand(t, "team", "archive", name)
   182  
   183  	output := th.CheckCommand(t, "team", "list")
   184  
   185  	if !strings.Contains(string(output), name+" (archived)") {
   186  		t.Fatal("should have archived team")
   187  	}
   188  }
   189  
   190  func TestRestoreTeams(t *testing.T) {
   191  	th := Setup().InitBasic()
   192  	defer th.TearDown()
   193  
   194  	id := model.NewId()
   195  	name := "name" + id
   196  	displayName := "Name " + id
   197  
   198  	th.CheckCommand(t, "team", "create", "--name", name, "--display_name", displayName)
   199  
   200  	th.CheckCommand(t, "team", "archive", name)
   201  
   202  	th.CheckCommand(t, "team", "restore", name)
   203  
   204  	found := th.SystemAdminClient.Must(th.SystemAdminClient.TeamExists(name, "")).(bool)
   205  
   206  	require.True(t, found)
   207  }