summaryrefslogtreecommitdiff
path: root/spec/requests
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-12-02 06:09:50 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-12-02 06:09:50 +0000
commitd5e4aa5266e94798f1c4a1a83a77fa0354056f0e (patch)
treeb83f32d31052fb1f5b402298b9a7c06ba4077d5f /spec/requests
parent408af4d5cf3a3893f8431d4d28821c766ab92bec (diff)
downloadgitlab-ce-d5e4aa5266e94798f1c4a1a83a77fa0354056f0e.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/requests')
-rw-r--r--spec/requests/api/graphql/group/group_members_spec.rb80
-rw-r--r--spec/requests/api/graphql/project/project_members_spec.rb121
2 files changed, 187 insertions, 14 deletions
diff --git a/spec/requests/api/graphql/group/group_members_spec.rb b/spec/requests/api/graphql/group/group_members_spec.rb
index 84b2fd63d46..3554e22cdf2 100644
--- a/spec/requests/api/graphql/group/group_members_spec.rb
+++ b/spec/requests/api/graphql/group/group_members_spec.rb
@@ -5,44 +5,95 @@ require 'spec_helper'
RSpec.describe 'getting group members information' do
include GraphqlHelpers
- let_it_be(:group) { create(:group, :public) }
+ let_it_be(:parent_group) { create(:group, :public) }
let_it_be(:user) { create(:user) }
let_it_be(:user_1) { create(:user, username: 'user') }
let_it_be(:user_2) { create(:user, username: 'test') }
let(:member_data) { graphql_data['group']['groupMembers']['edges'] }
- before do
- [user_1, user_2].each { |user| group.add_guest(user) }
+ before_all do
+ [user_1, user_2].each { |user| parent_group.add_guest(user) }
end
context 'when the request is correct' do
it_behaves_like 'a working graphql query' do
- before do
- fetch_members(user)
+ before_all do
+ fetch_members
end
end
it 'returns group members successfully' do
- fetch_members(user)
+ fetch_members
expect(graphql_errors).to be_nil
- expect_array_response(user_1.to_global_id.to_s, user_2.to_global_id.to_s)
+ expect_array_response(user_1, user_2)
end
it 'returns members that match the search query' do
- fetch_members(user, { search: 'test' })
+ fetch_members(args: { search: 'test' })
expect(graphql_errors).to be_nil
- expect_array_response(user_2.to_global_id.to_s)
+ expect_array_response(user_2)
end
end
- def fetch_members(user = nil, args = {})
- post_graphql(members_query(args), current_user: user)
+ context 'member relations' do
+ let_it_be(:child_group) { create(:group, :public, parent: parent_group) }
+ let_it_be(:grandchild_group) { create(:group, :public, parent: child_group) }
+ let_it_be(:child_user) { create(:user) }
+ let_it_be(:grandchild_user) { create(:user) }
+
+ before_all do
+ child_group.add_guest(child_user)
+ grandchild_group.add_guest(grandchild_user)
+ end
+
+ it 'returns direct members' do
+ fetch_members(group: child_group, args: { relations: [:DIRECT] })
+
+ expect(graphql_errors).to be_nil
+ expect_array_response(child_user)
+ end
+
+ it 'returns direct and inherited members' do
+ fetch_members(group: child_group, args: { relations: [:DIRECT, :INHERITED] })
+
+ expect(graphql_errors).to be_nil
+ expect_array_response(child_user, user_1, user_2)
+ end
+
+ it 'returns direct, inherited, and descendant members' do
+ fetch_members(group: child_group, args: { relations: [:DIRECT, :INHERITED, :DESCENDANTS] })
+
+ expect(graphql_errors).to be_nil
+ expect_array_response(child_user, user_1, user_2, grandchild_user)
+ end
+
+ it 'returns an error for an invalid member relation' do
+ fetch_members(group: child_group, args: { relations: [:OBLIQUE] })
+
+ expect(graphql_errors.first)
+ .to include('path' => %w[query group groupMembers relations],
+ 'message' => a_string_including('invalid value ([OBLIQUE])'))
+ end
+ end
+
+ context 'when unauthenticated' do
+ it 'returns nothing' do
+ fetch_members(current_user: nil)
+
+ expect(graphql_errors).to be_nil
+ expect(response).to have_gitlab_http_status(:success)
+ expect(member_data).to be_empty
+ end
+ end
+
+ def fetch_members(group: parent_group, current_user: user, args: {})
+ post_graphql(members_query(group.full_path, args), current_user: current_user)
end
- def members_query(args = {})
+ def members_query(group_path, args = {})
members_node = <<~NODE
edges {
node {
@@ -54,7 +105,7 @@ RSpec.describe 'getting group members information' do
NODE
graphql_query_for("group",
- { full_path: group.full_path },
+ { full_path: group_path },
[query_graphql_field("groupMembers", args, members_node)]
)
end
@@ -62,6 +113,7 @@ RSpec.describe 'getting group members information' do
def expect_array_response(*items)
expect(response).to have_gitlab_http_status(:success)
expect(member_data).to be_an Array
- expect(member_data.map { |node| node["node"]["user"]["id"] }).to match_array(items)
+ expect(member_data.map { |node| node["node"]["user"]["id"] })
+ .to match_array(items.map { |u| global_id_of(u) })
end
end
diff --git a/spec/requests/api/graphql/project/project_members_spec.rb b/spec/requests/api/graphql/project/project_members_spec.rb
new file mode 100644
index 00000000000..cb937432ef7
--- /dev/null
+++ b/spec/requests/api/graphql/project/project_members_spec.rb
@@ -0,0 +1,121 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe 'getting project members information' do
+ include GraphqlHelpers
+
+ let_it_be(:parent_group) { create(:group, :public) }
+ let_it_be(:parent_project) { create(:project, :public, group: parent_group) }
+ let_it_be(:user) { create(:user) }
+ let_it_be(:user_1) { create(:user, username: 'user') }
+ let_it_be(:user_2) { create(:user, username: 'test') }
+
+ let(:member_data) { graphql_data['project']['projectMembers']['edges'] }
+
+ before_all do
+ [user_1, user_2].each { |user| parent_group.add_guest(user) }
+ end
+
+ context 'when the request is correct' do
+ it_behaves_like 'a working graphql query' do
+ before_all do
+ fetch_members(project: parent_project)
+ end
+ end
+
+ it 'returns project members successfully' do
+ fetch_members(project: parent_project)
+
+ expect(graphql_errors).to be_nil
+ expect_array_response(user_1, user_2)
+ end
+
+ it 'returns members that match the search query' do
+ fetch_members(project: parent_project, args: { search: 'test' })
+
+ expect(graphql_errors).to be_nil
+ expect_array_response(user_2)
+ end
+ end
+
+ context 'member relations' do
+ let_it_be(:child_group) { create(:group, :public, parent: parent_group) }
+ let_it_be(:child_project) { create(:project, :public, group: child_group) }
+ let_it_be(:invited_group) { create(:group, :public) }
+ let_it_be(:child_user) { create(:user) }
+ let_it_be(:invited_user) { create(:user) }
+ let_it_be(:group_link) { create(:project_group_link, project: child_project, group: invited_group) }
+
+ before_all do
+ child_project.add_guest(child_user)
+ invited_group.add_guest(invited_user)
+ end
+
+ it 'returns direct members' do
+ fetch_members(project: child_project, args: { relations: [:DIRECT] })
+
+ expect(graphql_errors).to be_nil
+ expect_array_response(child_user)
+ end
+
+ it 'returns invited members plus inherited members' do
+ fetch_members(project: child_project, args: { relations: [:INVITED_GROUPS] })
+
+ expect(graphql_errors).to be_nil
+ expect_array_response(invited_user, user_1, user_2)
+ end
+
+ it 'returns direct, inherited, descendant, and invited members' do
+ fetch_members(project: child_project, args: { relations: [:DIRECT, :INHERITED, :DESCENDANTS, :INVITED_GROUPS] })
+
+ expect(graphql_errors).to be_nil
+ expect_array_response(child_user, user_1, user_2, invited_user)
+ end
+
+ it 'returns an error for an invalid member relation' do
+ fetch_members(project: child_project, args: { relations: [:OBLIQUE] })
+
+ expect(graphql_errors.first)
+ .to include('path' => %w[query project projectMembers relations],
+ 'message' => a_string_including('invalid value ([OBLIQUE])'))
+ end
+ end
+
+ context 'when unauthenticated' do
+ it 'returns members' do
+ fetch_members(current_user: nil, project: parent_project)
+
+ expect(graphql_errors).to be_nil
+ expect_array_response(user_1, user_2)
+ end
+ end
+
+ def fetch_members(project:, current_user: user, args: {})
+ post_graphql(members_query(project.full_path, args), current_user: current_user)
+ end
+
+ def members_query(group_path, args = {})
+ members_node = <<~NODE
+ edges {
+ node {
+ user {
+ id
+ }
+ }
+ }
+ NODE
+
+ graphql_query_for('project',
+ { full_path: group_path },
+ [query_graphql_field('projectMembers', args, members_node)]
+ )
+ end
+
+ def expect_array_response(*items)
+ expect(response).to have_gitlab_http_status(:success)
+ expect(member_data).to be_an Array
+ expect(member_data.map { |node| node['node']['user']['id'] })
+ .to match_array(items.map { |u| global_id_of(u) })
+ end
+end