summaryrefslogtreecommitdiffstats
path: root/api4/user_test.go
diff options
context:
space:
mode:
authorCarlos Tadeu Panato Junior <ctadeu@gmail.com>2018-07-11 12:58:16 +0200
committerGitHub <noreply@github.com>2018-07-11 12:58:16 +0200
commit7ed712f938588491da35b1d04b7f44700975c70b (patch)
tree45586bdbefda64408c0cc1c3e34e7fd8d1b2004a /api4/user_test.go
parent7c08ff99864721956d1496b8114fa54dd33569f0 (diff)
downloadchat-7ed712f938588491da35b1d04b7f44700975c70b.tar.gz
chat-7ed712f938588491da35b1d04b7f44700975c70b.tar.bz2
chat-7ed712f938588491da35b1d04b7f44700975c70b.zip
Restore config after finisht the test case (#9085)
Diffstat (limited to 'api4/user_test.go')
-rw-r--r--api4/user_test.go64
1 files changed, 61 insertions, 3 deletions
diff --git a/api4/user_test.go b/api4/user_test.go
index ad77c8c4c..4cbaf449a 100644
--- a/api4/user_test.go
+++ b/api4/user_test.go
@@ -22,6 +22,13 @@ func TestCreateUser(t *testing.T) {
Client := th.Client
AdminClient := th.SystemAdminClient
+ enableOpenServer := th.App.Config().TeamSettings.EnableOpenServer
+ enableUserCreation := th.App.Config().TeamSettings.EnableUserCreation
+ defer func() {
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.TeamSettings.EnableOpenServer = enableOpenServer })
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.TeamSettings.EnableUserCreation = enableUserCreation })
+ }()
+
user := model.User{Email: th.GenerateTestEmail(), Nickname: "Corey Hulen", Password: "hello1", Username: GenerateTestUsername(), Roles: model.SYSTEM_ADMIN_ROLE_ID + " " + model.SYSTEM_USER_ROLE_ID}
ruser, resp := Client.CreateUser(&user)
@@ -161,6 +168,12 @@ func TestCreateUserWithToken(t *testing.T) {
})
t.Run("EnableUserCreationDisable", func(t *testing.T) {
+
+ enableUserCreation := th.App.Config().TeamSettings.EnableUserCreation
+ defer func() {
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.TeamSettings.EnableUserCreation = enableUserCreation })
+ }()
+
user := model.User{Email: th.GenerateTestEmail(), Nickname: "Corey Hulen", Password: "hello1", Username: GenerateTestUsername(), Roles: model.SYSTEM_ADMIN_ROLE_ID + " " + model.SYSTEM_USER_ROLE_ID}
token := model.NewToken(
@@ -176,7 +189,6 @@ func TestCreateUserWithToken(t *testing.T) {
CheckNotImplementedStatus(t, resp)
CheckErrorMessage(t, resp, "api.user.create_user.signup_email_disabled.app_error")
- th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.EnableUserCreation = true })
})
t.Run("EnableOpenServerDisable", func(t *testing.T) {
@@ -188,6 +200,11 @@ func TestCreateUserWithToken(t *testing.T) {
)
<-th.App.Srv.Store.Token().Save(token)
+ enableOpenServer := th.App.Config().TeamSettings.EnableOpenServer
+ defer func() {
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.TeamSettings.EnableOpenServer = enableOpenServer })
+ }()
+
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.EnableOpenServer = false })
ruser, resp := Client.CreateUserWithToken(&user, token.Token)
@@ -270,6 +287,11 @@ func TestCreateUserWithInviteId(t *testing.T) {
t.Run("EnableUserCreationDisable", func(t *testing.T) {
user := model.User{Email: th.GenerateTestEmail(), Nickname: "Corey Hulen", Password: "hello1", Username: GenerateTestUsername(), Roles: model.SYSTEM_ADMIN_ROLE_ID + " " + model.SYSTEM_USER_ROLE_ID}
+ enableUserCreation := th.App.Config().TeamSettings.EnableUserCreation
+ defer func() {
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.TeamSettings.EnableUserCreation = enableUserCreation })
+ }()
+
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.EnableUserCreation = false })
inviteId := th.BasicTeam.InviteId
@@ -277,13 +299,16 @@ func TestCreateUserWithInviteId(t *testing.T) {
_, resp := Client.CreateUserWithInviteId(&user, inviteId)
CheckNotImplementedStatus(t, resp)
CheckErrorMessage(t, resp, "api.user.create_user.signup_email_disabled.app_error")
-
- th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.EnableUserCreation = true })
})
t.Run("EnableOpenServerDisable", func(t *testing.T) {
user := model.User{Email: th.GenerateTestEmail(), Nickname: "Corey Hulen", Password: "hello1", Username: GenerateTestUsername(), Roles: model.SYSTEM_ADMIN_ROLE_ID + " " + model.SYSTEM_USER_ROLE_ID}
+ enableOpenServer := th.App.Config().TeamSettings.EnableOpenServer
+ defer func() {
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.TeamSettings.EnableOpenServer = enableOpenServer })
+ }()
+
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.EnableOpenServer = false })
inviteId := th.BasicTeam.InviteId
@@ -332,6 +357,13 @@ func TestGetUser(t *testing.T) {
th.App.UpdateUser(user, false)
+ showEmailAddress := th.App.Config().PrivacySettings.ShowEmailAddress
+ showFullName := th.App.Config().PrivacySettings.ShowFullName
+ defer func() {
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.PrivacySettings.ShowEmailAddress = showEmailAddress })
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.PrivacySettings.ShowFullName = showFullName })
+ }()
+
ruser, resp := Client.GetUser(user.Id, "")
CheckNoError(t, resp)
CheckUserSanitization(t, ruser)
@@ -393,6 +425,13 @@ func TestGetUserByUsername(t *testing.T) {
user := th.BasicUser
+ showEmailAddress := th.App.Config().PrivacySettings.ShowEmailAddress
+ showFullName := th.App.Config().PrivacySettings.ShowFullName
+ defer func() {
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.PrivacySettings.ShowEmailAddress = showEmailAddress })
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.PrivacySettings.ShowFullName = showFullName })
+ }()
+
ruser, resp := Client.GetUserByUsername(user.Username, "")
CheckNoError(t, resp)
CheckUserSanitization(t, ruser)
@@ -452,6 +491,13 @@ func TestGetUserByEmail(t *testing.T) {
defer th.TearDown()
Client := th.Client
+ showEmailAddress := th.App.Config().PrivacySettings.ShowEmailAddress
+ showFullName := th.App.Config().PrivacySettings.ShowFullName
+ defer func() {
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.PrivacySettings.ShowEmailAddress = showEmailAddress })
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.PrivacySettings.ShowFullName = showFullName })
+ }()
+
user := th.CreateUser()
ruser, resp := Client.GetUserByEmail(user.Email, "")
@@ -510,6 +556,13 @@ func TestSearchUsers(t *testing.T) {
defer th.TearDown()
Client := th.Client
+ showEmailAddress := th.App.Config().PrivacySettings.ShowEmailAddress
+ showFullName := th.App.Config().PrivacySettings.ShowFullName
+ defer func() {
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.PrivacySettings.ShowEmailAddress = showEmailAddress })
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.PrivacySettings.ShowFullName = showFullName })
+ }()
+
search := &model.UserSearch{Term: th.BasicUser.Username}
users, resp := Client.SearchUsers(search)
@@ -696,6 +749,11 @@ func TestAutocompleteUsers(t *testing.T) {
channelId := th.BasicChannel.Id
username := th.BasicUser.Username
+ showFullName := th.App.Config().PrivacySettings.ShowFullName
+ defer func() {
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.PrivacySettings.ShowFullName = showFullName })
+ }()
+
rusers, resp := Client.AutocompleteUsersInChannel(teamId, channelId, username, "")
CheckNoError(t, resp)