summaryrefslogtreecommitdiff
path: root/spec/requests/api/graphql/users_spec.rb
diff options
context:
space:
mode:
authorRobert Speicher <rspeicher@gmail.com>2021-01-20 13:34:23 -0600
committerRobert Speicher <rspeicher@gmail.com>2021-01-20 13:34:23 -0600
commit6438df3a1e0fb944485cebf07976160184697d72 (patch)
tree00b09bfd170e77ae9391b1a2f5a93ef6839f2597 /spec/requests/api/graphql/users_spec.rb
parent42bcd54d971da7ef2854b896a7b34f4ef8601067 (diff)
downloadgitlab-ce-6438df3a1e0fb944485cebf07976160184697d72.tar.gz
Add latest changes from gitlab-org/gitlab@13-8-stable-eev13.8.0-rc42
Diffstat (limited to 'spec/requests/api/graphql/users_spec.rb')
-rw-r--r--spec/requests/api/graphql/users_spec.rb46
1 files changed, 46 insertions, 0 deletions
diff --git a/spec/requests/api/graphql/users_spec.rb b/spec/requests/api/graphql/users_spec.rb
index 72d86c10df1..22b68fbc9bb 100644
--- a/spec/requests/api/graphql/users_spec.rb
+++ b/spec/requests/api/graphql/users_spec.rb
@@ -54,6 +54,52 @@ RSpec.describe 'Users' do
)
end
end
+
+ context 'when admins is true' do
+ let_it_be(:admin) { create(:user, :admin) }
+ let_it_be(:another_admin) { create(:user, :admin) }
+
+ let(:query) { graphql_query_for(:users, { admins: true }, 'nodes { id }') }
+
+ context 'current user is not an admin' do
+ let(:post_query) { post_graphql(query, current_user: current_user) }
+
+ it_behaves_like 'a working users query'
+
+ it 'includes all non-admin users', :aggregate_failures do
+ post_graphql(query)
+
+ expect(graphql_data.dig('users', 'nodes')).to include(
+ { "id" => user1.to_global_id.to_s },
+ { "id" => user2.to_global_id.to_s },
+ { "id" => user3.to_global_id.to_s },
+ { "id" => current_user.to_global_id.to_s },
+ { "id" => admin.to_global_id.to_s },
+ { "id" => another_admin.to_global_id.to_s }
+ )
+ end
+ end
+
+ context 'when current user is an admin' do
+ it_behaves_like 'a working users query'
+
+ it 'includes only admins', :aggregate_failures do
+ post_graphql(query, current_user: admin)
+
+ expect(graphql_data.dig('users', 'nodes')).to include(
+ { "id" => another_admin.to_global_id.to_s },
+ { "id" => admin.to_global_id.to_s }
+ )
+
+ expect(graphql_data.dig('users', 'nodes')).not_to include(
+ { "id" => user1.to_global_id.to_s },
+ { "id" => user2.to_global_id.to_s },
+ { "id" => user3.to_global_id.to_s },
+ { "id" => current_user.to_global_id.to_s }
+ )
+ end
+ end
+ end
end
describe 'sorting and pagination' do