2020-07-10 15:09:07 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
RSpec.describe Packages::Composer::CreatePackageService do
|
|
|
|
include PackagesManagerApiSpecHelpers
|
|
|
|
|
|
|
|
let_it_be(:package_name) { 'composer-package-name' }
|
|
|
|
let_it_be(:json) { { name: package_name }.to_json }
|
2021-08-13 15:11:15 +00:00
|
|
|
let_it_be(:project) { create(:project, :custom_repo, files: { 'composer.json' => json }) }
|
2020-07-10 15:09:07 +00:00
|
|
|
let_it_be(:user) { create(:user) }
|
2021-06-29 03:07:32 +00:00
|
|
|
|
2020-07-10 15:09:07 +00:00
|
|
|
let(:params) do
|
|
|
|
{
|
|
|
|
branch: branch,
|
|
|
|
tag: tag
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#execute' do
|
|
|
|
let(:tag) { nil }
|
|
|
|
let(:branch) { nil }
|
|
|
|
|
|
|
|
subject { described_class.new(project, user, params).execute }
|
|
|
|
|
|
|
|
let(:created_package) { Packages::Package.composer.last }
|
|
|
|
|
|
|
|
context 'without an existing package' do
|
|
|
|
context 'with a branch' do
|
|
|
|
let(:branch) { project.repository.find_branch('master') }
|
|
|
|
|
|
|
|
it 'creates the package' do
|
|
|
|
expect { subject }
|
|
|
|
.to change { Packages::Package.composer.count }.by(1)
|
|
|
|
.and change { Packages::Composer::Metadatum.count }.by(1)
|
|
|
|
|
|
|
|
expect(created_package.name).to eq package_name
|
|
|
|
expect(created_package.version).to eq 'dev-master'
|
|
|
|
expect(created_package.composer_metadatum.target_sha).to eq branch.target
|
|
|
|
expect(created_package.composer_metadatum.composer_json.to_json).to eq json
|
|
|
|
end
|
2020-09-08 15:08:41 +00:00
|
|
|
|
|
|
|
it_behaves_like 'assigns the package creator' do
|
|
|
|
let(:package) { created_package }
|
|
|
|
end
|
2020-12-04 00:09:55 +00:00
|
|
|
|
|
|
|
it_behaves_like 'assigns build to package'
|
2021-02-17 12:09:26 +00:00
|
|
|
it_behaves_like 'assigns status to package'
|
2020-07-10 15:09:07 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'with a tag' do
|
|
|
|
let(:tag) { project.repository.find_tag('v1.2.3') }
|
|
|
|
|
2020-09-08 15:08:41 +00:00
|
|
|
before(:all) do
|
2020-07-10 15:09:07 +00:00
|
|
|
project.repository.add_tag(user, 'v1.2.3', 'master')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates the package' do
|
|
|
|
expect { subject }
|
|
|
|
.to change { Packages::Package.composer.count }.by(1)
|
|
|
|
.and change { Packages::Composer::Metadatum.count }.by(1)
|
|
|
|
|
|
|
|
expect(created_package.name).to eq package_name
|
|
|
|
expect(created_package.version).to eq '1.2.3'
|
|
|
|
end
|
2020-09-08 15:08:41 +00:00
|
|
|
|
|
|
|
it_behaves_like 'assigns the package creator' do
|
|
|
|
let(:package) { created_package }
|
|
|
|
end
|
2020-12-04 00:09:55 +00:00
|
|
|
|
|
|
|
it_behaves_like 'assigns build to package'
|
2021-02-17 12:09:26 +00:00
|
|
|
it_behaves_like 'assigns status to package'
|
2020-07-10 15:09:07 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with an existing package' do
|
|
|
|
let(:branch) { project.repository.find_branch('master') }
|
|
|
|
|
|
|
|
context 'belonging to the same project' do
|
|
|
|
before do
|
|
|
|
described_class.new(project, user, params).execute
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not create a new package' do
|
|
|
|
expect { subject }
|
|
|
|
.to change { Packages::Package.composer.count }.by(0)
|
|
|
|
.and change { Packages::Composer::Metadatum.count }.by(0)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'belonging to another project' do
|
2022-02-11 03:12:21 +00:00
|
|
|
let(:other_project) { create(:project)}
|
2020-07-10 15:09:07 +00:00
|
|
|
let!(:other_package) { create(:composer_package, name: package_name, version: 'dev-master', project: other_project) }
|
|
|
|
|
|
|
|
it 'fails with an error' do
|
|
|
|
expect { subject }
|
|
|
|
.to raise_error(/is already taken/)
|
|
|
|
end
|
2022-02-11 03:12:21 +00:00
|
|
|
|
|
|
|
context 'with pending_destruction package' do
|
|
|
|
let!(:other_package) { create(:composer_package, :pending_destruction, name: package_name, version: 'dev-master', project: other_project) }
|
|
|
|
|
|
|
|
it 'creates the package' do
|
|
|
|
expect { subject }
|
|
|
|
.to change { Packages::Package.composer.count }.by(1)
|
|
|
|
.and change { Packages::Composer::Metadatum.count }.by(1)
|
|
|
|
end
|
|
|
|
end
|
2020-07-10 15:09:07 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'same name but of different type' do
|
|
|
|
let(:other_project) { create(:project) }
|
|
|
|
let!(:other_package) { create(:package, name: package_name, version: 'dev-master', project: other_project) }
|
|
|
|
|
|
|
|
it 'creates the package' do
|
|
|
|
expect { subject }
|
|
|
|
.to change { Packages::Package.composer.count }.by(1)
|
|
|
|
.and change { Packages::Composer::Metadatum.count }.by(1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|