diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-06-20 14:10:13 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-06-20 14:10:13 +0300 |
commit | 0ea3fcec397b69815975647f5e2aa5fe944a8486 (patch) | |
tree | 7979381b89d26011bcf9bdc989a40fcc2f1ed4ff /spec/graphql/mutations | |
parent | 72123183a20411a36d607d70b12d57c484394c8e (diff) |
Add latest changes from gitlab-org/gitlab@15-1-stable-eev15.1.0-rc42
Diffstat (limited to 'spec/graphql/mutations')
19 files changed, 143 insertions, 72 deletions
diff --git a/spec/graphql/mutations/boards/issues/issue_move_list_spec.rb b/spec/graphql/mutations/boards/issues/issue_move_list_spec.rb index 11c0fa44110..10aed8a1f00 100644 --- a/spec/graphql/mutations/boards/issues/issue_move_list_spec.rb +++ b/spec/graphql/mutations/boards/issues/issue_move_list_spec.rb @@ -19,7 +19,7 @@ RSpec.describe Mutations::Boards::Issues::IssueMoveList do let_it_be(:existing_issue2) { create(:labeled_issue, project: project, labels: [testing], relative_position: 50) } let(:current_ctx) { { current_user: user } } - let(:params) { { board_id: global_id_of(board), project_path: project.full_path, iid: issue1.iid } } + let(:params) { { board_id: global_id_of(board), project_path: project.full_path, iid: issue1.iid.to_s } } let(:move_params) do { from_list_id: list1.id, @@ -67,7 +67,7 @@ RSpec.describe Mutations::Boards::Issues::IssueMoveList do end it 'raises an error' do - expect { subject }.to raise_error(::GraphQL::LoadApplicationObjectFailedError) + expect { subject }.to raise_error(::GraphQL::CoercionError, "\"#{params[:board_id]}\" does not represent an instance of Board") end end diff --git a/spec/graphql/mutations/branches/create_spec.rb b/spec/graphql/mutations/branches/create_spec.rb index e378a8e3d41..5e9b914d87c 100644 --- a/spec/graphql/mutations/branches/create_spec.rb +++ b/spec/graphql/mutations/branches/create_spec.rb @@ -3,13 +3,16 @@ require 'spec_helper' RSpec.describe Mutations::Branches::Create do + include GraphqlHelpers + subject(:mutation) { described_class.new(object: nil, context: context, field: nil) } let_it_be(:project) { create(:project, :public, :repository) } let_it_be(:user) { create(:user) } - let_it_be(:context) do + + let(:context) do GraphQL::Query::Context.new( - query: OpenStruct.new(schema: nil), + query: query_double(schema: nil), values: { current_user: user }, object: nil ) diff --git a/spec/graphql/mutations/ci/runner/update_spec.rb b/spec/graphql/mutations/ci/runner/update_spec.rb index 75e9b57e60a..ffaa6e93d1b 100644 --- a/spec/graphql/mutations/ci/runner/update_spec.rb +++ b/spec/graphql/mutations/ci/runner/update_spec.rb @@ -2,11 +2,12 @@ require 'spec_helper' -RSpec.describe Mutations::Ci::Runner::Update do +RSpec.describe 'Mutations::Ci::Runner::Update' do include GraphqlHelpers let_it_be(:user) { create(:user) } let_it_be(:runner) { create(:ci_runner, active: true, locked: false, run_untagged: true) } + let_it_be(:described_class) { Mutations::Ci::Runner::Update } let(:current_ctx) { { current_user: user } } let(:mutated_runner) { subject[:runner] } @@ -49,6 +50,7 @@ RSpec.describe Mutations::Ci::Runner::Update do { id: runner.to_global_id, description: 'updated description', + maintenance_note: 'updated maintenance note', maximum_timeout: 900, access_level: 'ref_protected', active: false, @@ -84,6 +86,16 @@ RSpec.describe Mutations::Ci::Runner::Update do ) end end + + context 'with too long maintenance note' do + it 'returns a descriptive error' do + mutation_params[:maintenance_note] = '1' * 1025 + + expect(subject[:errors]).to contain_exactly( + 'Maintenance note is too long (maximum is 1024 characters)' + ) + end + end end end end diff --git a/spec/graphql/mutations/clusters/agent_tokens/create_spec.rb b/spec/graphql/mutations/clusters/agent_tokens/create_spec.rb index 45d421509d0..7998be19c20 100644 --- a/spec/graphql/mutations/clusters/agent_tokens/create_spec.rb +++ b/spec/graphql/mutations/clusters/agent_tokens/create_spec.rb @@ -3,6 +3,8 @@ require 'spec_helper' RSpec.describe Mutations::Clusters::AgentTokens::Create do + include GraphqlHelpers + subject(:mutation) { described_class.new(object: nil, context: context, field: nil) } let_it_be(:cluster_agent) { create(:cluster_agent) } @@ -10,7 +12,7 @@ RSpec.describe Mutations::Clusters::AgentTokens::Create do let(:context) do GraphQL::Query::Context.new( - query: OpenStruct.new(schema: nil), + query: query_double(schema: nil), # rubocop:disable RSpec/VerifiedDoubles values: { current_user: user }, object: nil ) diff --git a/spec/graphql/mutations/clusters/agents/create_spec.rb b/spec/graphql/mutations/clusters/agents/create_spec.rb index c80b6f6cdad..e2c04254ed8 100644 --- a/spec/graphql/mutations/clusters/agents/create_spec.rb +++ b/spec/graphql/mutations/clusters/agents/create_spec.rb @@ -3,13 +3,15 @@ require 'spec_helper' RSpec.describe Mutations::Clusters::Agents::Create do + include GraphqlHelpers + subject(:mutation) { described_class.new(object: nil, context: context, field: nil) } let(:project) { create(:project, :public, :repository) } let(:user) { create(:user) } let(:context) do GraphQL::Query::Context.new( - query: OpenStruct.new(schema: nil), + query: query_double(schema: nil), # rubocop:disable RSpec/VerifiedDoubles values: { current_user: user }, object: nil ) diff --git a/spec/graphql/mutations/clusters/agents/delete_spec.rb b/spec/graphql/mutations/clusters/agents/delete_spec.rb index e0ecff5fe44..c3a2c0dcbb4 100644 --- a/spec/graphql/mutations/clusters/agents/delete_spec.rb +++ b/spec/graphql/mutations/clusters/agents/delete_spec.rb @@ -3,6 +3,8 @@ require 'spec_helper' RSpec.describe Mutations::Clusters::Agents::Delete do + include GraphqlHelpers + subject(:mutation) { described_class.new(object: nil, context: context, field: nil) } let(:cluster_agent) { create(:cluster_agent) } @@ -10,7 +12,7 @@ RSpec.describe Mutations::Clusters::Agents::Delete do let(:user) { create(:user) } let(:context) do GraphQL::Query::Context.new( - query: OpenStruct.new(schema: nil), + query: query_double(schema: nil), # rubocop:disable RSpec/VerifiedDoubles values: { current_user: user }, object: nil ) diff --git a/spec/graphql/mutations/commits/create_spec.rb b/spec/graphql/mutations/commits/create_spec.rb index 097e70bada6..9fc9c731b96 100644 --- a/spec/graphql/mutations/commits/create_spec.rb +++ b/spec/graphql/mutations/commits/create_spec.rb @@ -3,6 +3,8 @@ require 'spec_helper' RSpec.describe Mutations::Commits::Create do + include GraphqlHelpers + subject(:mutation) { described_class.new(object: nil, context: context, field: nil) } let_it_be(:user) { create(:user) } @@ -10,7 +12,7 @@ RSpec.describe Mutations::Commits::Create do let(:context) do GraphQL::Query::Context.new( - query: OpenStruct.new(schema: nil), + query: query_double(schema: nil), # rubocop:disable RSpec/VerifiedDoubles values: { current_user: user }, object: nil ) diff --git a/spec/graphql/mutations/customer_relations/contacts/create_spec.rb b/spec/graphql/mutations/customer_relations/contacts/create_spec.rb index dafc7b4c367..f2bbf0949fb 100644 --- a/spec/graphql/mutations/customer_relations/contacts/create_spec.rb +++ b/spec/graphql/mutations/customer_relations/contacts/create_spec.rb @@ -40,17 +40,6 @@ RSpec.describe Mutations::CustomerRelations::Contacts::Create do group.add_developer(user) end - context 'when the feature flag is disabled' do - before do - stub_feature_flags(customer_relations: false) - end - - it 'raises an error' do - expect { resolve_mutation }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable) - .with_message("The resource that you are attempting to access does not exist or you don't have permission to perform this action") - end - end - context 'when crm_enabled is false' do let(:group) { create(:group) } diff --git a/spec/graphql/mutations/customer_relations/contacts/update_spec.rb b/spec/graphql/mutations/customer_relations/contacts/update_spec.rb index c8206eca442..421bb4f1b06 100644 --- a/spec/graphql/mutations/customer_relations/contacts/update_spec.rb +++ b/spec/graphql/mutations/customer_relations/contacts/update_spec.rb @@ -57,17 +57,6 @@ RSpec.describe Mutations::CustomerRelations::Contacts::Update do it 'updates the organization with correct values' do expect(resolve_mutation[:contact]).to have_attributes(attributes) end - - context 'when the feature is disabled' do - before do - stub_feature_flags(customer_relations: false) - end - - it 'raises an error' do - expect { resolve_mutation }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable) - .with_message("The resource that you are attempting to access does not exist or you don't have permission to perform this action") - end - end end end diff --git a/spec/graphql/mutations/customer_relations/organizations/create_spec.rb b/spec/graphql/mutations/customer_relations/organizations/create_spec.rb index ee78d2b16f6..ffc9632350a 100644 --- a/spec/graphql/mutations/customer_relations/organizations/create_spec.rb +++ b/spec/graphql/mutations/customer_relations/organizations/create_spec.rb @@ -39,17 +39,6 @@ RSpec.describe Mutations::CustomerRelations::Organizations::Create do group.add_developer(user) end - context 'when the feature is disabled' do - before do - stub_feature_flags(customer_relations: false) - end - - it 'raises an error' do - expect { resolve_mutation }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable) - .with_message("The resource that you are attempting to access does not exist or you don't have permission to perform this action") - end - end - context 'when the params are invalid' do before do valid_params[:name] = nil diff --git a/spec/graphql/mutations/customer_relations/organizations/update_spec.rb b/spec/graphql/mutations/customer_relations/organizations/update_spec.rb index 90fd7a0a9f1..f0f37ee9c47 100644 --- a/spec/graphql/mutations/customer_relations/organizations/update_spec.rb +++ b/spec/graphql/mutations/customer_relations/organizations/update_spec.rb @@ -56,17 +56,6 @@ RSpec.describe Mutations::CustomerRelations::Organizations::Update do expect(resolve_mutation[:organization]).to have_attributes(attributes) end - context 'when the feature flag is disabled' do - before do - stub_feature_flags(customer_relations: false) - end - - it 'raises an error' do - expect { resolve_mutation }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable) - .with_message("The resource that you are attempting to access does not exist or you don't have permission to perform this action") - end - end - context 'when the feature is disabled' do let_it_be(:group) { create(:group) } diff --git a/spec/graphql/mutations/incident_management/timeline_event/create_spec.rb b/spec/graphql/mutations/incident_management/timeline_event/create_spec.rb index 63faecad5d5..ea74e427dd6 100644 --- a/spec/graphql/mutations/incident_management/timeline_event/create_spec.rb +++ b/spec/graphql/mutations/incident_management/timeline_event/create_spec.rb @@ -22,7 +22,8 @@ RSpec.describe Mutations::IncidentManagement::TimelineEvent::Create do occurred_at: args[:occurred_at].to_s, incident: incident, author: current_user, - promoted_from_note: nil + promoted_from_note: nil, + editable: true ) end diff --git a/spec/graphql/mutations/incident_management/timeline_event/promote_from_note_spec.rb b/spec/graphql/mutations/incident_management/timeline_event/promote_from_note_spec.rb index 598ee496cf1..4541f8af7d3 100644 --- a/spec/graphql/mutations/incident_management/timeline_event/promote_from_note_spec.rb +++ b/spec/graphql/mutations/incident_management/timeline_event/promote_from_note_spec.rb @@ -27,7 +27,8 @@ RSpec.describe Mutations::IncidentManagement::TimelineEvent::PromoteFromNote do occurred_at: comment.created_at.to_s, incident: incident, author: current_user, - promoted_from_note: comment + promoted_from_note: comment, + editable: true ) end diff --git a/spec/graphql/mutations/issues/set_escalation_status_spec.rb b/spec/graphql/mutations/issues/set_escalation_status_spec.rb index d41118b1812..f04d396efb8 100644 --- a/spec/graphql/mutations/issues/set_escalation_status_spec.rb +++ b/spec/graphql/mutations/issues/set_escalation_status_spec.rb @@ -50,16 +50,6 @@ RSpec.describe Mutations::Issues::SetEscalationStatus do expect { result }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable, 'Feature unavailable for provided issue') end end - - context 'with feature disabled' do - before do - stub_feature_flags(incident_escalations: false) - end - - it 'raises an error' do - expect { result }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable, 'Feature unavailable for provided issue') - end - end end end end diff --git a/spec/graphql/mutations/release_asset_links/create_spec.rb b/spec/graphql/mutations/release_asset_links/create_spec.rb index 86a6c77fa3f..a5291a00799 100644 --- a/spec/graphql/mutations/release_asset_links/create_spec.rb +++ b/spec/graphql/mutations/release_asset_links/create_spec.rb @@ -37,7 +37,7 @@ RSpec.describe Mutations::ReleaseAssetLinks::Create do context 'when the user has access and no validation errors occur' do it 'creates a new release asset link', :aggregate_failures do - expect(subject).to eq({ + expect(subject).to include({ link: release.reload.links.first, errors: [] }) diff --git a/spec/graphql/mutations/security/ci_configuration/base_security_analyzer_spec.rb b/spec/graphql/mutations/security/ci_configuration/base_security_analyzer_spec.rb index 818a7d303bd..668768189df 100644 --- a/spec/graphql/mutations/security/ci_configuration/base_security_analyzer_spec.rb +++ b/spec/graphql/mutations/security/ci_configuration/base_security_analyzer_spec.rb @@ -7,8 +7,10 @@ RSpec.describe Mutations::Security::CiConfiguration::BaseSecurityAnalyzer do it 'raises a NotImplementedError error if the resolve method is called on the base class' do user = create(:user) + mutation = described_class.new(context: { current_user: user }, object: nil, field: nil) project = create(:project, :public, :repository) project.add_developer(user) - expect { resolve(described_class, args: { project_path: project.full_path }, ctx: { current_user: user }) }.to raise_error(NotImplementedError) + + expect { mutation.resolve(project_path: project.full_path ) }.to raise_error(NotImplementedError) end end diff --git a/spec/graphql/mutations/terraform/state/delete_spec.rb b/spec/graphql/mutations/terraform/state/delete_spec.rb index 313a85a4bac..66d4b50741f 100644 --- a/spec/graphql/mutations/terraform/state/delete_spec.rb +++ b/spec/graphql/mutations/terraform/state/delete_spec.rb @@ -34,12 +34,12 @@ RSpec.describe Mutations::Terraform::State::Delete do state.project.add_maintainer(user) end - it 'deletes the state', :aggregate_failures do - expect do - expect(subject).to eq(errors: []) - end.to change { ::Terraform::State.count }.by(-1) + it 'schedules the state for deletion', :aggregate_failures do + expect_next_instance_of(Terraform::States::TriggerDestroyService, state, current_user: user) do |service| + expect(service).to receive(:execute).once.and_return(ServiceResponse.success) + end - expect { state.reload }.to raise_error(ActiveRecord::RecordNotFound) + subject end end diff --git a/spec/graphql/mutations/work_items/update_task_spec.rb b/spec/graphql/mutations/work_items/update_task_spec.rb new file mode 100644 index 00000000000..cb93e97504a --- /dev/null +++ b/spec/graphql/mutations/work_items/update_task_spec.rb @@ -0,0 +1,40 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Mutations::WorkItems::UpdateTask do + let_it_be(:project) { create(:project) } + let_it_be(:developer) { create(:user).tap { |user| project.add_developer(user) } } + let_it_be(:referenced_work_item, refind: true) { create(:work_item, project: project, title: 'REFERENCED') } + let_it_be(:parent_work_item) do + create(:work_item, project: project, description: "- [ ] #{referenced_work_item.to_reference}+") + end + + let(:task_params) { { title: 'UPDATED' } } + let(:task_input) { { id: referenced_work_item.to_global_id }.merge(task_params) } + let(:input) { { id: parent_work_item.to_global_id, task_data: task_input } } + let(:mutation) { described_class.new(object: nil, context: { current_user: current_user }, field: nil) } + + describe '#resolve' do + subject(:resolve) do + mutation.resolve(**input) + end + + before do + stub_spam_services + end + + context 'when user has sufficient permissions' do + let(:current_user) { developer } + + it 'expires etag cache for parent work item' do + allow(WorkItem).to receive(:find).and_call_original + allow(WorkItem).to receive(:find).with(parent_work_item.id.to_s).and_return(parent_work_item) + + expect(parent_work_item).to receive(:expire_etag_cache) + + resolve + end + end + end +end diff --git a/spec/graphql/mutations/work_items/update_widgets_spec.rb b/spec/graphql/mutations/work_items/update_widgets_spec.rb new file mode 100644 index 00000000000..2e54b81b5c7 --- /dev/null +++ b/spec/graphql/mutations/work_items/update_widgets_spec.rb @@ -0,0 +1,58 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Mutations::WorkItems::UpdateWidgets do + include GraphqlHelpers + + let_it_be(:project) { create(:project) } + let_it_be(:developer) { create(:user).tap { |user| project.add_developer(user) } } + + let(:mutation) { described_class.new(object: nil, context: { current_user: current_user }, field: nil) } + + describe '#resolve' do + before do + stub_spam_services + end + + context 'when no work item matches the given id' do + let(:current_user) { developer } + let(:gid) { global_id_of(id: non_existing_record_id, model_name: WorkItem.name) } + + it 'raises an error' do + expect { mutation.resolve(id: gid, resolve: true) }.to raise_error( + Gitlab::Graphql::Errors::ResourceNotAvailable, + Gitlab::Graphql::Authorize::AuthorizeResource::RESOURCE_ACCESS_ERROR + ) + end + end + + context 'when user can access the requested work item', :aggregate_failures do + let(:current_user) { developer } + let(:args) { {} } + + let_it_be(:work_item) { create(:work_item, project: project) } + + subject { mutation.resolve(id: work_item.to_global_id, **args) } + + context 'when `:work_items` is disabled for a project' do + let_it_be(:project2) { create(:project) } + + it 'returns an error' do + stub_feature_flags(work_items: project2) # only enable `work_item` for project2 + + expect(subject[:errors]).to contain_exactly('`work_items` feature flag disabled for this project') + end + end + + context 'when resolved with an input for description widget' do + let(:args) { { description_widget: { description: "updated description" } } } + + it 'returns the updated work item' do + expect(subject[:work_item].description).to eq("updated description") + expect(subject[:errors]).to be_empty + end + end + end + end +end |