diff options
author | Robert Speicher <rspeicher@gmail.com> | 2021-01-20 13:34:23 -0600 |
---|---|---|
committer | Robert Speicher <rspeicher@gmail.com> | 2021-01-20 13:34:23 -0600 |
commit | 6438df3a1e0fb944485cebf07976160184697d72 (patch) | |
tree | 00b09bfd170e77ae9391b1a2f5a93ef6839f2597 /spec/services/namespaces | |
parent | 42bcd54d971da7ef2854b896a7b34f4ef8601067 (diff) | |
download | gitlab-ce-6438df3a1e0fb944485cebf07976160184697d72.tar.gz |
Add latest changes from gitlab-org/gitlab@13-8-stable-eev13.8.0-rc42
Diffstat (limited to 'spec/services/namespaces')
-rw-r--r-- | spec/services/namespaces/package_settings/update_service_spec.rb | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/spec/services/namespaces/package_settings/update_service_spec.rb b/spec/services/namespaces/package_settings/update_service_spec.rb new file mode 100644 index 00000000000..fa0c58e4c9b --- /dev/null +++ b/spec/services/namespaces/package_settings/update_service_spec.rb @@ -0,0 +1,102 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe ::Namespaces::PackageSettings::UpdateService do + using RSpec::Parameterized::TableSyntax + + let_it_be_with_reload(:namespace) { create(:group) } + let_it_be(:user) { create(:user) } + let_it_be(:params) { {} } + + describe '#execute' do + subject { described_class.new(container: namespace, current_user: user, params: params).execute } + + shared_examples 'returning a success' do + it 'returns a success' do + result = subject + + expect(result.payload[:package_settings]).to be_present + expect(result.success?).to be_truthy + end + end + + shared_examples 'returning an error' do |message, http_status| + it 'returns an error' do + result = subject + + expect(result.message).to eq(message) + expect(result.status).to eq(:error) + expect(result.http_status).to eq(http_status) + end + end + + shared_examples 'updating the namespace package setting' do + it_behaves_like 'updating the namespace package setting attributes', from: { maven_duplicates_allowed: true, maven_duplicate_exception_regex: 'SNAPSHOT' }, to: { maven_duplicates_allowed: false, maven_duplicate_exception_regex: 'RELEASE' } + + it_behaves_like 'returning a success' + + context 'with invalid params' do + let_it_be(:params) { { maven_duplicates_allowed: nil } } + + it_behaves_like 'not creating the namespace package setting' + + it "doesn't update the maven_duplicates_allowed" do + expect { subject } + .not_to change { package_settings.reload.maven_duplicates_allowed } + end + + it_behaves_like 'returning an error', 'Maven duplicates allowed is not included in the list', 400 + end + end + + shared_examples 'denying access to namespace package setting' do + context 'with existing namespace package setting' do + it_behaves_like 'not creating the namespace package setting' + + it_behaves_like 'returning an error', 'Access Denied', 403 + end + end + + context 'with existing namespace package setting' do + let_it_be(:package_settings) { create(:namespace_package_setting, namespace: namespace) } + let_it_be(:params) { { maven_duplicates_allowed: false, maven_duplicate_exception_regex: 'RELEASE' } } + + where(:user_role, :shared_examples_name) do + :maintainer | 'updating the namespace package setting' + :developer | 'updating the namespace package setting' + :reporter | 'denying access to namespace package setting' + :guest | 'denying access to namespace package setting' + :anonymous | 'denying access to namespace package setting' + end + + with_them do + before do + namespace.send("add_#{user_role}", user) unless user_role == :anonymous + end + + it_behaves_like params[:shared_examples_name] + end + end + + context 'without existing namespace package setting' do + let_it_be(:package_settings) { namespace.package_settings } + + where(:user_role, :shared_examples_name) do + :maintainer | 'creating the namespace package setting' + :developer | 'creating the namespace package setting' + :reporter | 'denying access to namespace package setting' + :guest | 'denying access to namespace package setting' + :anonymous | 'denying access to namespace package setting' + end + + with_them do + before do + namespace.send("add_#{user_role}", user) unless user_role == :anonymous + end + + it_behaves_like params[:shared_examples_name] + end + end + end +end |