diff options
Diffstat (limited to 'spec/requests/api/npm_project_packages_spec.rb')
-rw-r--r-- | spec/requests/api/npm_project_packages_spec.rb | 43 |
1 files changed, 40 insertions, 3 deletions
diff --git a/spec/requests/api/npm_project_packages_spec.rb b/spec/requests/api/npm_project_packages_spec.rb index ab74da4bda4..8c35a1642e2 100644 --- a/spec/requests/api/npm_project_packages_spec.rb +++ b/spec/requests/api/npm_project_packages_spec.rb @@ -78,7 +78,7 @@ RSpec.describe API::NpmProjectPackages do context 'with a job token for a different user' do let_it_be(:other_user) { create(:user) } - let_it_be_with_reload(:other_job) { create(:ci_build, :running, user: other_user, project: project) } + let_it_be_with_reload(:other_job) { create(:ci_build, :running, user: other_user) } let(:headers) { build_token_auth_header(other_job.token) } @@ -161,8 +161,10 @@ RSpec.describe API::NpmProjectPackages do end end - context 'valid package record' do - let(:params) { upload_params(package_name: package_name) } + context 'valid package params' do + let_it_be(:version) { '1.2.3' } + + let(:params) { upload_params(package_name: package_name, package_version: version) } let(:snowplow_gitlab_standard_context) { { project: project, namespace: project.namespace, user: user } } shared_examples 'handling upload with different authentications' do @@ -211,6 +213,15 @@ RSpec.describe API::NpmProjectPackages do end end + shared_examples 'uploading the package' do + it 'uploads the package' do + expect { upload_package_with_token(package_name, params) } + .to change { project.packages.count }.by(1) + + expect(response).to have_gitlab_http_status(:ok) + end + end + context 'with a scoped name' do let(:package_name) { "@#{group.path}/my_package_name" } @@ -228,6 +239,32 @@ RSpec.describe API::NpmProjectPackages do it_behaves_like 'handling upload with different authentications' end + + context 'with an existing package' do + let_it_be(:second_project) { create(:project, namespace: namespace) } + + context 'following the naming convention' do + let_it_be(:second_package) { create(:npm_package, project: second_project, name: "@#{group.path}/test", version: version) } + + let(:package_name) { "@#{group.path}/test" } + + it_behaves_like 'handling invalid record with 400 error' + + context 'with a new version' do + let_it_be(:version) { '4.5.6' } + + it_behaves_like 'uploading the package' + end + end + + context 'not following the naming convention' do + let_it_be(:second_package) { create(:npm_package, project: second_project, name: "@any_scope/test", version: version) } + + let(:package_name) { "@any_scope/test" } + + it_behaves_like 'uploading the package' + end + end end context 'package creation fails' do |