2020-09-12 00:08:44 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2021-01-22 12:08:52 +00:00
|
|
|
RSpec.describe GroupLink::ProjectGroupLinkEntity do
|
2020-09-21 15:09:44 +00:00
|
|
|
let_it_be(:current_user) { create(:user) }
|
2021-01-22 12:08:52 +00:00
|
|
|
let_it_be(:project_group_link) { create(:project_group_link) }
|
2021-04-14 15:09:04 +00:00
|
|
|
|
2022-04-12 09:08:22 +00:00
|
|
|
let(:entity) { described_class.new(project_group_link, { current_user: current_user, source: project_group_link.project }) }
|
2020-09-21 15:09:44 +00:00
|
|
|
|
|
|
|
before do
|
|
|
|
allow(entity).to receive(:current_user).and_return(current_user)
|
|
|
|
end
|
2020-09-12 00:08:44 +00:00
|
|
|
|
|
|
|
it 'matches json schema' do
|
2021-01-22 12:08:52 +00:00
|
|
|
expect(entity.to_json).to match_schema('group_link/project_group_link')
|
2020-09-21 15:09:44 +00:00
|
|
|
end
|
|
|
|
|
2021-01-22 12:08:52 +00:00
|
|
|
context 'when current user has `admin_project_member` permissions' do
|
2020-09-21 15:09:44 +00:00
|
|
|
before do
|
2021-01-22 12:08:52 +00:00
|
|
|
allow(entity).to receive(:can?).with(current_user, :admin_project_member, project_group_link.project).and_return(true)
|
2020-09-21 15:09:44 +00:00
|
|
|
end
|
|
|
|
|
2021-01-22 12:08:52 +00:00
|
|
|
it 'exposes `can_update` and `can_remove` as `true`' do
|
2020-09-21 15:09:44 +00:00
|
|
|
json = entity.as_json
|
|
|
|
|
|
|
|
expect(json[:can_update]).to be true
|
|
|
|
expect(json[:can_remove]).to be true
|
|
|
|
end
|
2020-09-12 00:08:44 +00:00
|
|
|
end
|
|
|
|
end
|