Commit e185d359 authored by Jarka Košanová's avatar Jarka Košanová

Merge branch 'use-named-subject-with-unblock-specs' into 'master'

Use named subject with unblock user specs

See merge request gitlab-org/gitlab!69418
parents 05d6596e a2f89be6
......@@ -3031,52 +3031,83 @@ RSpec.describe API::Users do
end
end
describe 'POST /users/:id/unblock' do
let(:blocked_user) { create(:user, state: 'blocked') }
let(:deactivated_user) { create(:user, state: 'deactivated') }
describe 'POST /users/:id/unblock', :aggregate_failures do
context 'when admin' do
subject(:unblock_user) { post api("/users/#{user_id}/unblock", admin) }
context 'with an existing user' do
let(:user_id) { user.id }
it 'unblocks existing user' do
post api("/users/#{user.id}/unblock", admin)
unblock_user
expect(response).to have_gitlab_http_status(:created)
expect(user.reload.state).to eq('active')
end
end
context 'with a blocked user' do
let(:blocked_user) { create(:user, state: 'blocked') }
let(:user_id) { blocked_user.id }
it 'unblocks a blocked user' do
post api("/users/#{blocked_user.id}/unblock", admin)
unblock_user
expect(response).to have_gitlab_http_status(:created)
expect(blocked_user.reload.state).to eq('active')
end
end
context 'with a ldap blocked user' do
let(:user_id) { ldap_blocked_user.id }
it 'does not unblock ldap blocked users' do
post api("/users/#{ldap_blocked_user.id}/unblock", admin)
unblock_user
expect(response).to have_gitlab_http_status(:forbidden)
expect(ldap_blocked_user.reload.state).to eq('ldap_blocked')
end
end
context 'with a deactivated user' do
let(:user_id) { deactivated_user.id }
it 'does not unblock deactivated users' do
post api("/users/#{deactivated_user.id}/unblock", admin)
unblock_user
expect(response).to have_gitlab_http_status(:forbidden)
expect(deactivated_user.reload.state).to eq('deactivated')
end
it 'is not available for non admin users' do
post api("/users/#{user.id}/unblock", user)
expect(response).to have_gitlab_http_status(:forbidden)
expect(user.reload.state).to eq('active')
end
context 'with a non existent user' do
let(:user_id) { non_existing_record_id }
it 'returns a 404 error if user id not found' do
post api('/users/0/block', admin)
unblock_user
expect(response).to have_gitlab_http_status(:not_found)
expect(json_response['message']).to eq('404 User Not Found')
end
end
it "returns a 404 for invalid ID" do
post api("/users/ASDF/block", admin)
context 'with an invalid user id' do
let(:user_id) { 'ASDF' }
it 'returns a 404' do
unblock_user
expect(response).to have_gitlab_http_status(:not_found)
end
end
end
it 'is not available for non admin users' do
post api("/users/#{user.id}/unblock", user)
expect(response).to have_gitlab_http_status(:forbidden)
expect(user.reload.state).to eq('active')
end
end
describe 'POST /users/:id/ban', :aggregate_failures do
context 'when admin' do
......
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