Migrate tests from "cmd/mattermost/commands/roles_test.go" to… (#12421)
* migrated tests in roles_test.go to use testify * format file * format file and edit some test statements * change some require statements to assert * remove extra t.Fatal * test error on response * use require.NotEmpty
Этот коммит содержится в:
коммит произвёл
jfrerich
родитель
894b124bc6
Коммит
d290534297
@@ -114,16 +114,17 @@ func TestCreateCommand(t *testing.T) {
|
||||
t.Run(testCase.Description, func(t *testing.T) {
|
||||
actual, _ := th.RunCommandWithOutput(t, testCase.Args...)
|
||||
|
||||
cmds, _ := th.SystemAdminClient.ListCommands(team.Id, true)
|
||||
cmds, response := th.SystemAdminClient.ListCommands(team.Id, true)
|
||||
|
||||
require.Nil(t, response.Error, "Failed to list commands")
|
||||
|
||||
if testCase.ExpectedErr == "" {
|
||||
if len(cmds) == 0 || cmds[0].Trigger != "testcmd" {
|
||||
t.Fatal("Failed to create command")
|
||||
}
|
||||
require.NotEmpty(t, cmds, "Failed to create command")
|
||||
require.Equal(t, "testcmd", cmds[0].Trigger)
|
||||
assert.Contains(t, string(actual), "PASS")
|
||||
} else {
|
||||
if len(cmds) > 1 {
|
||||
t.Fatal("Created command that shouldn't have been created")
|
||||
require.Fail(t, "Created command that shouldn't have been created")
|
||||
}
|
||||
assert.Contains(t, string(actual), testCase.ExpectedErr)
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@@ -13,21 +15,14 @@ func TestAssignRole(t *testing.T) {
|
||||
|
||||
th.CheckCommand(t, "roles", "system_admin", th.BasicUser.Email)
|
||||
|
||||
if user, err := th.App.Srv.Store.User().GetByEmail(th.BasicUser.Email); err != nil {
|
||||
t.Fatal(err)
|
||||
} else {
|
||||
if user.Roles != "system_user system_admin" {
|
||||
t.Fatal("Got wrong roles:", user.Roles)
|
||||
}
|
||||
}
|
||||
user, err := th.App.Srv.Store.User().GetByEmail(th.BasicUser.Email)
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, "system_user system_admin", user.Roles)
|
||||
|
||||
th.CheckCommand(t, "roles", "member", th.BasicUser.Email)
|
||||
|
||||
if user, err := th.App.Srv.Store.User().GetByEmail(th.BasicUser.Email); err != nil {
|
||||
t.Fatal(err)
|
||||
} else {
|
||||
if user.Roles != "system_user" {
|
||||
t.Fatal("Got wrong roles:", user.Roles, user.Id)
|
||||
}
|
||||
}
|
||||
user, err = th.App.Srv.Store.User().GetByEmail(th.BasicUser.Email)
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, "system_user", user.Roles)
|
||||
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user