From db68e598a10d36013b7ff0994eca86e0464355e1 Mon Sep 17 00:00:00 2001 From: Harrison Healey Date: Tue, 25 Apr 2017 11:00:41 -0400 Subject: 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 --- api4/user_test.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'api4/user_test.go') 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() -- cgit v1.2.3-1-g7c22