diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-02-25 19:54:51 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-02-25 19:54:51 +0300 |
commit | cdc3d9991b0cca2d2243bdf452f61aae40d778cd (patch) | |
tree | f05b5b8c2e3fd10e210c35637292f3d28ac6f510 /spec/requests/api/graphql | |
parent | e92c90758eb4126acc84962d37bb273d6d87b27b (diff) |
Add latest changes from gitlab-org/security/gitlab@14-8-stable-ee
Diffstat (limited to 'spec/requests/api/graphql')
-rw-r--r-- | spec/requests/api/graphql/users_spec.rb | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/spec/requests/api/graphql/users_spec.rb b/spec/requests/api/graphql/users_spec.rb index 67cd35ee545..fe824834a2c 100644 --- a/spec/requests/api/graphql/users_spec.rb +++ b/spec/requests/api/graphql/users_spec.rb @@ -5,11 +5,13 @@ require 'spec_helper' RSpec.describe 'Users' do include GraphqlHelpers - let_it_be(:current_user) { create(:user, created_at: 1.day.ago) } + let_it_be(:user0) { create(:user, created_at: 1.day.ago) } let_it_be(:user1) { create(:user, created_at: 2.days.ago) } let_it_be(:user2) { create(:user, created_at: 3.days.ago) } let_it_be(:user3) { create(:user, created_at: 4.days.ago) } + let(:current_user) { user0 } + describe '.users' do shared_examples 'a working users query' do it_behaves_like 'a working graphql query' do @@ -19,7 +21,7 @@ RSpec.describe 'Users' do end it 'includes a list of users' do - post_graphql(query) + post_graphql(query, current_user: current_user) expect(graphql_data.dig('users', 'nodes')).not_to be_empty end @@ -47,7 +49,7 @@ RSpec.describe 'Users' do let_it_be(:query) { graphql_query_for(:users, { ids: user1.to_global_id.to_s, usernames: user1.username }, 'nodes { id }') } it 'displays an error' do - post_graphql(query) + post_graphql(query, current_user: current_user) expect(graphql_errors).to include( a_hash_including('message' => a_string_matching(%r{Provide either a list of usernames or ids})) @@ -66,14 +68,14 @@ RSpec.describe 'Users' do it_behaves_like 'a working users query' - it 'includes all non-admin users', :aggregate_failures do - post_graphql(query) + it 'includes all users', :aggregate_failures do + post_query expect(graphql_data.dig('users', 'nodes')).to include( + { "id" => user0.to_global_id.to_s }, { "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 } ) @@ -81,10 +83,12 @@ RSpec.describe 'Users' do end context 'when current user is an admin' do + let(:current_user) { admin } + it_behaves_like 'a working users query' it 'includes only admins', :aggregate_failures do - post_graphql(query, current_user: admin) + post_graphql(query, current_user: current_user) expect(graphql_data.dig('users', 'nodes')).to include( { "id" => another_admin.to_global_id.to_s }, @@ -92,10 +96,10 @@ RSpec.describe 'Users' do ) expect(graphql_data.dig('users', 'nodes')).not_to include( + { "id" => user0.to_global_id.to_s }, { "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" => user3.to_global_id.to_s } ) end end @@ -110,7 +114,7 @@ RSpec.describe 'Users' do end context 'when sorting by created_at' do - let_it_be(:ascending_users) { [user3, user2, user1, current_user].map { |u| global_id_of(u) } } + let_it_be(:ascending_users) { [user3, user2, user1, user0].map { |u| global_id_of(u) } } context 'when ascending' do it_behaves_like 'sorted paginated query' do |