2020-07-28 23:09:34 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
RSpec.describe Packages::CreatePackageFileService, feature_category: :package_registry do
|
2021-01-29 00:20:46 +05:30
|
|
|
let_it_be(:package) { create(:maven_package) }
|
|
|
|
let_it_be(:user) { create(:user) }
|
2021-09-30 23:02:18 +05:30
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
let(:service) { described_class.new(package, params) }
|
2020-07-28 23:09:34 +05:30
|
|
|
|
|
|
|
describe '#execute' do
|
2021-02-22 17:27:13 +05:30
|
|
|
subject { service.execute }
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
context 'with valid params' do
|
|
|
|
let(:params) do
|
|
|
|
{
|
|
|
|
file: Tempfile.new,
|
|
|
|
file_name: 'foo.jar'
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates a new package file' do
|
2021-02-22 17:27:13 +05:30
|
|
|
package_file = subject
|
2020-07-28 23:09:34 +05:30
|
|
|
|
|
|
|
expect(package_file).to be_valid
|
|
|
|
expect(package_file.file_name).to eq('foo.jar')
|
|
|
|
end
|
2021-02-22 17:27:13 +05:30
|
|
|
|
|
|
|
it_behaves_like 'assigns build to package file'
|
2020-07-28 23:09:34 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context 'file is missing' do
|
|
|
|
let(:params) do
|
|
|
|
{
|
|
|
|
file_name: 'foo.jar'
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'raises an error' do
|
2021-02-22 17:27:13 +05:30
|
|
|
expect { subject }.to raise_error(ActiveRecord::RecordInvalid)
|
2020-07-28 23:09:34 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|