Migrate tests from "cmd/mattermost/commands/team_test.go" to use test… (#12509)
* Migrate tests from "cmd/mattermost/commands/team_test.go" to use testify #12410 * #12410: Simplify if checks Migrate tests from "cmd/mattermost/commands/team_test.go" to use testify #12410
Этот коммит содержится в:
коммит произвёл
Saturnino Abril
родитель
714a5c3c29
Коммит
f010346945
@@ -4,10 +4,10 @@
|
|||||||
package commands
|
package commands
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strings"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/mattermost/mattermost-server/model"
|
"github.com/mattermost/mattermost-server/model"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -23,9 +23,7 @@ func TestCreateTeam(t *testing.T) {
|
|||||||
|
|
||||||
found := th.SystemAdminClient.Must(th.SystemAdminClient.TeamExists(name, "")).(bool)
|
found := th.SystemAdminClient.Must(th.SystemAdminClient.TeamExists(name, "")).(bool)
|
||||||
|
|
||||||
if !found {
|
require.True(t, found, "Failed to create Team")
|
||||||
t.Fatal("Failed to create Team")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestJoinTeam(t *testing.T) {
|
func TestJoinTeam(t *testing.T) {
|
||||||
@@ -45,9 +43,7 @@ func TestJoinTeam(t *testing.T) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if !found {
|
require.True(t, found, "Failed to create User")
|
||||||
t.Fatal("Failed to create User")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLeaveTeam(t *testing.T) {
|
func TestLeaveTeam(t *testing.T) {
|
||||||
@@ -67,15 +63,11 @@ func TestLeaveTeam(t *testing.T) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if found {
|
require.False(t, found, "profile should not be on team")
|
||||||
t.Fatal("profile should not be on team")
|
|
||||||
}
|
|
||||||
|
|
||||||
if teams, err := th.App.Srv.Store.Team().GetTeamsByUserId(th.BasicUser.Id); err != nil {
|
teams, err := th.App.Srv.Store.Team().GetTeamsByUserId(th.BasicUser.Id)
|
||||||
if len(teams) > 0 {
|
require.Nil(t, err)
|
||||||
t.Fatal("Shouldn't be in team")
|
require.Equal(t, 0, len(teams), "Shouldn't be in team")
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestListTeams(t *testing.T) {
|
func TestListTeams(t *testing.T) {
|
||||||
@@ -90,9 +82,7 @@ func TestListTeams(t *testing.T) {
|
|||||||
|
|
||||||
output := th.CheckCommand(t, "team", "list", th.BasicTeam.Name, th.BasicUser.Email)
|
output := th.CheckCommand(t, "team", "list", th.BasicTeam.Name, th.BasicUser.Email)
|
||||||
|
|
||||||
if !strings.Contains(string(output), name) {
|
assert.Contains(t, output, name, "should have the created team")
|
||||||
t.Fatal("should have the created team")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestListArchivedTeams(t *testing.T) {
|
func TestListArchivedTeams(t *testing.T) {
|
||||||
@@ -109,9 +99,7 @@ func TestListArchivedTeams(t *testing.T) {
|
|||||||
|
|
||||||
output := th.CheckCommand(t, "team", "list", th.BasicTeam.Name, th.BasicUser.Email)
|
output := th.CheckCommand(t, "team", "list", th.BasicTeam.Name, th.BasicUser.Email)
|
||||||
|
|
||||||
if !strings.Contains(string(output), name+" (archived)") {
|
assert.Contains(t, output, name+" (archived)", "should have archived team")
|
||||||
t.Fatal("should have archived team")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSearchTeamsByName(t *testing.T) {
|
func TestSearchTeamsByName(t *testing.T) {
|
||||||
@@ -126,9 +114,7 @@ func TestSearchTeamsByName(t *testing.T) {
|
|||||||
|
|
||||||
output := th.CheckCommand(t, "team", "search", name)
|
output := th.CheckCommand(t, "team", "search", name)
|
||||||
|
|
||||||
if !strings.Contains(string(output), name) {
|
assert.Contains(t, output, name, "should have the created team")
|
||||||
t.Fatal("should have the created team")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSearchTeamsByDisplayName(t *testing.T) {
|
func TestSearchTeamsByDisplayName(t *testing.T) {
|
||||||
@@ -143,9 +129,7 @@ func TestSearchTeamsByDisplayName(t *testing.T) {
|
|||||||
|
|
||||||
output := th.CheckCommand(t, "team", "search", displayName)
|
output := th.CheckCommand(t, "team", "search", displayName)
|
||||||
|
|
||||||
if !strings.Contains(string(output), name) {
|
assert.Contains(t, output, name, "should have the created team")
|
||||||
t.Fatal("should have the created team")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSearchArchivedTeamsByName(t *testing.T) {
|
func TestSearchArchivedTeamsByName(t *testing.T) {
|
||||||
@@ -162,9 +146,7 @@ func TestSearchArchivedTeamsByName(t *testing.T) {
|
|||||||
|
|
||||||
output := th.CheckCommand(t, "team", "search", name)
|
output := th.CheckCommand(t, "team", "search", name)
|
||||||
|
|
||||||
if !strings.Contains(string(output), "(archived)") {
|
assert.Contains(t, output, "(archived)", "should have archived team")
|
||||||
t.Fatal("should have archived team")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestArchiveTeams(t *testing.T) {
|
func TestArchiveTeams(t *testing.T) {
|
||||||
@@ -181,9 +163,7 @@ func TestArchiveTeams(t *testing.T) {
|
|||||||
|
|
||||||
output := th.CheckCommand(t, "team", "list")
|
output := th.CheckCommand(t, "team", "list")
|
||||||
|
|
||||||
if !strings.Contains(string(output), name+" (archived)") {
|
assert.Contains(t, output, name+" (archived)", "should have archived team")
|
||||||
t.Fatal("should have archived team")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRestoreTeams(t *testing.T) {
|
func TestRestoreTeams(t *testing.T) {
|
||||||
@@ -219,13 +199,8 @@ func TestRenameTeam(t *testing.T) {
|
|||||||
// Get the team from the DB
|
// Get the team from the DB
|
||||||
updatedTeam, _ := th.App.GetTeam(team.Id)
|
updatedTeam, _ := th.App.GetTeam(team.Id)
|
||||||
|
|
||||||
if updatedTeam.Name != newTeamName {
|
require.Equal(t, updatedTeam.Name, newTeamName, "failed renaming team")
|
||||||
t.Fatal("failed renaming team")
|
require.Equal(t, updatedTeam.DisplayName, newDisplayName, "failed updating team display name")
|
||||||
}
|
|
||||||
|
|
||||||
if updatedTeam.DisplayName != newDisplayName {
|
|
||||||
t.Fatal("failed updating team display name")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Try to rename to occupied name
|
// Try to rename to occupied name
|
||||||
team2 := th.CreateTeam()
|
team2 := th.CreateTeam()
|
||||||
@@ -235,13 +210,8 @@ func TestRenameTeam(t *testing.T) {
|
|||||||
th.CheckCommand(t, "team", "rename", team2.Name, newTeamName, "--display_name", newDisplayName)
|
th.CheckCommand(t, "team", "rename", team2.Name, newTeamName, "--display_name", newDisplayName)
|
||||||
|
|
||||||
// No renaming should have occured
|
// No renaming should have occured
|
||||||
if team2.Name != n {
|
require.Equal(t, team2.Name, n, "team was renamed when it should have not been")
|
||||||
t.Fatal("team was renamed when it should have not been")
|
require.Equal(t, team2.DisplayName, dn, "team display name was changed when it should have not been")
|
||||||
}
|
|
||||||
|
|
||||||
if team2.DisplayName != dn {
|
|
||||||
t.Fatal("team display name was changed when it should have not been")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Try to change only Display Name
|
// Try to change only Display Name
|
||||||
team3 := th.CreateTeam()
|
team3 := th.CreateTeam()
|
||||||
@@ -252,13 +222,8 @@ func TestRenameTeam(t *testing.T) {
|
|||||||
// Get the team from the DB
|
// Get the team from the DB
|
||||||
updatedTeam, _ = th.App.GetTeam(team3.Id)
|
updatedTeam, _ = th.App.GetTeam(team3.Id)
|
||||||
|
|
||||||
if updatedTeam.Name == "-" {
|
require.NotEqual(t, updatedTeam.Name, "-", "team was renamed to `-` but only display name should have been changed")
|
||||||
t.Fatal("team was renamed to `-` but only display name should have been changed")
|
require.Equal(t, updatedTeam.DisplayName, newDisplayName, "team Display Name was not properly updated")
|
||||||
}
|
|
||||||
|
|
||||||
if updatedTeam.DisplayName != newDisplayName {
|
|
||||||
t.Fatal("team Display Name was not properly updated")
|
|
||||||
}
|
|
||||||
|
|
||||||
// now try to change Display Name using old team name
|
// now try to change Display Name using old team name
|
||||||
th.CheckCommand(t, "team", "rename", team3.Name, team3.Name, "--display_name", "Brand New DName")
|
th.CheckCommand(t, "team", "rename", team3.Name, team3.Name, "--display_name", "Brand New DName")
|
||||||
@@ -266,10 +231,7 @@ func TestRenameTeam(t *testing.T) {
|
|||||||
// Get the team from the DB
|
// Get the team from the DB
|
||||||
updatedTeam, _ = th.App.GetTeam(team3.Id)
|
updatedTeam, _ = th.App.GetTeam(team3.Id)
|
||||||
|
|
||||||
if updatedTeam.DisplayName != "Brand New DName" {
|
require.Equal(t, updatedTeam.DisplayName, "Brand New DName", "team Display Name was not properly updated")
|
||||||
t.Fatal("team Display Name was not properly updated")
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestModifyTeam(t *testing.T) {
|
func TestModifyTeam(t *testing.T) {
|
||||||
@@ -282,14 +244,9 @@ func TestModifyTeam(t *testing.T) {
|
|||||||
|
|
||||||
updatedTeam, _ := th.App.GetTeam(team.Id)
|
updatedTeam, _ := th.App.GetTeam(team.Id)
|
||||||
|
|
||||||
if !updatedTeam.AllowOpenInvite && team.Type == model.TEAM_INVITE {
|
require.False(t, !updatedTeam.AllowOpenInvite && team.Type == model.TEAM_INVITE, "Failed modifying team's privacy to private")
|
||||||
t.Fatal("Failed modifying team's privacy to private")
|
|
||||||
}
|
|
||||||
|
|
||||||
th.CheckCommand(t, "team", "modify", team.Name, "--public")
|
th.CheckCommand(t, "team", "modify", team.Name, "--public")
|
||||||
|
|
||||||
if updatedTeam.AllowOpenInvite && team.Type == model.TEAM_OPEN {
|
require.False(t, updatedTeam.AllowOpenInvite && team.Type == model.TEAM_OPEN, "Failed modifying team's privacy to private")
|
||||||
t.Fatal("Failed modifying team's privacy to private")
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user