debian-mirror-gitlab/spec/helpers/groups/group_members_helper_spec.rb

106 lines
3.3 KiB
Ruby
Raw Normal View History

2019-09-04 21:01:54 +05:30
# frozen_string_literal: true
require "spec_helper"
2020-07-28 23:09:34 +05:30
RSpec.describe Groups::GroupMembersHelper do
2020-11-24 15:15:51 +05:30
include MembersPresentation
2021-01-03 14:25:43 +05:30
let_it_be(:current_user) { create(:user) }
let_it_be(:group) { create(:group) }
before do
allow(helper).to receive(:can?).with(current_user, :owner_access, group).and_return(true)
allow(helper).to receive(:current_user).and_return(current_user)
end
2019-09-04 21:01:54 +05:30
2021-01-03 14:25:43 +05:30
describe '.group_member_select_options' do
2019-09-04 21:01:54 +05:30
before do
helper.instance_variable_set(:@group, group)
end
it 'returns an options hash' do
expect(helper.group_member_select_options).to include(multiple: true, scope: :all, email_user: true)
end
end
2020-11-24 15:15:51 +05:30
2021-03-11 19:13:27 +05:30
describe '#group_group_links_data_json' do
2020-11-24 15:15:51 +05:30
include_context 'group_group_link'
it 'matches json schema' do
2021-03-11 19:13:27 +05:30
json = helper.group_group_links_data_json(shared_group.shared_with_group_links)
2020-11-24 15:15:51 +05:30
2021-03-11 19:13:27 +05:30
expect(json).to match_schema('group_link/group_group_links')
2020-11-24 15:15:51 +05:30
end
end
describe '#members_data_json' do
2021-03-08 18:12:59 +05:30
shared_examples 'members.json' do
2020-11-24 15:15:51 +05:30
it 'matches json schema' do
json = helper.members_data_json(group, present_members([group_member]))
2021-03-08 18:12:59 +05:30
expect(json).to match_schema('members')
2020-11-24 15:15:51 +05:30
end
end
context 'for a group member' do
let(:group_member) { create(:group_member, group: group, created_by: current_user) }
2021-03-08 18:12:59 +05:30
it_behaves_like 'members.json'
2021-01-03 14:25:43 +05:30
context 'with user status set' do
let(:user) { create(:user) }
let!(:status) { create(:user_status, user: user) }
let(:group_member) { create(:group_member, group: group, user: user, created_by: current_user) }
2021-03-08 18:12:59 +05:30
it_behaves_like 'members.json'
2021-01-03 14:25:43 +05:30
end
2020-11-24 15:15:51 +05:30
end
context 'for an invited group member' do
let(:group_member) { create(:group_member, :invited, group: group, created_by: current_user) }
2021-03-08 18:12:59 +05:30
it_behaves_like 'members.json'
2020-11-24 15:15:51 +05:30
end
context 'for an access request' do
let(:group_member) { create(:group_member, :access_request, group: group, created_by: current_user) }
2021-03-08 18:12:59 +05:30
it_behaves_like 'members.json'
2020-11-24 15:15:51 +05:30
end
end
2021-01-03 14:25:43 +05:30
describe '#group_members_list_data_attributes' do
let(:group_member) { create(:group_member, group: group, created_by: current_user) }
before do
allow(helper).to receive(:group_group_member_path).with(group, ':id').and_return('/groups/foo-bar/-/group_members/:id')
2021-02-22 17:27:13 +05:30
allow(helper).to receive(:can?).with(current_user, :admin_group_member, group).and_return(true)
2021-01-03 14:25:43 +05:30
end
it 'returns expected hash' do
expect(helper.group_members_list_data_attributes(group, present_members([group_member]))).to include({
members: helper.members_data_json(group, present_members([group_member])),
member_path: '/groups/foo-bar/-/group_members/:id',
2021-03-11 19:13:27 +05:30
source_id: group.id,
2021-02-22 17:27:13 +05:30
can_manage_members: 'true'
2021-01-03 14:25:43 +05:30
})
end
end
2021-03-11 19:13:27 +05:30
describe '#group_group_links_list_data_attributes' do
2021-01-03 14:25:43 +05:30
include_context 'group_group_link'
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 hash' do
2021-03-11 19:13:27 +05:30
expect(helper.group_group_links_list_data_attributes(shared_group)).to include({
members: helper.group_group_links_data_json(shared_group.shared_with_group_links),
2021-01-03 14:25:43 +05:30
member_path: '/groups/foo-bar/-/group_links/:id',
2021-03-11 19:13:27 +05:30
source_id: shared_group.id
2021-01-03 14:25:43 +05:30
})
end
end
2019-09-04 21:01:54 +05:30
end