1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Resolvers::NestedGroupsResolver, feature_category: :groups_and_projects do
include GraphqlHelpers
describe '#resolve' do
let_it_be(:group) { create(:group, name: 'public-group') }
let_it_be(:private_group) { create(:group, :private, name: 'private-group') }
let_it_be(:subgroup1) { create(:group, parent: group, name: 'Subgroup') }
let_it_be(:subgroup2) { create(:group, parent: subgroup1, name: 'Test Subgroup 2') }
let_it_be(:private_subgroup1) { create(:group, :private, parent: private_group, name: 'Subgroup1') }
let_it_be(:private_subgroup2) { create(:group, :private, parent: private_subgroup1, name: 'Subgroup2') }
let_it_be(:user) { create(:user) }
before_all do
private_group.add_developer(user)
end
shared_examples 'access to all public descendant groups' do
it 'returns all public descendant groups of the parent group ordered by ASC name' do
is_expected.to eq([subgroup1, subgroup2])
end
end
shared_examples 'access to all public subgroups' do
it 'returns all public subgroups of the parent group' do
is_expected.to contain_exactly(subgroup1)
end
end
shared_examples 'returning empty results' do
it 'returns empty results' do
is_expected.to be_empty
end
end
context 'when parent group is public' do
subject { resolve(described_class, obj: group, args: params, ctx: { current_user: current_user }) }
context 'when `include_parent_descendants` is false' do
let(:params) { { include_parent_descendants: false } }
context 'when user is not logged in' do
let(:current_user) { nil }
it_behaves_like 'access to all public subgroups'
end
context 'when user is logged in' do
let(:current_user) { user }
it_behaves_like 'access to all public subgroups'
end
end
context 'when `include_parent_descendants` is true' do
let(:params) { { include_parent_descendants: true } }
context 'when user is not logged in' do
let(:current_user) { nil }
it_behaves_like 'access to all public descendant groups'
end
context 'when user is logged in' do
let(:current_user) { user }
it_behaves_like 'access to all public descendant groups'
context 'with owned argument set as true' do
before do
subgroup1.add_owner(current_user)
params[:owned] = true
end
it 'returns only descendant groups owned by the user' do
is_expected.to contain_exactly(subgroup1)
end
end
context 'with search argument' do
it 'returns only descendant groups with matching name or path' do
params[:search] = 'Test'
is_expected.to contain_exactly(subgroup2)
end
end
end
end
end
context 'when parent group is private' do
subject { resolve(described_class, obj: private_group, args: params, ctx: { current_user: current_user }) }
context 'when `include_parent_descendants` is true' do
let(:params) { { include_parent_descendants: true } }
context 'when user is not logged in' do
let(:current_user) { nil }
it_behaves_like 'returning empty results'
end
context 'when user is logged in' do
let(:current_user) { user }
it 'returns all private descendant groups' do
is_expected.to contain_exactly(private_subgroup1, private_subgroup2)
end
end
end
context 'when `include_parent_descendants` is false' do
let(:params) { { include_parent_descendants: false } }
context 'when user is not logged in' do
let(:current_user) { nil }
it_behaves_like 'returning empty results'
end
context 'when user is logged in' do
let(:current_user) { user }
it 'returns private subgroups' do
is_expected.to contain_exactly(private_subgroup1)
end
end
end
end
end
end
|