diff options
author | Harrison Healey <harrisonmhealey@gmail.com> | 2017-04-25 11:00:41 -0400 |
---|---|---|
committer | Corey Hulen <corey@hulen.com> | 2017-04-25 08:00:41 -0700 |
commit | db68e598a10d36013b7ff0994eca86e0464355e1 (patch) | |
tree | ec0f5e42c42d43afd4476f7e6b5ba9d3484577cc /api4/user_test.go | |
parent | cb668b92832193df7549c5a16543dcdfed44be56 (diff) | |
download | chat-db68e598a10d36013b7ff0994eca86e0464355e1.tar.gz chat-db68e598a10d36013b7ff0994eca86e0464355e1.tar.bz2 chat-db68e598a10d36013b7ff0994eca86e0464355e1.zip |
PLT-4457 Added API to get multiple users by their usernames (#6218)
* Allow getting profiles by username without a team
* Changed UserStore.GetProfilesByUsernames to return an array
* PLT-4457 Added API to get multiple users by their usernames
* Changed users/names route to users/usernames
Diffstat (limited to 'api4/user_test.go')
-rw-r--r-- | api4/user_test.go | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/api4/user_test.go b/api4/user_test.go index 9a360c7e4..20def9a17 100644 --- a/api4/user_test.go +++ b/api4/user_test.go @@ -666,6 +666,38 @@ func TestGetUsersByIds(t *testing.T) { CheckUnauthorizedStatus(t, resp) } +func TestGetUsersByUsernames(t *testing.T) { + th := Setup().InitBasic() + Client := th.Client + + users, resp := Client.GetUsersByUsernames([]string{th.BasicUser.Username}) + CheckNoError(t, resp) + + if users[0].Id != th.BasicUser.Id { + t.Fatal("returned wrong user") + } + CheckUserSanitization(t, users[0]) + + _, resp = Client.GetUsersByIds([]string{}) + CheckBadRequestStatus(t, resp) + + users, resp = Client.GetUsersByUsernames([]string{"junk"}) + CheckNoError(t, resp) + if len(users) > 0 { + t.Fatal("no users should be returned") + } + + users, resp = Client.GetUsersByUsernames([]string{"junk", th.BasicUser.Username}) + CheckNoError(t, resp) + if len(users) != 1 { + t.Fatal("1 user should be returned") + } + + Client.Logout() + _, resp = Client.GetUsersByUsernames([]string{th.BasicUser.Username}) + CheckUnauthorizedStatus(t, resp) +} + func TestUpdateUser(t *testing.T) { th := Setup().InitBasic().InitSystemAdmin() defer TearDown() |