summaryrefslogtreecommitdiff
path: root/spec/graphql/mutations
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-03-18 20:02:30 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2022-03-18 20:02:30 +0000
commit41fe97390ceddf945f3d967b8fdb3de4c66b7dea (patch)
tree9c8d89a8624828992f06d892cd2f43818ff5dcc8 /spec/graphql/mutations
parent0804d2dc31052fb45a1efecedc8e06ce9bc32862 (diff)
downloadgitlab-ce-41fe97390ceddf945f3d967b8fdb3de4c66b7dea.tar.gz
Add latest changes from gitlab-org/gitlab@14-9-stable-eev14.9.0-rc42
Diffstat (limited to 'spec/graphql/mutations')
-rw-r--r--spec/graphql/mutations/boards/issues/issue_move_list_spec.rb18
-rw-r--r--spec/graphql/mutations/ci/runner/delete_spec.rb72
-rw-r--r--spec/graphql/mutations/ci/runner/update_spec.rb6
-rw-r--r--spec/graphql/mutations/release_asset_links/create_spec.rb16
-rw-r--r--spec/graphql/mutations/saved_replies/create_spec.rb46
-rw-r--r--spec/graphql/mutations/saved_replies/update_spec.rb47
6 files changed, 170 insertions, 35 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 dd9305d2197..11c0fa44110 100644
--- a/spec/graphql/mutations/boards/issues/issue_move_list_spec.rb
+++ b/spec/graphql/mutations/boards/issues/issue_move_list_spec.rb
@@ -43,11 +43,10 @@ RSpec.describe Mutations::Boards::Issues::IssueMoveList do
context "when we only pass #{arg_name}" do
let(:move_params) { { arg_name => list1.id } }
- it 'raises an error' do
- expect { subject }.to raise_error(
- Gitlab::Graphql::Errors::ArgumentError,
- 'Both fromListId and toListId must be present'
- )
+ it 'generates an error' do
+ expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ArgumentError, 'Both fromListId and toListId must be present') do
+ subject
+ end
end
end
end
@@ -55,11 +54,10 @@ RSpec.describe Mutations::Boards::Issues::IssueMoveList do
context 'when required arguments are missing' do
let(:move_params) { {} }
- it 'raises an error' do
- expect { subject }.to raise_error(
- Gitlab::Graphql::Errors::ArgumentError,
- "At least one of the arguments fromListId, toListId, afterId or beforeId is required"
- )
+ it 'generates an error' do
+ expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ArgumentError, 'At least one of the arguments fromListId, toListId, afterId or beforeId is required') do
+ subject
+ end
end
end
diff --git a/spec/graphql/mutations/ci/runner/delete_spec.rb b/spec/graphql/mutations/ci/runner/delete_spec.rb
index b53ee30f826..c0f979e43cc 100644
--- a/spec/graphql/mutations/ci/runner/delete_spec.rb
+++ b/spec/graphql/mutations/ci/runner/delete_spec.rb
@@ -6,8 +6,9 @@ RSpec.describe Mutations::Ci::Runner::Delete do
include GraphqlHelpers
let_it_be(:runner) { create(:ci_runner) }
+ let_it_be(:admin_user) { create(:user, :admin) }
+ let_it_be(:user) { create(:user) }
- let(:user) { create(:user) }
let(:current_ctx) { { current_user: user } }
let(:mutation_params) do
@@ -22,15 +23,29 @@ RSpec.describe Mutations::Ci::Runner::Delete do
end
context 'when the user cannot admin the runner' do
- it 'raises an error' do
- expect { subject }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
+ it 'generates an error' do
+ expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ResourceNotAvailable) do
+ subject
+ end
+ end
+
+ context 'with more than one associated project' do
+ let!(:project) { create(:project, creator_id: user.id) }
+ let!(:project2) { create(:project, creator_id: user.id) }
+ let!(:two_projects_runner) { create(:ci_runner, :project, description: 'Two projects runner', projects: [project, project2]) }
+
+ it 'raises an error' do
+ mutation_params[:id] = two_projects_runner.to_global_id
+
+ expect { subject }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
+ end
end
end
context 'with invalid params' do
- it 'raises an error' do
- mutation_params[:id] = "invalid-id"
+ let(:mutation_params) { { id: "invalid-id" } }
+ it 'raises an error' do
expect { subject }.to raise_error(::GraphQL::CoercionError)
end
end
@@ -44,6 +59,8 @@ RSpec.describe Mutations::Ci::Runner::Delete do
end
context 'when user can delete owned runner' do
+ let_it_be(:user) { create(:user) }
+
let!(:project) { create(:project, creator_id: user.id) }
let!(:project_runner) { create(:ci_runner, :project, description: 'Project runner', projects: [project]) }
@@ -52,10 +69,12 @@ RSpec.describe Mutations::Ci::Runner::Delete do
end
context 'with one associated project' do
- it 'deletes runner' do
- mutation_params[:id] = project_runner.to_global_id
+ let(:mutation_params) do
+ { id: project_runner.to_global_id }
+ end
- expect_next_instance_of(::Ci::UnregisterRunnerService, project_runner) do |service|
+ it 'deletes runner' do
+ expect_next_instance_of(::Ci::Runners::UnregisterRunnerService, project_runner, current_ctx[:current_user]) do |service|
expect(service).to receive(:execute).once.and_call_original
end
@@ -68,28 +87,45 @@ RSpec.describe Mutations::Ci::Runner::Delete do
let!(:project2) { create(:project, creator_id: user.id) }
let!(:two_projects_runner) { create(:ci_runner, :project, description: 'Two projects runner', projects: [project, project2]) }
- before do
- project2.add_maintainer(user)
+ let(:mutation_params) do
+ { id: two_projects_runner.to_global_id }
end
- it 'does not delete project runner' do
- mutation_params[:id] = two_projects_runner.to_global_id
+ context 'with user as admin', :enable_admin_mode do
+ let(:current_ctx) { { current_user: admin_user } }
+
+ it 'deletes runner' do
+ expect_next_instance_of(::Ci::Runners::UnregisterRunnerService, two_projects_runner, current_ctx[:current_user]) do |service|
+ expect(service).to receive(:execute).once.and_call_original
+ end
+
+ expect { subject }.to change { Ci::Runner.count }.by(-1)
+ expect(subject[:errors]).to be_empty
+ end
+ end
+
+ context 'with user as project maintainer' do
+ let_it_be(:user) { create(:user) }
+
+ before do
+ project2.add_maintainer(user)
+ end
- allow_next_instance_of(::Ci::UnregisterRunnerService) do |service|
- expect(service).not_to receive(:execute).once
+ it 'raises error' do
+ allow_next_instance_of(::Ci::Runners::UnregisterRunnerService) do |service|
+ expect(service).not_to receive(:execute)
+ end
+ expect { subject }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
end
- expect { subject }.not_to change { Ci::Runner.count }
- expect(subject[:errors]).to contain_exactly("Runner #{two_projects_runner.to_global_id} associated with more than one project")
end
end
end
context 'when admin can delete runner', :enable_admin_mode do
- let(:admin_user) { create(:user, :admin) }
let(:current_ctx) { { current_user: admin_user } }
it 'deletes runner' do
- expect_next_instance_of(::Ci::UnregisterRunnerService, runner) do |service|
+ expect_next_instance_of(::Ci::Runners::UnregisterRunnerService, runner, current_ctx[:current_user]) do |service|
expect(service).to receive(:execute).once.and_call_original
end
diff --git a/spec/graphql/mutations/ci/runner/update_spec.rb b/spec/graphql/mutations/ci/runner/update_spec.rb
index 83150c3d7f6..0b3489d37dc 100644
--- a/spec/graphql/mutations/ci/runner/update_spec.rb
+++ b/spec/graphql/mutations/ci/runner/update_spec.rb
@@ -26,8 +26,10 @@ RSpec.describe Mutations::Ci::Runner::Update do
end
context 'when the user cannot admin the runner' do
- it 'raises an error' do
- expect { subject }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
+ it 'generates an error' do
+ expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ResourceNotAvailable) do
+ subject
+ 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 eb7cbb4b789..86a6c77fa3f 100644
--- a/spec/graphql/mutations/release_asset_links/create_spec.rb
+++ b/spec/graphql/mutations/release_asset_links/create_spec.rb
@@ -63,7 +63,9 @@ RSpec.describe Mutations::ReleaseAssetLinks::Create do
let!(:protected_tag) { create(:protected_tag, :maintainers_can_create, name: '*', project: project) }
it 'has an access error' do
- expect { subject }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
+ expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ResourceNotAvailable) do
+ subject
+ end
end
end
end
@@ -71,16 +73,20 @@ RSpec.describe Mutations::ReleaseAssetLinks::Create do
context "when the user doesn't have access to the project" do
let(:current_user) { reporter }
- it 'raises an error' do
- expect { subject }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
+ it 'generates an error' do
+ expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ResourceNotAvailable) do
+ subject
+ end
end
end
context "when the project doesn't exist" do
let(:project_path) { 'project/that/does/not/exist' }
- it 'raises an error' do
- expect { subject }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
+ it 'generates an error' do
+ expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ResourceNotAvailable) do
+ subject
+ end
end
end
diff --git a/spec/graphql/mutations/saved_replies/create_spec.rb b/spec/graphql/mutations/saved_replies/create_spec.rb
new file mode 100644
index 00000000000..5141c537b06
--- /dev/null
+++ b/spec/graphql/mutations/saved_replies/create_spec.rb
@@ -0,0 +1,46 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Mutations::SavedReplies::Create do
+ let_it_be(:current_user) { create(:user) }
+
+ let(:mutation) { described_class.new(object: nil, context: { current_user: current_user }, field: nil) }
+
+ let(:mutation_arguments) { { name: 'save_reply_name', content: 'Save Reply Content' } }
+
+ describe '#resolve' do
+ subject(:resolve) do
+ mutation.resolve(**mutation_arguments)
+ end
+
+ context 'when feature is disabled' do
+ before do
+ stub_feature_flags(saved_replies: false)
+ end
+
+ it 'raises Gitlab::Graphql::Errors::ResourceNotAvailable' do
+ expect { subject }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable, 'Feature disabled')
+ end
+ end
+
+ context 'when feature is enabled for current user' do
+ before do
+ stub_feature_flags(saved_replies: current_user)
+ end
+
+ context 'when service fails to create a new saved reply' do
+ let(:mutation_arguments) { { name: '', content: '' } }
+
+ it { expect(subject[:saved_reply]).to be_nil }
+ it { expect(subject[:errors]).to match_array(["Content can't be blank", "Name can't be blank", "Name can contain only lowercase letters, digits, '_' and '-'. Must start with a letter, and cannot end with '-' or '_'"]) }
+ end
+
+ context 'when service successfully creates a new saved reply' do
+ it { expect(subject[:saved_reply].name).to eq(mutation_arguments[:name]) }
+ it { expect(subject[:saved_reply].content).to eq(mutation_arguments[:content]) }
+ it { expect(subject[:errors]).to be_empty }
+ end
+ end
+ end
+end
diff --git a/spec/graphql/mutations/saved_replies/update_spec.rb b/spec/graphql/mutations/saved_replies/update_spec.rb
new file mode 100644
index 00000000000..67c2d1348f7
--- /dev/null
+++ b/spec/graphql/mutations/saved_replies/update_spec.rb
@@ -0,0 +1,47 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Mutations::SavedReplies::Update do
+ let_it_be(:current_user) { create(:user) }
+ let_it_be(:saved_reply) { create(:saved_reply, user: current_user) }
+
+ let(:mutation) { described_class.new(object: nil, context: { current_user: current_user }, field: nil) }
+
+ let(:mutation_arguments) { { name: 'save_reply_name', content: 'Save Reply Content' } }
+
+ describe '#resolve' do
+ subject(:resolve) do
+ mutation.resolve(id: saved_reply.to_global_id, **mutation_arguments)
+ end
+
+ context 'when feature is disabled' do
+ before do
+ stub_feature_flags(saved_replies: false)
+ end
+
+ it 'raises Gitlab::Graphql::Errors::ResourceNotAvailable' do
+ expect { subject }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable, 'Feature disabled')
+ end
+ end
+
+ context 'when feature is enabled for current user' do
+ before do
+ stub_feature_flags(saved_replies: current_user)
+ end
+
+ context 'when service fails to update a new saved reply' do
+ let(:mutation_arguments) { { name: '', content: '' } }
+
+ it { expect(subject[:saved_reply]).to be_nil }
+ it { expect(subject[:errors]).to match_array(["Content can't be blank", "Name can't be blank", "Name can contain only lowercase letters, digits, '_' and '-'. Must start with a letter, and cannot end with '-' or '_'"]) }
+ end
+
+ context 'when service successfully updates the saved reply' do
+ it { expect(subject[:saved_reply].name).to eq(mutation_arguments[:name]) }
+ it { expect(subject[:saved_reply].content).to eq(mutation_arguments[:content]) }
+ it { expect(subject[:errors]).to be_empty }
+ end
+ end
+ end
+end