diff options
author | Robert Speicher <rspeicher@gmail.com> | 2021-01-20 22:34:23 +0300 |
---|---|---|
committer | Robert Speicher <rspeicher@gmail.com> | 2021-01-20 22:34:23 +0300 |
commit | 6438df3a1e0fb944485cebf07976160184697d72 (patch) | |
tree | 00b09bfd170e77ae9391b1a2f5a93ef6839f2597 /spec/requests/api/graphql/mutations | |
parent | 42bcd54d971da7ef2854b896a7b34f4ef8601067 (diff) |
Add latest changes from gitlab-org/gitlab@13-8-stable-eev13.8.0-rc42
Diffstat (limited to 'spec/requests/api/graphql/mutations')
6 files changed, 212 insertions, 38 deletions
diff --git a/spec/requests/api/graphql/mutations/alert_management/alerts/todo/create_spec.rb b/spec/requests/api/graphql/mutations/alert_management/alerts/todo/create_spec.rb index e5803f50474..cd423d7764a 100644 --- a/spec/requests/api/graphql/mutations/alert_management/alerts/todo/create_spec.rb +++ b/spec/requests/api/graphql/mutations/alert_management/alerts/todo/create_spec.rb @@ -42,6 +42,8 @@ RSpec.describe 'Creating a todo for the alert' do context 'todo already exists' do before do + stub_feature_flags(multiple_todos: false) + create(:todo, :pending, project: project, user: user, target: alert) end diff --git a/spec/requests/api/graphql/mutations/alert_management/http_integration/create_spec.rb b/spec/requests/api/graphql/mutations/alert_management/http_integration/create_spec.rb index a285cebc805..e594d67aab4 100644 --- a/spec/requests/api/graphql/mutations/alert_management/http_integration/create_spec.rb +++ b/spec/requests/api/graphql/mutations/alert_management/http_integration/create_spec.rb @@ -39,21 +39,7 @@ RSpec.describe 'Creating a new HTTP Integration' do project.add_maintainer(current_user) end - it 'creates a new integration' do - post_graphql_mutation(mutation, current_user: current_user) - - new_integration = ::AlertManagement::HttpIntegration.last! - integration_response = mutation_response['integration'] - - expect(response).to have_gitlab_http_status(:success) - expect(integration_response['id']).to eq(GitlabSchema.id_from_object(new_integration).to_s) - expect(integration_response['type']).to eq('HTTP') - expect(integration_response['name']).to eq(new_integration.name) - expect(integration_response['active']).to eq(new_integration.active) - expect(integration_response['token']).to eq(new_integration.token) - expect(integration_response['url']).to eq(new_integration.url) - expect(integration_response['apiUrl']).to eq(nil) - end + it_behaves_like 'creating a new HTTP integration' [:project_path, :active, :name].each do |argument| context "without required argument #{argument}" do diff --git a/spec/requests/api/graphql/mutations/ci/ci_cd_settings_update_spec.rb b/spec/requests/api/graphql/mutations/ci/ci_cd_settings_update_spec.rb new file mode 100644 index 00000000000..283badeaf33 --- /dev/null +++ b/spec/requests/api/graphql/mutations/ci/ci_cd_settings_update_spec.rb @@ -0,0 +1,58 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe 'CiCdSettingsUpdate' do + include GraphqlHelpers + + let_it_be(:project) { create(:project, ci_keep_latest_artifact: true) } + let(:variables) { { full_path: project.full_path, keep_latest_artifact: false } } + let(:mutation) { graphql_mutation(:ci_cd_settings_update, variables) } + + context 'when unauthorized' do + let(:user) { create(:user) } + + shared_examples 'unauthorized' do + it 'returns an error' do + post_graphql_mutation(mutation, current_user: user) + + expect(graphql_errors).not_to be_empty + end + end + + context 'when not a project member' do + it_behaves_like 'unauthorized' + end + + context 'when a non-admin project member' do + before do + project.add_developer(user) + end + + it_behaves_like 'unauthorized' + end + end + + context 'when authorized' do + let_it_be(:user) { project.owner } + + it 'updates ci cd settings' do + post_graphql_mutation(mutation, current_user: user) + + project.reload + + expect(response).to have_gitlab_http_status(:success) + expect(project.ci_keep_latest_artifact).to eq(false) + end + + context 'when bad arguments are provided' do + let(:variables) { { full_path: '', keep_latest_artifact: false } } + + it 'returns the errors' do + post_graphql_mutation(mutation, current_user: user) + + expect(graphql_errors).not_to be_empty + end + end + end +end diff --git a/spec/requests/api/graphql/mutations/namespace/package_settings/update_spec.rb b/spec/requests/api/graphql/mutations/namespace/package_settings/update_spec.rb new file mode 100644 index 00000000000..749373e7b8d --- /dev/null +++ b/spec/requests/api/graphql/mutations/namespace/package_settings/update_spec.rb @@ -0,0 +1,142 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe 'Updating the package settings' do + include GraphqlHelpers + using RSpec::Parameterized::TableSyntax + + let_it_be(:user) { create(:user) } + + let(:params) do + { + namespace_path: namespace.full_path, + maven_duplicates_allowed: false, + maven_duplicate_exception_regex: 'foo-.*' + } + end + + let(:mutation) do + graphql_mutation(:update_namespace_package_settings, params) do + <<~QL + packageSettings { + mavenDuplicatesAllowed + mavenDuplicateExceptionRegex + } + errors + QL + end + end + + let(:mutation_response) { graphql_mutation_response(:update_namespace_package_settings) } + let(:package_settings_response) { mutation_response['packageSettings'] } + + RSpec.shared_examples 'returning a success' do + it_behaves_like 'returning response status', :success + + it 'returns the updated package settings', :aggregate_failures do + subject + + expect(mutation_response['errors']).to be_empty + expect(package_settings_response['mavenDuplicatesAllowed']).to eq(params[:maven_duplicates_allowed]) + expect(package_settings_response['mavenDuplicateExceptionRegex']).to eq(params[:maven_duplicate_exception_regex]) + end + end + + RSpec.shared_examples 'rejecting invalid regex' do + context "for field mavenDuplicateExceptionRegex" do + let_it_be(:invalid_regex) { '][' } + + let(:params) do + { + :namespace_path => namespace.full_path, + 'mavenDuplicateExceptionRegex' => invalid_regex + } + end + + it_behaves_like 'returning response status', :success + + it_behaves_like 'not creating the namespace package setting' + + it 'returns an error', :aggregate_failures do + subject + + expect(graphql_errors.size).to eq(1) + expect(graphql_errors.first['message']).to include("#{invalid_regex} is an invalid regexp") + end + end + end + + RSpec.shared_examples 'accepting the mutation request updating the package settings' 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: 'foo-.*' } + + it_behaves_like 'returning a success' + it_behaves_like 'rejecting invalid regex' + end + + RSpec.shared_examples 'accepting the mutation request creating the package settings' do + it_behaves_like 'creating the namespace package setting' + it_behaves_like 'returning a success' + it_behaves_like 'rejecting invalid regex' + end + + RSpec.shared_examples 'denying the mutation request' do + it_behaves_like 'not creating the namespace package setting' + + it_behaves_like 'returning response status', :success + + it 'returns no response' do + subject + + expect(mutation_response).to be_nil + end + end + + describe 'post graphql mutation' do + subject { post_graphql_mutation(mutation, current_user: user) } + + context 'with existing package settings' do + let_it_be(:package_settings, reload: true) { create(:namespace_package_setting, :group) } + let_it_be(:namespace, reload: true) { package_settings.namespace } + + where(:user_role, :shared_examples_name) do + :maintainer | 'accepting the mutation request updating the package settings' + :developer | 'accepting the mutation request updating the package settings' + :reporter | 'denying the mutation request' + :guest | 'denying the mutation request' + :anonymous | 'denying the mutation request' + 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 package settings' do + let_it_be(:namespace, reload: true) { create(:group) } + let(:package_settings) { namespace.package_settings } + + where(:user_role, :shared_examples_name) do + :maintainer | 'accepting the mutation request creating the package settings' + :developer | 'accepting the mutation request creating the package settings' + :reporter | 'denying the mutation request' + :guest | 'denying the mutation request' + :anonymous | 'denying the mutation request' + 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 diff --git a/spec/requests/api/graphql/mutations/releases/create_spec.rb b/spec/requests/api/graphql/mutations/releases/create_spec.rb index d745eb3083d..79bdcec7944 100644 --- a/spec/requests/api/graphql/mutations/releases/create_spec.rb +++ b/spec/requests/api/graphql/mutations/releases/create_spec.rb @@ -116,11 +116,9 @@ RSpec.describe 'Creation of a new release' do context 'when all available mutation arguments are provided' do it_behaves_like 'no errors' - # rubocop: disable CodeReuse/ActiveRecord it 'returns the new release data' do create_release - release = mutation_response[:release] expected_direct_asset_url = Gitlab::Routing.url_helpers.project_release_url(project, Release.find_by(tag: tag_name)) << "/downloads#{asset_link[:directAssetPath]}" expected_attributes = { @@ -139,21 +137,17 @@ RSpec.describe 'Creation of a new release' do directAssetUrl: expected_direct_asset_url }] } + }, + milestones: { + nodes: [ + { title: '12.3' }, + { title: '12.4' } + ] } - } - - expect(release).to include(expected_attributes) + }.with_indifferent_access - # Right now the milestones are returned in a non-deterministic order. - # This `milestones` test should be moved up into the expect(release) - # above (and `.to include` updated to `.to eq`) once - # https://gitlab.com/gitlab-org/gitlab/-/issues/259012 is addressed. - expect(release['milestones']['nodes']).to match_array([ - { 'title' => '12.4' }, - { 'title' => '12.3' } - ]) + expect(mutation_response[:release]).to eq(expected_attributes) end - # rubocop: enable CodeReuse/ActiveRecord end context 'when only the required mutation arguments are provided' do diff --git a/spec/requests/api/graphql/mutations/releases/update_spec.rb b/spec/requests/api/graphql/mutations/releases/update_spec.rb index 19320c3393c..c9a6c3abd57 100644 --- a/spec/requests/api/graphql/mutations/releases/update_spec.rb +++ b/spec/requests/api/graphql/mutations/releases/update_spec.rb @@ -116,15 +116,7 @@ RSpec.describe 'Updating an existing release' do it 'updates the correct field and returns the release' do update_release - expect(mutation_response[:release]).to include(expected_attributes.merge(updates).except(:milestones)) - - # Right now the milestones are returned in a non-deterministic order. - # Because of this, we need to test milestones separately to allow - # for them to be returned in any order. - # Once https://gitlab.com/gitlab-org/gitlab/-/issues/259012 has been - # fixed, this special milestone handling can be removed. - expected_milestones = expected_attributes.merge(updates)[:milestones] - expect(mutation_response[:release][:milestones][:nodes]).to match_array(expected_milestones[:nodes]) + expect(mutation_response[:release]).to eq(expected_attributes.merge(updates)) end end |