2020-11-24 15:15:51 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
RSpec.describe 'getting group members information' do
|
|
|
|
include GraphqlHelpers
|
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
let_it_be(:parent_group) { create(:group, :public) }
|
2020-11-24 15:15:51 +05:30
|
|
|
let_it_be(:user) { create(:user) }
|
|
|
|
let_it_be(:user_1) { create(:user, username: 'user') }
|
|
|
|
let_it_be(:user_2) { create(:user, username: 'test') }
|
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
before_all do
|
|
|
|
[user_1, user_2].each { |user| parent_group.add_guest(user) }
|
2020-11-24 15:15:51 +05:30
|
|
|
end
|
|
|
|
|
2021-09-04 01:27:46 +05:30
|
|
|
context 'when a member is invited only via email' do
|
|
|
|
before do
|
|
|
|
create(:group_member, :invited, source: parent_group)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns null in the user field' do
|
|
|
|
fetch_members(group: parent_group, args: { relations: [:DIRECT] })
|
|
|
|
|
|
|
|
expect(graphql_errors).to be_nil
|
|
|
|
expect(graphql_data_at(:group, :group_members, :edges, :node)).to contain_exactly(
|
|
|
|
{ 'user' => { 'id' => global_id_of(user_1) } },
|
|
|
|
{ 'user' => { 'id' => global_id_of(user_2) } },
|
|
|
|
'user' => nil
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
context 'when the request is correct' do
|
|
|
|
it_behaves_like 'a working graphql query' do
|
2021-03-08 18:12:59 +05:30
|
|
|
before do
|
2021-02-22 17:27:13 +05:30
|
|
|
fetch_members
|
2020-11-24 15:15:51 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns group members successfully' do
|
2021-02-22 17:27:13 +05:30
|
|
|
fetch_members
|
2020-11-24 15:15:51 +05:30
|
|
|
|
|
|
|
expect(graphql_errors).to be_nil
|
2021-02-22 17:27:13 +05:30
|
|
|
expect_array_response(user_1, user_2)
|
2020-11-24 15:15:51 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns members that match the search query' do
|
2021-02-22 17:27:13 +05:30
|
|
|
fetch_members(args: { search: 'test' })
|
2020-11-24 15:15:51 +05:30
|
|
|
|
|
|
|
expect(graphql_errors).to be_nil
|
2021-02-22 17:27:13 +05:30
|
|
|
expect_array_response(user_2)
|
2020-11-24 15:15:51 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
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
|
2021-03-08 18:12:59 +05:30
|
|
|
it 'returns visible members' do
|
2021-02-22 17:27:13 +05:30
|
|
|
fetch_members(current_user: nil)
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
expect_array_response(user_1, user_2)
|
2021-02-22 17:27:13 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def fetch_members(group: parent_group, current_user: user, args: {})
|
|
|
|
post_graphql(members_query(group.full_path, args), current_user: current_user)
|
2020-11-24 15:15:51 +05:30
|
|
|
end
|
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
def members_query(group_path, args = {})
|
2020-11-24 15:15:51 +05:30
|
|
|
members_node = <<~NODE
|
|
|
|
edges {
|
|
|
|
node {
|
|
|
|
user {
|
|
|
|
id
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
NODE
|
|
|
|
|
|
|
|
graphql_query_for("group",
|
2021-02-22 17:27:13 +05:30
|
|
|
{ full_path: group_path },
|
2020-11-24 15:15:51 +05:30
|
|
|
[query_graphql_field("groupMembers", args, members_node)]
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
def expect_array_response(*items)
|
|
|
|
expect(response).to have_gitlab_http_status(:success)
|
2021-03-08 18:12:59 +05:30
|
|
|
member_gids = graphql_data_at(:group, :group_members, :edges, :node, :user, :id)
|
|
|
|
|
|
|
|
expect(member_gids).to match_array(items.map { |u| global_id_of(u) })
|
2020-11-24 15:15:51 +05:30
|
|
|
end
|
|
|
|
end
|