diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-01-20 09:16:11 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-01-20 09:16:11 +0000 |
commit | edaa33dee2ff2f7ea3fac488d41558eb5f86d68c (patch) | |
tree | 11f143effbfeba52329fb7afbd05e6e2a3790241 /spec/graphql/mutations | |
parent | d8a5691316400a0f7ec4f83832698f1988eb27c1 (diff) | |
download | gitlab-ce-edaa33dee2ff2f7ea3fac488d41558eb5f86d68c.tar.gz |
Add latest changes from gitlab-org/gitlab@14-7-stable-eev14.7.0-rc42
Diffstat (limited to 'spec/graphql/mutations')
7 files changed, 153 insertions, 14 deletions
diff --git a/spec/graphql/mutations/ci/runner/delete_spec.rb b/spec/graphql/mutations/ci/runner/delete_spec.rb index 27e8236d593..9f30c95edd5 100644 --- a/spec/graphql/mutations/ci/runner/delete_spec.rb +++ b/spec/graphql/mutations/ci/runner/delete_spec.rb @@ -5,9 +5,9 @@ require 'spec_helper' RSpec.describe Mutations::Ci::Runner::Delete do include GraphqlHelpers - let_it_be(:user) { create(:user) } let_it_be(:runner) { create(:ci_runner) } + let(:user) { create(:user) } let(:current_ctx) { { current_user: user } } let(:mutation_params) do @@ -46,10 +46,10 @@ RSpec.describe Mutations::Ci::Runner::Delete do end context 'when user can delete owned runner' do - let_it_be(:project) { create(:project, creator_id: user.id) } - let_it_be(:project_runner, reload: true) { create(:ci_runner, :project, description: 'Project runner', projects: [project]) } + let!(:project) { create(:project, creator_id: user.id) } + let!(:project_runner) { create(:ci_runner, :project, description: 'Project runner', projects: [project]) } - before_all do + before do project.add_maintainer(user) end @@ -63,10 +63,10 @@ RSpec.describe Mutations::Ci::Runner::Delete do end context 'with more than one associated project' do - let_it_be(:project2) { create(:project, creator_id: user.id) } - let_it_be(:two_projects_runner) { create(:ci_runner, :project, description: 'Two projects runner', projects: [project, project2]) } + let!(:project2) { create(:project, creator_id: user.id) } + let!(:two_projects_runner) { create(:ci_runner, :project, description: 'Two projects runner', projects: [project, project2]) } - before_all do + before do project2.add_maintainer(user) end diff --git a/spec/graphql/mutations/clusters/agent_tokens/revoke_spec.rb b/spec/graphql/mutations/clusters/agent_tokens/revoke_spec.rb new file mode 100644 index 00000000000..f5f4c0cefad --- /dev/null +++ b/spec/graphql/mutations/clusters/agent_tokens/revoke_spec.rb @@ -0,0 +1,55 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Mutations::Clusters::AgentTokens::Revoke do + let_it_be(:token) { create(:cluster_agent_token) } + let_it_be(:user) { create(:user) } + + let(:mutation) do + described_class.new( + object: double, + context: { current_user: user }, + field: double + ) + end + + it { expect(described_class.graphql_name).to eq('ClusterAgentTokenRevoke') } + it { expect(described_class).to require_graphql_authorizations(:admin_cluster) } + + describe '#resolve' do + let(:global_id) { token.to_global_id } + + subject { mutation.resolve(id: global_id) } + + context 'user does not have permission' do + it 'does not revoke the token' do + expect { subject }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable) + + expect(token.reload).not_to be_revoked + end + end + + context 'user has permission' do + before do + token.agent.project.add_maintainer(user) + end + + it 'revokes the token' do + subject + + expect(token.reload).to be_revoked + end + + context 'supplied ID is invalid' do + let(:global_id) { token.id } + + it 'raises a coercion error' do + expect { subject }.to raise_error(::GraphQL::CoercionError) + + expect(token.reload).not_to be_revoked + end + end + end + end +end diff --git a/spec/graphql/mutations/customer_relations/contacts/create_spec.rb b/spec/graphql/mutations/customer_relations/contacts/create_spec.rb index 0f05504d4f2..d17d11305b1 100644 --- a/spec/graphql/mutations/customer_relations/contacts/create_spec.rb +++ b/spec/graphql/mutations/customer_relations/contacts/create_spec.rb @@ -4,8 +4,8 @@ require 'spec_helper' RSpec.describe Mutations::CustomerRelations::Contacts::Create do let_it_be(:user) { create(:user) } - let_it_be(:group) { create(:group) } + let(:group) { create(:group, :crm_enabled) } let(:not_found_or_does_not_belong) { 'The specified organization was not found or does not belong to this group' } let(:valid_params) do attributes_for(:contact, @@ -34,11 +34,11 @@ RSpec.describe Mutations::CustomerRelations::Contacts::Create do end context 'when the user has permission' do - before_all do + before do group.add_developer(user) end - context 'when the feature is disabled' do + context 'when the feature flag is disabled' do before do stub_feature_flags(customer_relations: false) end @@ -49,6 +49,15 @@ RSpec.describe Mutations::CustomerRelations::Contacts::Create do end end + context 'when crm_enabled is false' do + let(:group) { create(:group) } + + 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 it 'returns the validation error' do valid_params[:first_name] = nil diff --git a/spec/graphql/mutations/customer_relations/contacts/update_spec.rb b/spec/graphql/mutations/customer_relations/contacts/update_spec.rb index 4f59de194fd..c8206eca442 100644 --- a/spec/graphql/mutations/customer_relations/contacts/update_spec.rb +++ b/spec/graphql/mutations/customer_relations/contacts/update_spec.rb @@ -4,7 +4,7 @@ require 'spec_helper' RSpec.describe Mutations::CustomerRelations::Contacts::Update do let_it_be(:user) { create(:user) } - let_it_be(:group) { create(:group) } + let_it_be(:group) { create(:group, :crm_enabled) } let(:first_name) { 'Lionel' } let(:last_name) { 'Smith' } diff --git a/spec/graphql/mutations/customer_relations/organizations/create_spec.rb b/spec/graphql/mutations/customer_relations/organizations/create_spec.rb index 9be0f5d4289..ee78d2b16f6 100644 --- a/spec/graphql/mutations/customer_relations/organizations/create_spec.rb +++ b/spec/graphql/mutations/customer_relations/organizations/create_spec.rb @@ -4,7 +4,7 @@ require 'spec_helper' RSpec.describe Mutations::CustomerRelations::Organizations::Create do let_it_be(:user) { create(:user) } - let_it_be(:group) { create(:group) } + let_it_be(:group) { create(:group, :crm_enabled) } let(:valid_params) do attributes_for(:organization, diff --git a/spec/graphql/mutations/customer_relations/organizations/update_spec.rb b/spec/graphql/mutations/customer_relations/organizations/update_spec.rb index e3aa8eafe0c..90fd7a0a9f1 100644 --- a/spec/graphql/mutations/customer_relations/organizations/update_spec.rb +++ b/spec/graphql/mutations/customer_relations/organizations/update_spec.rb @@ -4,7 +4,7 @@ require 'spec_helper' RSpec.describe Mutations::CustomerRelations::Organizations::Update do let_it_be(:user) { create(:user) } - let_it_be(:group) { create(:group) } + let_it_be(:group) { create(:group, :crm_enabled) } let(:name) { 'GitLab' } let(:default_rate) { 1000.to_f } @@ -56,7 +56,7 @@ RSpec.describe Mutations::CustomerRelations::Organizations::Update do expect(resolve_mutation[:organization]).to have_attributes(attributes) end - context 'when the feature is disabled' do + context 'when the feature flag is disabled' do before do stub_feature_flags(customer_relations: false) end @@ -66,6 +66,15 @@ RSpec.describe Mutations::CustomerRelations::Organizations::Update do .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) } + + 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/issues/set_escalation_status_spec.rb b/spec/graphql/mutations/issues/set_escalation_status_spec.rb new file mode 100644 index 00000000000..d41118b1812 --- /dev/null +++ b/spec/graphql/mutations/issues/set_escalation_status_spec.rb @@ -0,0 +1,66 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Mutations::Issues::SetEscalationStatus do + let_it_be(:user) { create(:user) } + let_it_be(:project) { create(:project) } + let_it_be(:issue, reload: true) { create(:incident, project: project) } + let_it_be(:escalation_status, reload: true) { create(:incident_management_issuable_escalation_status, issue: issue) } + + let(:status) { :acknowledged } + let(:mutation) { described_class.new(object: nil, context: { current_user: user }, field: nil) } + + describe '#resolve' do + let(:args) { { status: status } } + let(:mutated_issue) { result[:issue] } + + subject(:result) { mutation.resolve(project_path: issue.project.full_path, iid: issue.iid, **args) } + + it_behaves_like 'permission level for issue mutation is correctly verified', true + + context 'when the user can update the issue' do + before_all do + project.add_reporter(user) + end + + it_behaves_like 'permission level for issue mutation is correctly verified', true + + context 'when the user can update the escalation status' do + before_all do + project.add_developer(user) + end + + it 'returns the issue with the escalation policy' do + expect(mutated_issue).to eq(issue) + expect(mutated_issue.escalation_status.status_name).to eq(status) + expect(result[:errors]).to be_empty + end + + it 'returns errors when issue update fails' do + issue.update_column(:author_id, nil) + + expect(result[:errors]).not_to be_empty + end + + context 'with non-incident issue is provided' do + let_it_be(:issue) { create(:issue, project: project) } + + it 'raises an error' 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 +end |