diff options
Diffstat (limited to 'api/user_test.go')
-rw-r--r-- | api/user_test.go | 137 |
1 files changed, 137 insertions, 0 deletions
diff --git a/api/user_test.go b/api/user_test.go index 02ea71c83..13ae45f6e 100644 --- a/api/user_test.go +++ b/api/user_test.go @@ -2240,6 +2240,112 @@ func TestSearchUsers(t *testing.T) { } } + emailPrivacy := utils.Cfg.PrivacySettings.ShowEmailAddress + namePrivacy := utils.Cfg.PrivacySettings.ShowFullName + defer func() { + utils.Cfg.PrivacySettings.ShowEmailAddress = emailPrivacy + utils.Cfg.PrivacySettings.ShowFullName = namePrivacy + }() + utils.Cfg.PrivacySettings.ShowEmailAddress = false + utils.Cfg.PrivacySettings.ShowFullName = false + + privacyEmailPrefix := strings.ToLower(model.NewId()) + privacyUser := &model.User{Email: privacyEmailPrefix + "success+test@simulator.amazonses.com", Nickname: "Corey Hulen", Password: "passwd1", FirstName: model.NewId(), LastName: "Jimmers"} + privacyUser = Client.Must(Client.CreateUser(privacyUser, "")).Data.(*model.User) + LinkUserToTeam(privacyUser, th.BasicTeam) + + if result, err := Client.SearchUsers(model.UserSearch{Term: privacyUser.FirstName}); err != nil { + t.Fatal(err) + } else { + users := result.Data.([]*model.User) + + found := false + for _, user := range users { + if user.Id == privacyUser.Id { + found = true + } + } + + if found { + t.Fatal("should not have found profile") + } + } + + utils.Cfg.PrivacySettings.ShowEmailAddress = true + + if result, err := Client.SearchUsers(model.UserSearch{Term: privacyUser.FirstName}); err != nil { + t.Fatal(err) + } else { + users := result.Data.([]*model.User) + + found := false + for _, user := range users { + if user.Id == privacyUser.Id { + found = true + } + } + + if found { + t.Fatal("should not have found profile") + } + } + + utils.Cfg.PrivacySettings.ShowEmailAddress = false + utils.Cfg.PrivacySettings.ShowFullName = true + + if result, err := Client.SearchUsers(model.UserSearch{Term: privacyUser.FirstName}); err != nil { + t.Fatal(err) + } else { + users := result.Data.([]*model.User) + + found := false + for _, user := range users { + if user.Id == privacyUser.Id { + found = true + } + } + + if !found { + t.Fatal("should have found profile") + } + } + + if result, err := Client.SearchUsers(model.UserSearch{Term: privacyEmailPrefix}); err != nil { + t.Fatal(err) + } else { + users := result.Data.([]*model.User) + + found := false + for _, user := range users { + if user.Id == privacyUser.Id { + found = true + } + } + + if found { + t.Fatal("should not have found profile") + } + } + + utils.Cfg.PrivacySettings.ShowEmailAddress = true + + if result, err := Client.SearchUsers(model.UserSearch{Term: privacyEmailPrefix}); err != nil { + t.Fatal(err) + } else { + users := result.Data.([]*model.User) + + found := false + for _, user := range users { + if user.Id == privacyUser.Id { + found = true + } + } + + if !found { + t.Fatal("should have found profile") + } + } + th.LoginBasic2() if result, err := Client.SearchUsers(model.UserSearch{Term: th.BasicUser.Username}); err != nil { @@ -2364,6 +2470,37 @@ func TestAutocompleteUsers(t *testing.T) { } } + namePrivacy := utils.Cfg.PrivacySettings.ShowFullName + defer func() { + utils.Cfg.PrivacySettings.ShowFullName = namePrivacy + }() + utils.Cfg.PrivacySettings.ShowFullName = false + + privacyUser := &model.User{Email: strings.ToLower(model.NewId()) + "success+test@simulator.amazonses.com", Nickname: "Corey Hulen", Password: "passwd1", FirstName: model.NewId(), LastName: "Jimmers"} + privacyUser = Client.Must(Client.CreateUser(privacyUser, "")).Data.(*model.User) + LinkUserToTeam(privacyUser, th.BasicTeam) + + if result, err := Client.AutocompleteUsersInChannel(privacyUser.FirstName, th.BasicChannel.Id); err != nil { + t.Fatal(err) + } else { + autocomplete := result.Data.(*model.UserAutocompleteInChannel) + if len(autocomplete.InChannel) != 0 { + t.Fatal("should have returned no users") + } + if len(autocomplete.OutOfChannel) != 0 { + t.Fatal("should have returned no users") + } + } + + if result, err := Client.AutocompleteUsersInTeam(privacyUser.FirstName); err != nil { + t.Fatal(err) + } else { + autocomplete := result.Data.(*model.UserAutocompleteInTeam) + if len(autocomplete.InTeam) != 0 { + t.Fatal("should have returned no users") + } + } + if _, err := Client.AutocompleteUsersInChannel("", "junk"); err == nil { t.Fatal("should have errored - bad channel id") } |