debian-mirror-gitlab/spec/helpers/projects/project_members_helper_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

90 lines
2.7 KiB
Ruby
Raw Normal View History

2021-03-08 18:12:59 +05:30
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Projects::ProjectMembersHelper do
2021-03-11 19:13:27 +05:30
include MembersPresentation
2021-03-08 18:12:59 +05:30
let_it_be(:current_user) { create(:user) }
let_it_be(:project) { create(:project) }
before do
allow(helper).to receive(:current_user).and_return(current_user)
end
2021-03-11 19:13:27 +05:30
describe 'project members' do
2021-09-04 01:27:46 +05:30
let_it_be(:members) { create_list(:project_member, 2, project: project) }
let_it_be(:group_links) { create_list(:project_group_link, 1, project: project) }
let_it_be(:invited) { create_list(:project_member, 2, :invited, project: project) }
let_it_be(:access_requests) { create_list(:project_member, 2, :access_request, project: project) }
2021-03-11 19:13:27 +05:30
2021-09-04 01:27:46 +05:30
let(:members_collection) { members }
2021-03-11 19:13:27 +05:30
2021-09-04 01:27:46 +05:30
describe '#project_members_app_data_json' do
subject do
Gitlab::Json.parse(
helper.project_members_app_data_json(
project,
members: present_members(members_collection),
group_links: group_links,
invited: present_members(invited),
access_requests: present_members(access_requests)
)
)
end
2021-03-11 19:13:27 +05:30
before do
allow(helper).to receive(:project_project_member_path).with(project, ':id').and_return('/foo-bar/-/project_members/:id')
2021-10-27 15:23:28 +05:30
project.add_maintainer(current_user)
2021-03-11 19:13:27 +05:30
end
2021-06-08 01:23:25 +05:30
it 'returns expected json' do
expected = {
2021-03-11 19:13:27 +05:30
source_id: project.id,
2021-06-08 01:23:25 +05:30
can_manage_members: true
}.as_json
expect(subject).to include(expected)
end
2021-09-04 01:27:46 +05:30
it 'sets `members` property that matches json schema' do
expect(subject['user']['members'].to_json).to match_schema('members')
end
it 'sets `member_path` property' do
expect(subject['user']['member_path']).to eq('/foo-bar/-/project_members/:id')
2021-06-08 01:23:25 +05:30
end
context 'when pagination is not available' do
it 'sets `pagination` attribute to expected json' do
expected = {
current_page: nil,
per_page: nil,
total_items: 2,
param_name: nil,
params: {}
}.as_json
2021-09-04 01:27:46 +05:30
expect(subject['invite']['pagination']).to include(expected)
2021-06-08 01:23:25 +05:30
end
end
context 'when pagination is available' do
2021-09-04 01:27:46 +05:30
let(:members_collection) { Kaminari.paginate_array(members).page(1).per(1) }
2021-06-08 01:23:25 +05:30
it 'sets `pagination` attribute to expected json' do
expected = {
current_page: 1,
per_page: 1,
total_items: 2,
param_name: :page,
params: { search_groups: nil }
}.as_json
2021-09-04 01:27:46 +05:30
expect(subject['user']['pagination']).to match(expected)
2021-06-08 01:23:25 +05:30
end
2021-03-11 19:13:27 +05:30
end
end
end
2021-03-08 18:12:59 +05:30
end