2020-06-23 00:09:42 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
RSpec.shared_examples 'a working membership object query' do |model_option|
|
|
|
|
let_it_be(:member_source) { member.source }
|
|
|
|
let_it_be(:member_source_type) { member_source.class.to_s.downcase }
|
|
|
|
|
|
|
|
it 'contains edge to expected project' do
|
|
|
|
expect(
|
|
|
|
graphql_data.dig('user', "#{member_source_type}Memberships", 'nodes', 0, member_source_type, 'id')
|
|
|
|
).to eq(member.send(member_source_type).to_global_id.to_s)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'contains correct access level' do
|
|
|
|
expect(
|
|
|
|
graphql_data.dig('user', "#{member_source_type}Memberships", 'nodes', 0, 'accessLevel', 'integerValue')
|
|
|
|
).to eq(30)
|
|
|
|
|
|
|
|
expect(
|
|
|
|
graphql_data.dig('user', "#{member_source_type}Memberships", 'nodes', 0, 'accessLevel', 'stringValue')
|
|
|
|
).to eq('DEVELOPER')
|
|
|
|
end
|
|
|
|
end
|
2020-11-24 15:15:51 +05:30
|
|
|
|
|
|
|
RSpec.shared_examples 'querying members with a group' do
|
|
|
|
let_it_be(:root_group) { create(:group, :private) }
|
|
|
|
let_it_be(:group_1) { create(:group, :private, parent: root_group, name: 'Main Group') }
|
|
|
|
let_it_be(:group_2) { create(:group, :private, parent: root_group) }
|
|
|
|
|
|
|
|
let_it_be(:user_1) { create(:user, name: 'test user') }
|
|
|
|
let_it_be(:user_2) { create(:user, name: 'test user 2') }
|
|
|
|
let_it_be(:user_3) { create(:user, name: 'another user 1') }
|
|
|
|
let_it_be(:user_4) { create(:user, name: 'another user 2') }
|
|
|
|
|
|
|
|
let_it_be(:root_group_member) { create(:group_member, user: user_4, group: root_group) }
|
|
|
|
let_it_be(:group_1_member) { create(:group_member, user: user_2, group: group_1) }
|
|
|
|
let_it_be(:group_2_member) { create(:group_member, user: user_3, group: group_2) }
|
|
|
|
|
|
|
|
let(:args) { {} }
|
2021-02-22 17:27:13 +05:30
|
|
|
let(:base_args) { { relations: described_class.arguments['relations'].default_value } }
|
2020-11-24 15:15:51 +05:30
|
|
|
|
|
|
|
subject do
|
2021-02-22 17:27:13 +05:30
|
|
|
resolve(described_class, obj: resource, args: base_args.merge(args), ctx: { current_user: user_4 })
|
2020-11-24 15:15:51 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
describe '#resolve' do
|
|
|
|
before do
|
|
|
|
group_1.add_maintainer(user_4)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'finds all resource members' do
|
|
|
|
expect(subject).to contain_exactly(resource_member, group_1_member, root_group_member)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with search' do
|
|
|
|
context 'when the search term matches a user' do
|
|
|
|
let(:args) { { search: 'test' } }
|
|
|
|
|
|
|
|
it 'searches users by user name' do
|
|
|
|
expect(subject).to contain_exactly(resource_member, group_1_member)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the search term does not match any user' do
|
|
|
|
let(:args) { { search: 'nothing' } }
|
|
|
|
|
|
|
|
it 'is empty' do
|
|
|
|
expect(subject).to be_empty
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user can not see resource members' do
|
|
|
|
let_it_be(:other_user) { create(:user) }
|
|
|
|
|
|
|
|
subject do
|
2021-02-22 17:27:13 +05:30
|
|
|
resolve(described_class, obj: resource, args: base_args.merge(args), ctx: { current_user: other_user })
|
2020-11-24 15:15:51 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'raises an error' do
|
|
|
|
expect { subject }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|