Commit 04a35642 authored by Serena Fang's avatar Serena Fang Committed by Peter Leitzen

DRY api/users_spec activation specs

parent dd456683
......@@ -2291,23 +2291,31 @@ RSpec.describe API::Users, :do_not_mock_admin_mode do
end
describe 'POST /users/:id/activate' do
subject(:activate) { post api("/users/#{user_id}/activate", api_user) }
let(:user_id) { user.id }
context 'performed by a non-admin user' do
let(:api_user) { user }
it 'is not authorized to perform the action' do
post api("/users/#{user.id}/activate", user)
activate
expect(response).to have_gitlab_http_status(:forbidden)
end
end
context 'performed by an admin user' do
let(:api_user) { admin }
context 'for a deactivated user' do
before do
user.deactivate
post api("/users/#{user.id}/activate", admin)
end
it 'activates a deactivated user' do
activate
expect(response).to have_gitlab_http_status(:created)
expect(user.reload.state).to eq('active')
end
......@@ -2316,11 +2324,11 @@ RSpec.describe API::Users, :do_not_mock_admin_mode do
context 'for an active user' do
before do
user.activate
post api("/users/#{user.id}/activate", admin)
end
it 'returns 201' do
activate
expect(response).to have_gitlab_http_status(:created)
expect(user.reload.state).to eq('active')
end
......@@ -2329,11 +2337,11 @@ RSpec.describe API::Users, :do_not_mock_admin_mode do
context 'for a blocked user' do
before do
user.block
post api("/users/#{user.id}/activate", admin)
end
it 'returns 403' do
activate
expect(response).to have_gitlab_http_status(:forbidden)
expect(json_response['message']).to eq('403 Forbidden - A blocked user must be unblocked to be activated')
expect(user.reload.state).to eq('blocked')
......@@ -2343,11 +2351,11 @@ RSpec.describe API::Users, :do_not_mock_admin_mode do
context 'for a ldap blocked user' do
before do
user.ldap_block
post api("/users/#{user.id}/activate", admin)
end
it 'returns 403' do
activate
expect(response).to have_gitlab_http_status(:forbidden)
expect(json_response['message']).to eq('403 Forbidden - A blocked user must be unblocked to be activated')
expect(user.reload.state).to eq('ldap_blocked')
......@@ -2355,8 +2363,10 @@ RSpec.describe API::Users, :do_not_mock_admin_mode do
end
context 'for a user that does not exist' do
let(:user_id) { 0 }
before do
post api("/users/0/activate", admin)
activate
end
it_behaves_like '404'
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment