From 742bab6429aeb1b581275da3c06af99fe293baab Mon Sep 17 00:00:00 2001 From: Saturnino Abril Date: Tue, 18 Apr 2017 00:06:33 +0900 Subject: APIv4 PUT /users/{user_id}/active (#6118) --- api4/user_test.go | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'api4/user_test.go') diff --git a/api4/user_test.go b/api4/user_test.go index 2ff665c8a..95271984c 100644 --- a/api4/user_test.go +++ b/api4/user_test.go @@ -850,6 +850,49 @@ func TestUpdateUserRoles(t *testing.T) { CheckBadRequestStatus(t, resp) } +func TestUpdateUserActive(t *testing.T) { + th := Setup().InitBasic().InitSystemAdmin() + Client := th.Client + SystemAdminClient := th.SystemAdminClient + user := th.BasicUser + + pass, resp := Client.UpdateUserActive(user.Id, false) + CheckNoError(t, resp) + + if !pass { + t.Fatal("should have returned true") + } + + pass, resp = Client.UpdateUserActive(user.Id, false) + CheckUnauthorizedStatus(t, resp) + + if pass { + t.Fatal("should have returned false") + } + + th.LoginBasic2() + + _, resp = Client.UpdateUserActive(user.Id, true) + CheckForbiddenStatus(t, resp) + + _, resp = Client.UpdateUserActive(GenerateTestId(), true) + CheckForbiddenStatus(t, resp) + + _, resp = Client.UpdateUserActive("junk", true) + CheckBadRequestStatus(t, resp) + + Client.Logout() + + _, resp = Client.UpdateUserActive(user.Id, true) + CheckUnauthorizedStatus(t, resp) + + _, resp = SystemAdminClient.UpdateUserActive(user.Id, true) + CheckNoError(t, resp) + + _, resp = SystemAdminClient.UpdateUserActive(user.Id, false) + CheckNoError(t, resp) +} + func TestGetUsers(t *testing.T) { th := Setup().InitBasic() defer TearDown() -- cgit v1.2.3-1-g7c22