debian-mirror-gitlab/spec/services/groups/group_links/update_service_spec.rb

61 lines
1.7 KiB
Ruby
Raw Normal View History

2020-03-13 15:44:24 +05:30
# frozen_string_literal: true
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe Groups::GroupLinks::UpdateService, '#execute' do
2020-03-13 15:44:24 +05:30
let(:user) { create(:user) }
let_it_be(:group) { create(:group, :private) }
let_it_be(:shared_group) { create(:group, :private) }
let_it_be(:project) { create(:project, group: shared_group) }
2021-04-29 21:17:54 +05:30
2021-04-17 20:07:23 +05:30
let(:group_member_user) { create(:user) }
2020-03-13 15:44:24 +05:30
let!(:link) { create(:group_group_link, shared_group: shared_group, shared_with_group: group) }
let(:expiry_date) { 1.month.from_now.to_date }
let(:group_link_params) do
{ group_access: Gitlab::Access::GUEST,
expires_at: expiry_date }
end
subject { described_class.new(link).execute(group_link_params) }
before do
2021-04-17 20:07:23 +05:30
group.add_developer(group_member_user)
2020-03-13 15:44:24 +05:30
end
it 'updates existing link' do
expect(link.group_access).to eq(Gitlab::Access::DEVELOPER)
expect(link.expires_at).to be_nil
subject
link.reload
expect(link.group_access).to eq(Gitlab::Access::GUEST)
expect(link.expires_at).to eq(expiry_date)
end
2021-09-30 23:02:18 +05:30
it 'updates project permissions', :sidekiq_inline do
2021-04-17 20:07:23 +05:30
expect { subject }.to change { group_member_user.can?(:create_release, project) }.from(true).to(false)
2020-03-13 15:44:24 +05:30
end
it 'executes UserProjectAccessChangedService' do
2021-04-17 20:07:23 +05:30
expect_next_instance_of(UserProjectAccessChangedService, [group_member_user.id]) do |service|
2020-03-13 15:44:24 +05:30
expect(service).to receive(:execute)
end
subject
end
context 'with only param not requiring authorization refresh' do
let(:group_link_params) { { expires_at: Date.tomorrow } }
it 'does not execute UserProjectAccessChangedService' do
expect(UserProjectAccessChangedService).not_to receive(:new)
subject
end
end
end