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