summaryrefslogtreecommitdiffstats
path: root/api4/user_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'api4/user_test.go')
-rw-r--r--api4/user_test.go121
1 files changed, 121 insertions, 0 deletions
diff --git a/api4/user_test.go b/api4/user_test.go
index 4ef1505e7..fd555fe42 100644
--- a/api4/user_test.go
+++ b/api4/user_test.go
@@ -267,6 +267,127 @@ func TestGetUserByEmail(t *testing.T) {
}
}
+func TestAutocompleteUsers(t *testing.T) {
+ th := Setup().InitBasic().InitSystemAdmin()
+ defer TearDown()
+ Client := th.Client
+ teamId := th.BasicTeam.Id
+ channelId := th.BasicChannel.Id
+ username := th.BasicUser.Username
+
+ rusers, resp := Client.AutocompleteUsersInChannel(teamId, channelId, username, "")
+ CheckNoError(t, resp)
+
+ if len(rusers.Users) != 1 {
+ t.Fatal("should have returned 1 user")
+ }
+
+ rusers, resp = Client.AutocompleteUsersInChannel(teamId, channelId, "amazonses", "")
+ CheckNoError(t, resp)
+ if len(rusers.Users) != 0 {
+ t.Fatal("should have returned 0 users")
+ }
+
+ rusers, resp = Client.AutocompleteUsersInChannel(teamId, channelId, "", "")
+ CheckNoError(t, resp)
+ if len(rusers.Users) < 2 {
+ t.Fatal("should have many users")
+ }
+
+ rusers, resp = Client.AutocompleteUsersInTeam(teamId, username, "")
+ CheckNoError(t, resp)
+
+ if len(rusers.Users) != 1 {
+ t.Fatal("should have returned 1 user")
+ }
+
+ rusers, resp = Client.AutocompleteUsers(username, "")
+ CheckNoError(t, resp)
+
+ if len(rusers.Users) != 1 {
+ t.Fatal("should have returned 1 users")
+ }
+
+ rusers, resp = Client.AutocompleteUsers("", "")
+ CheckNoError(t, resp)
+
+ if len(rusers.Users) < 2 {
+ t.Fatal("should have returned many users")
+ }
+
+ rusers, resp = Client.AutocompleteUsersInTeam(teamId, "amazonses", "")
+ CheckNoError(t, resp)
+ if len(rusers.Users) != 0 {
+ t.Fatal("should have returned 0 users")
+ }
+
+ rusers, resp = Client.AutocompleteUsersInTeam(teamId, "", "")
+ CheckNoError(t, resp)
+ if len(rusers.Users) < 2 {
+ t.Fatal("should have many users")
+ }
+
+ Client.Logout()
+ _, resp = Client.AutocompleteUsersInChannel(teamId, channelId, username, "")
+ CheckUnauthorizedStatus(t, resp)
+
+ _, resp = Client.AutocompleteUsersInTeam(teamId, username, "")
+ CheckUnauthorizedStatus(t, resp)
+
+ _, resp = Client.AutocompleteUsers(username, "")
+ CheckUnauthorizedStatus(t, resp)
+
+ user := th.CreateUser()
+ Client.Login(user.Email, user.Password)
+ _, resp = Client.AutocompleteUsersInChannel(teamId, channelId, username, "")
+ CheckForbiddenStatus(t, resp)
+
+ _, resp = Client.AutocompleteUsersInTeam(teamId, username, "")
+ CheckForbiddenStatus(t, resp)
+
+ _, resp = Client.AutocompleteUsers(username, "")
+ CheckNoError(t, resp)
+
+ _, resp = th.SystemAdminClient.AutocompleteUsersInChannel(teamId, channelId, username, "")
+ CheckNoError(t, resp)
+
+ _, resp = th.SystemAdminClient.AutocompleteUsersInTeam(teamId, username, "")
+ CheckNoError(t, resp)
+
+ _, resp = th.SystemAdminClient.AutocompleteUsers(username, "")
+ CheckNoError(t, resp)
+
+ // Check against privacy config settings
+ namePrivacy := utils.Cfg.PrivacySettings.ShowFullName
+ defer func() {
+ utils.Cfg.PrivacySettings.ShowFullName = namePrivacy
+ }()
+ utils.Cfg.PrivacySettings.ShowFullName = false
+
+ th.LoginBasic()
+
+ rusers, resp = Client.AutocompleteUsers(username, "")
+ CheckNoError(t, resp)
+
+ if rusers.Users[0].FirstName != "" || rusers.Users[0].LastName != "" {
+ t.Fatal("should not show first/last name")
+ }
+
+ rusers, resp = Client.AutocompleteUsersInChannel(teamId, channelId, username, "")
+ CheckNoError(t, resp)
+
+ if rusers.Users[0].FirstName != "" || rusers.Users[0].LastName != "" {
+ t.Fatal("should not show first/last name")
+ }
+
+ rusers, resp = Client.AutocompleteUsersInTeam(teamId, username, "")
+ CheckNoError(t, resp)
+
+ if rusers.Users[0].FirstName != "" || rusers.Users[0].LastName != "" {
+ t.Fatal("should not show first/last name")
+ }
+}
+
func TestGetProfileImage(t *testing.T) {
th := Setup().InitBasic().InitSystemAdmin()
defer TearDown()