2019-05-17 12:43:03 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require "spec_helper"
|
|
|
|
|
2020-06-24 09:08:32 +00:00
|
|
|
RSpec.describe Groups::GroupMembersHelper do
|
2020-09-12 00:08:44 +00:00
|
|
|
include MembersPresentation
|
|
|
|
|
2020-09-21 15:09:44 +00:00
|
|
|
let_it_be(:current_user) { create(:user) }
|
2020-10-12 09:08:38 +00:00
|
|
|
let_it_be(:group) { create(:group) }
|
2020-09-21 15:09:44 +00:00
|
|
|
|
2020-10-12 09:08:38 +00:00
|
|
|
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-05-17 12:43:03 +00:00
|
|
|
|
2020-10-12 09:08:38 +00:00
|
|
|
describe '.group_member_select_options' do
|
2019-05-17 12:43:03 +00:00
|
|
|
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-09-12 00:08:44 +00:00
|
|
|
|
|
|
|
describe '#linked_groups_data_json' do
|
|
|
|
include_context 'group_group_link'
|
|
|
|
|
|
|
|
it 'matches json schema' do
|
|
|
|
json = helper.linked_groups_data_json(shared_group.shared_with_group_links)
|
|
|
|
|
|
|
|
expect(json).to match_schema('group_group_links')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#members_data_json' do
|
|
|
|
shared_examples 'group_members.json' do
|
|
|
|
it 'matches json schema' do
|
|
|
|
json = helper.members_data_json(group, present_members([group_member]))
|
|
|
|
|
|
|
|
expect(json).to match_schema('group_members')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for a group member' do
|
|
|
|
let(:group_member) { create(:group_member, group: group, created_by: current_user) }
|
|
|
|
|
|
|
|
it_behaves_like 'group_members.json'
|
2020-09-21 15:09:44 +00:00
|
|
|
|
|
|
|
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) }
|
|
|
|
|
|
|
|
it_behaves_like 'group_members.json'
|
|
|
|
end
|
2020-09-12 00:08:44 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'for an invited group member' do
|
|
|
|
let(:group_member) { create(:group_member, :invited, group: group, created_by: current_user) }
|
|
|
|
|
|
|
|
it_behaves_like 'group_members.json'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for an access request' do
|
|
|
|
let(:group_member) { create(:group_member, :access_request, group: group, created_by: current_user) }
|
|
|
|
|
|
|
|
it_behaves_like 'group_members.json'
|
|
|
|
end
|
|
|
|
end
|
2020-10-12 09:08:38 +00:00
|
|
|
|
|
|
|
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')
|
|
|
|
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',
|
|
|
|
group_id: group.id
|
|
|
|
})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#linked_groups_list_data_attributes' do
|
|
|
|
include_context 'group_group_link'
|
|
|
|
|
|
|
|
it 'returns expected hash' do
|
|
|
|
expect(helper.linked_groups_list_data_attributes(shared_group)).to include({
|
|
|
|
members: helper.linked_groups_data_json(shared_group.shared_with_group_links),
|
|
|
|
group_id: shared_group.id
|
|
|
|
})
|
|
|
|
end
|
|
|
|
end
|
2019-05-17 12:43:03 +00:00
|
|
|
end
|