github.com/wgh-/mattermost-server@v4.8.0-rc2+incompatible/cmd/platform/user_test.go (about) 1 // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. 2 // See License.txt for license information. 3 4 package main 5 6 import ( 7 "testing" 8 9 "github.com/mattermost/mattermost-server/api" 10 "github.com/mattermost/mattermost-server/model" 11 ) 12 13 func TestCreateUserWithTeam(t *testing.T) { 14 th := api.Setup().InitSystemAdmin() 15 defer th.TearDown() 16 17 id := model.NewId() 18 email := "success+" + id + "@simulator.amazonses.com" 19 username := "name" + id 20 21 checkCommand(t, "user", "create", "--email", email, "--password", "mypassword1", "--username", username) 22 23 checkCommand(t, "team", "add", th.SystemAdminTeam.Id, email) 24 25 profiles := th.SystemAdminClient.Must(th.SystemAdminClient.GetProfilesInTeam(th.SystemAdminTeam.Id, 0, 1000, "")).Data.(map[string]*model.User) 26 27 found := false 28 29 for _, user := range profiles { 30 if user.Email == email { 31 found = true 32 } 33 34 } 35 36 if !found { 37 t.Fatal("Failed to create User") 38 } 39 } 40 41 func TestCreateUserWithoutTeam(t *testing.T) { 42 th := api.Setup() 43 defer th.TearDown() 44 45 id := model.NewId() 46 email := "success+" + id + "@simulator.amazonses.com" 47 username := "name" + id 48 49 checkCommand(t, "user", "create", "--email", email, "--password", "mypassword1", "--username", username) 50 51 if result := <-th.App.Srv.Store.User().GetByEmail(email); result.Err != nil { 52 t.Fatal() 53 } else { 54 user := result.Data.(*model.User) 55 if user.Email != email { 56 t.Fatal() 57 } 58 } 59 } 60 61 func TestResetPassword(t *testing.T) { 62 th := api.Setup().InitBasic() 63 defer th.TearDown() 64 65 checkCommand(t, "user", "password", th.BasicUser.Email, "password2") 66 67 th.BasicClient.Logout() 68 th.BasicUser.Password = "password2" 69 th.LoginBasic() 70 } 71 72 func TestMakeUserActiveAndInactive(t *testing.T) { 73 th := api.Setup().InitBasic() 74 defer th.TearDown() 75 76 // first inactivate the user 77 checkCommand(t, "user", "deactivate", th.BasicUser.Email) 78 79 // activate the inactive user 80 checkCommand(t, "user", "activate", th.BasicUser.Email) 81 }