2020-07-10 11:09:07 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
RSpec.describe Packages::Conan::CreatePackageService do
|
|
|
|
let_it_be(:project) { create(:project) }
|
|
|
|
let_it_be(:user) { create(:user) }
|
|
|
|
|
2020-09-08 11:08:41 -04:00
|
|
|
subject(:service) { described_class.new(project, user, params) }
|
2020-07-10 11:09:07 -04:00
|
|
|
|
|
|
|
describe '#execute' do
|
2020-09-08 11:08:41 -04:00
|
|
|
subject(:package) { service.execute }
|
|
|
|
|
2020-07-10 11:09:07 -04:00
|
|
|
context 'valid params' do
|
|
|
|
let(:params) do
|
|
|
|
{
|
|
|
|
package_name: 'my-pkg',
|
|
|
|
package_version: '1.0.0',
|
|
|
|
package_username: ::Packages::Conan::Metadatum.package_username_from(full_path: project.full_path),
|
|
|
|
package_channel: 'stable'
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates a new package' do
|
|
|
|
expect(package).to be_valid
|
|
|
|
expect(package.name).to eq(params[:package_name])
|
|
|
|
expect(package.version).to eq(params[:package_version])
|
|
|
|
expect(package.package_type).to eq('conan')
|
|
|
|
expect(package.conan_metadatum.package_username).to eq(params[:package_username])
|
|
|
|
expect(package.conan_metadatum.package_channel).to eq(params[:package_channel])
|
|
|
|
end
|
2020-09-08 11:08:41 -04:00
|
|
|
|
|
|
|
it_behaves_like 'assigns the package creator'
|
2020-12-03 19:09:55 -05:00
|
|
|
it_behaves_like 'assigns build to package'
|
2021-02-17 07:09:26 -05:00
|
|
|
it_behaves_like 'assigns status to package'
|
2020-07-10 11:09:07 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'invalid params' do
|
|
|
|
let(:params) do
|
|
|
|
{
|
|
|
|
package_name: 'my-pkg',
|
|
|
|
package_version: '1.0.0',
|
|
|
|
package_username: 'foo/bar',
|
|
|
|
package_channel: 'stable'
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'fails' do
|
2020-09-08 11:08:41 -04:00
|
|
|
expect { package }.to raise_exception(ActiveRecord::RecordInvalid)
|
2020-07-10 11:09:07 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|