diff options
Diffstat (limited to 'spec/helpers/groups')
-rw-r--r-- | spec/helpers/groups/group_members_helper_spec.rb | 106 |
1 files changed, 48 insertions, 58 deletions
diff --git a/spec/helpers/groups/group_members_helper_spec.rb b/spec/helpers/groups/group_members_helper_spec.rb index c3f1509fbc8..b409bebaac3 100644 --- a/spec/helpers/groups/group_members_helper_spec.rb +++ b/spec/helpers/groups/group_members_helper_spec.rb @@ -23,58 +23,79 @@ RSpec.describe Groups::GroupMembersHelper do end end - describe '#group_members_list_data_json' do - let(:group_members) { create_list(:group_member, 2, group: group, created_by: current_user) } - - let(:pagination) { {} } - let(:collection) { group_members } - let(:presented_members) { present_members(collection) } + describe '#group_members_app_data_json' do + include_context 'group_group_link' - subject { Gitlab::Json.parse(helper.group_members_list_data_json(group, presented_members, pagination)) } + let(:members) { create_list(:group_member, 2, group: shared_group, created_by: current_user) } + let(:invited) { create_list(:group_member, 2, :invited, group: shared_group, created_by: current_user) } + let!(:access_requests) { create_list(:group_member, 2, :access_request, group: shared_group, created_by: current_user) } + + let(:members_collection) { members } + + subject do + Gitlab::Json.parse( + helper.group_members_app_data_json( + shared_group, + members: present_members(members_collection), + invited: present_members(invited), + access_requests: present_members(access_requests) + ) + ) + end - shared_examples 'members.json' do + shared_examples 'members.json' do |member_type| it 'returns `members` property that matches json schema' do - expect(subject['members'].to_json).to match_schema('members') + expect(subject[member_type]['members'].to_json).to match_schema('members') + end + + it 'sets `member_path` property' do + expect(subject[member_type]['member_path']).to eq('/groups/foo-bar/-/group_members/:id') end end before do - allow(helper).to receive(:group_group_member_path).with(group, ':id').and_return('/groups/foo-bar/-/group_members/:id') - allow(helper).to receive(:can?).with(current_user, :admin_group_member, group).and_return(true) + allow(helper).to receive(:group_group_member_path).with(shared_group, ':id').and_return('/groups/foo-bar/-/group_members/:id') + allow(helper).to receive(:group_group_link_path).with(shared_group, ':id').and_return('/groups/foo-bar/-/group_links/:id') + allow(helper).to receive(:can?).with(current_user, :admin_group_member, shared_group).and_return(true) end it 'returns expected json' do expected = { - member_path: '/groups/foo-bar/-/group_members/:id', - source_id: group.id, + source_id: shared_group.id, can_manage_members: true }.as_json expect(subject).to include(expected) end - context 'for a group member' do - it_behaves_like 'members.json' + context 'group members' do + it_behaves_like 'members.json', 'user' context 'with user status set' do let(:user) { create(:user) } let!(:status) { create(:user_status, user: user) } - let(:group_members) { [create(:group_member, group: group, user: user, created_by: current_user)] } + let(:members) { [create(:group_member, group: shared_group, user: user, created_by: current_user)] } - it_behaves_like 'members.json' + it_behaves_like 'members.json', 'user' end end - context 'for an invited group member' do - let(:group_members) { create_list(:group_member, 2, :invited, group: group, created_by: current_user) } + context 'invited group members' do + it_behaves_like 'members.json', 'invite' + end - it_behaves_like 'members.json' + context 'access requests' do + it_behaves_like 'members.json', 'access_request' end - context 'for an access request' do - let(:group_members) { create_list(:group_member, 2, :access_request, group: group, created_by: current_user) } + context 'group links' do + it 'sets `group.members` property that matches json schema' do + expect(subject['group']['members'].to_json).to match_schema('group_link/group_group_links') + end - it_behaves_like 'members.json' + it 'sets `member_path` property' do + expect(subject['group']['member_path']).to eq('/groups/foo-bar/-/group_links/:id') + end end context 'when pagination is not available' do @@ -87,13 +108,12 @@ RSpec.describe Groups::GroupMembersHelper do params: {} }.as_json - expect(subject['pagination']).to include(expected) + expect(subject['access_request']['pagination']).to include(expected) end end context 'when pagination is available' do - let(:collection) { Kaminari.paginate_array(group_members).page(1).per(1) } - let(:pagination) { { param_name: :page, params: { search_groups: nil } } } + let(:members_collection) { Kaminari.paginate_array(members).page(1).per(1) } it 'sets `pagination` attribute to expected json' do expected = { @@ -101,41 +121,11 @@ RSpec.describe Groups::GroupMembersHelper do per_page: 1, total_items: 2, param_name: :page, - params: { search_groups: nil } + params: { invited_members_page: nil, search_invited: nil } }.as_json - expect(subject['pagination']).to include(expected) + expect(subject['user']['pagination']).to include(expected) end end end - - describe '#group_group_links_list_data_json' do - include_context 'group_group_link' - - subject { Gitlab::Json.parse(helper.group_group_links_list_data_json(shared_group)) } - - before do - allow(helper).to receive(:group_group_link_path).with(shared_group, ':id').and_return('/groups/foo-bar/-/group_links/:id') - end - - it 'returns expected json' do - expected = { - pagination: { - current_page: nil, - per_page: nil, - total_items: 1, - param_name: nil, - params: {} - }, - member_path: '/groups/foo-bar/-/group_links/:id', - source_id: shared_group.id - }.as_json - - expect(subject).to include(expected) - end - - it 'returns `members` property that matches json schema' do - expect(subject['members'].to_json).to match_schema('group_link/group_group_links') - end - end end |