blob: e525d615b50311c6e714d2d15501ad1956afc344 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Admin::UsersController, :enable_admin_mode, feature_category: :user_management do
let_it_be(:admin) { create(:admin) }
let_it_be(:user) { create(:user) }
before do
sign_in(admin)
end
describe 'PATCH #update' do
let(:user) { create(:user) }
context "when admin changes user email" do
let(:new_email) { 'new-email@example.com' }
subject(:request) { patch admin_user_path(user), params: { user: { email: new_email } } }
it 'allows change user email', :aggregate_failures do
expect { request }
.to change { user.reload.email }.from(user.email).to(new_email)
expect(response).to redirect_to(admin_user_path(user))
expect(flash[:notice]).to eq('User was successfully updated.')
end
it 'does not email the user with confirmation_instructions' do
expect { request }
.not_to have_enqueued_mail(DeviseMailer, :confirmation_instructions)
end
end
end
describe 'PUT #block' do
context 'when request format is :json' do
subject(:request) { put block_admin_user_path(user, format: :json) }
context 'when user was blocked' do
it 'returns 200 and json data with notice' do
request
expect(response).to have_gitlab_http_status(:ok)
expect(json_response).to include('notice' => 'Successfully blocked')
end
end
context 'when user was not blocked' do
before do
allow_next_instance_of(::Users::BlockService) do |service|
allow(service).to receive(:execute).and_return({ status: :failed })
end
end
it 'returns 200 and json data with error' do
request
expect(response).to have_gitlab_http_status(:ok)
expect(json_response).to include('error' => 'Error occurred. User was not blocked')
end
end
end
end
describe 'PUT #unlock' do
before do
user.lock_access!
end
subject(:request) { put unlock_admin_user_path(user) }
it 'unlocks the user' do
expect { request }.to change { user.reload.access_locked? }.from(true).to(false)
end
end
end
|