Commit b9132102 authored by Giorgenes Gelatti's avatar Giorgenes Gelatti

Refactor transfer service

Refactor transfer service code
and specs to improve code quality
and specs efficiency
parent f495e00a
......@@ -54,9 +54,7 @@ module Groups
npm_packages = ::Packages::GroupPackagesFinder.new(current_user, group, package_type: :npm).execute
return true if different_root_ancestor? && npm_packages.exists?
false
different_root_ancestor? && npm_packages.exists?
end
def different_root_ancestor?
......
......@@ -6198,38 +6198,40 @@ RSpec.describe Project do
subject { project.has_packages?(package_type) }
shared_examples 'returning true examples' do
let!(:package) { create("#{package_type}_package", project: project) }
shared_examples 'has_package' do
context 'package of package_type exists' do
let!(:package) { create("#{package_type}_package", project: project) }
it { is_expected.to be true }
end
it { is_expected.to be true }
end
shared_examples 'returning false examples' do
it { is_expected.to be false }
context 'package of package_type does not exist' do
it { is_expected.to be false }
end
end
context 'with maven packages' do
it_behaves_like 'returning true examples' do
it_behaves_like 'has_package' do
let(:package_type) { :maven }
end
end
context 'with npm packages' do
it_behaves_like 'returning true examples' do
it_behaves_like 'has_package' do
let(:package_type) { :npm }
end
end
context 'with conan packages' do
it_behaves_like 'returning true examples' do
it_behaves_like 'has_package' do
let(:package_type) { :conan }
end
end
context 'with no package type' do
it_behaves_like 'returning false examples' do
let(:package_type) { nil }
end
context 'calling has_package? with nil' do
let(:package_type) { nil }
it { is_expected.to be false }
end
end
......
......@@ -9,7 +9,7 @@ RSpec.describe Groups::TransferService do
let(:transfer_service) { described_class.new(group, user) }
context 'handling packages' do
let(:group) { create(:group, :public) }
let_it_be(:group) { create(:group, :public) }
let(:project) { create(:project, :public, namespace: group) }
let(:new_group) { create(:group, :public) }
......@@ -28,6 +28,7 @@ RSpec.describe Groups::TransferService do
transfer_service.execute(new_group)
expect(transfer_service.error).to eq('Transfer failed: Group contains projects with NPM packages.')
expect(group.parent).not_to eq(new_group)
end
end
......@@ -49,7 +50,7 @@ RSpec.describe Groups::TransferService do
it 'allows transfer' do
transfer_service.execute(new_group)
expect(transfer_service.error).not_to be
expect(transfer_service.error).to be nil
expect(group.parent).to eq(new_group)
end
end
......@@ -69,7 +70,7 @@ RSpec.describe Groups::TransferService do
it 'allows transfer' do
transfer_service.execute(nil)
expect(transfer_service.error).not_to be
expect(transfer_service.error).to be nil
expect(group.parent).to be_nil
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment