Commit a5147079 authored by Pavel Shutsin's avatar Pavel Shutsin

Merge branch 'bw-graphql-encapsulate-error-expects-4' into 'master'

Encapsulate checking for GraphQL error

See merge request gitlab-org/gitlab!84095
parents 6512f6c5 7a2a06a0
......@@ -18,9 +18,9 @@ RSpec.describe Resolvers::Admin::CloudLicenses::SubscriptionFutureEntriesResolve
it 'raises error' do
unauthorized_user = create(:user)
expect do
expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ResourceNotAvailable) do
resolve_entries(current_user: unauthorized_user)
end.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
end
end
end
......
......@@ -158,8 +158,9 @@ RSpec.describe Resolvers::EpicsResolver do
it 'returns an error' do
error_message = "User must be authenticated to include the `search` argument."
expect { resolve_epics(search: 'created') }
.to raise_error(Gitlab::Graphql::Errors::ArgumentError, error_message)
expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ArgumentError, error_message) do
resolve_epics(search: 'created')
end
end
end
......
......@@ -90,9 +90,9 @@ RSpec.describe Resolvers::IterationsResolver do
{ in: [:cadence_title] }
].each do |params|
it "raises an error when 'title' is used with #{params}" do
expect do
expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ArgumentError, "'title' is deprecated in favor of 'search'. Please use 'search'.") do
resolve_group_iterations({ title: "foo", **params })
end.to raise_error(Gitlab::Graphql::Errors::ArgumentError, "'title' is deprecated in favor of 'search'. Please use 'search'.")
end
end
end
......
......@@ -86,7 +86,9 @@ RSpec.describe Resolvers::TimeboxReportResolver do
let(:current_user) { group_member }
it 'raises a GraphQL exception' do
expect { subject }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable, "The resource that you are attempting to access does not exist or you don't have permission to perform this action")
expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ResourceNotAvailable, "The resource that you are attempting to access does not exist or you don't have permission to perform this action") do
subject
end
end
end
......@@ -110,7 +112,9 @@ RSpec.describe Resolvers::TimeboxReportResolver do
with_them do
it 'raises a GraphQL exception' do
expect { subject }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable, "The resource that you are attempting to access does not exist or you don't have permission to perform this action")
expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ResourceNotAvailable, "The resource that you are attempting to access does not exist or you don't have permission to perform this action") do
subject
end
end
end
end
......
......@@ -21,7 +21,9 @@ RSpec.shared_examples 'as an orchestration policy' do
end
it 'raises ResourceNotAvailable error' do
expect { resolve_scan_policies }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ResourceNotAvailable) do
resolve_scan_policies
end
end
end
......@@ -38,7 +40,9 @@ RSpec.shared_examples 'as an orchestration policy' do
let(:user) { create(:user) }
it 'raises ResourceNotAvailable error' do
expect { resolve_scan_policies }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ResourceNotAvailable) do
resolve_scan_policies
end
end
end
end
......
......@@ -37,7 +37,9 @@ RSpec.describe Mutations::Ci::Runner::Delete do
it 'raises an error' do
mutation_params[:id] = two_projects_runner.to_global_id
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
......@@ -115,7 +117,10 @@ RSpec.describe Mutations::Ci::Runner::Delete 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)
expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ResourceNotAvailable) do
subject
end
end
end
end
......
......@@ -75,10 +75,9 @@ RSpec.describe Resolvers::BlobsResolver do
let(:ref) { 'ma:in' }
it 'raises an ArgumentError' do
expect { resolve_blobs }.to raise_error(
Gitlab::Graphql::Errors::ArgumentError,
'Ref is not valid'
)
expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ArgumentError, 'Ref is not valid') do
resolve_blobs
end
end
end
......@@ -86,10 +85,9 @@ RSpec.describe Resolvers::BlobsResolver do
let(:ref) { '' }
it 'raises an ArgumentError' do
expect { resolve_blobs }.to raise_error(
Gitlab::Graphql::Errors::ArgumentError,
'Ref is not valid'
)
expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ArgumentError, 'Ref is not valid') do
resolve_blobs
end
end
end
end
......
......@@ -35,7 +35,9 @@ RSpec.describe Resolvers::GroupMembers::NotificationEmailResolver do
let(:current_user) { create(:user) }
it 'raises ResourceNotAvailable 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
......
......@@ -74,7 +74,9 @@ RSpec.describe Resolvers::UsersResolver do
let_it_be(:current_user) { nil }
it 'prohibits search without usernames passed' do
expect { resolve_users }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ResourceNotAvailable) do
resolve_users
end
end
it 'allows to search by username' do
......
......@@ -22,7 +22,9 @@ RSpec.describe Resolvers::WorkItemResolver do
let(:current_user) { create(:user) }
it 'raises a resource not available error' do
expect { resolved_work_item }.to raise_error(::Gitlab::Graphql::Errors::ResourceNotAvailable)
expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ResourceNotAvailable) do
resolved_work_item
end
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment