Commit 63b06098 authored by Brett Walker's avatar Brett Walker Committed by Alex Kalderimis

Encapsulate checking for GraphQL error

Helps migrate to the new GraphQL interpreter,
https://gitlab.com/gitlab-org/gitlab/-/issues/210556
parent 4074333e
......@@ -30,10 +30,10 @@ RSpec.describe Resolvers::BoardListIssuesResolver do
end
shared_examples 'raises error on mutually exclusive arguments' do
it 'raises an exception if mutually exclusive arguments are present' do
expect do
it 'generates an error if mutually exclusive arguments are present' do
expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ArgumentError) do
resolve_board_list_issues({ filters: filters })
end.to raise_error(Gitlab::Graphql::Errors::ArgumentError)
end
end
end
......
......@@ -115,10 +115,10 @@ RSpec.describe Resolvers::IssuesResolver do
expect(resolve_issues(iteration_wildcard_id: 'NONE')).to contain_exactly(issue2, issue4)
end
it 'raises a mutually exclusive filter error when wildcard and list are provided' do
expect do
it 'generates mutually exclusive filter error when wildcard and list are provided' do
expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ArgumentError, 'only one of [iterationId, iterationWildcardId] arguments is allowed at the same time.') do
resolve_issues(iteration_id: [iteration1.to_global_id], iteration_wildcard_id: 'CURRENT')
end.to raise_error(Gitlab::Graphql::Errors::ArgumentError, 'only one of [iterationId, iterationWildcardId] arguments is allowed at the same time.')
end
end
end
......@@ -182,10 +182,10 @@ RSpec.describe Resolvers::IssuesResolver do
expect(resolve_issues(not: { iteration_id: [iteration1.to_global_id] })).to contain_exactly(issue2, issue3, issue4)
end
it 'raises a mutually exclusive filter error when wildcard and list are provided' do
expect do
it 'generates a mutually exclusive filter error when wildcard and list are provided' do
expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ArgumentError, 'only one of [iterationId, iterationWildcardId] arguments is allowed at the same time.') do
resolve_issues(not: { iteration_id: [iteration1.to_global_id], iteration_wildcard_id: 'CURRENT' })
end.to raise_error(Gitlab::Graphql::Errors::ArgumentError, 'only one of [iterationId, iterationWildcardId] arguments is allowed at the same time.')
end
end
end
......
......@@ -46,7 +46,9 @@ RSpec.describe ::Mutations::Boards::EpicBoards::EpicMoveList do
context 'when user does not have permissions' do
it 'does not allow the move' do
expect { subject }.to raise_error
expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ResourceNotAvailable) do
subject
end
end
end
......
......@@ -20,12 +20,12 @@ RSpec.describe Resolvers::Admin::CloudLicenses::CurrentLicenseResolver do
end
context 'when current user is unauthorized' do
it 'raises error' do
it 'generates an error' do
unauthorized_user = create(:user)
expect do
expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ResourceNotAvailable) do
resolve_current_license(current_user: unauthorized_user)
end.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
end
end
end
......
......@@ -20,12 +20,12 @@ RSpec.describe Resolvers::Admin::CloudLicenses::LicenseHistoryEntriesResolver do
end
context 'when current user is unauthorized' do
it 'raises error' do
it 'generates an error' do
unauthorized_user = create(:user)
expect do
expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ResourceNotAvailable) do
resolve_license_history_entries(current_user: unauthorized_user)
end.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
end
end
end
......
......@@ -40,8 +40,10 @@ RSpec.describe Resolvers::Analytics::DevopsAdoption::EnabledNamespacesResolver d
context 'as a non-admin user' do
let(:current_user) { user }
it 'raises ResourceNotAvailable error' do
expect { resolved_enabled_namespaces }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
it 'generates ResourceNotAvailable error' do
expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ResourceNotAvailable) do
resolved_enabled_namespaces
end
end
end
......@@ -50,8 +52,10 @@ RSpec.describe Resolvers::Analytics::DevopsAdoption::EnabledNamespacesResolver d
stub_licensed_features(instance_level_devops_adoption: false)
end
it 'raises ResourceNotAvailable error' do
expect { resolved_enabled_namespaces }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
it 'generates ResourceNotAvailable error' do
expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ResourceNotAvailable) do
resolved_enabled_namespaces
end
end
end
end
......@@ -75,8 +79,10 @@ RSpec.describe Resolvers::Analytics::DevopsAdoption::EnabledNamespacesResolver d
root_group_1.add_guest(user)
end
it 'raises ResourceNotAvailable error' do
expect { resolved_enabled_namespaces }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
it 'generates ResourceNotAvailable error' do
expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ResourceNotAvailable) do
resolved_enabled_namespaces
end
end
end
......@@ -85,8 +91,10 @@ RSpec.describe Resolvers::Analytics::DevopsAdoption::EnabledNamespacesResolver d
stub_licensed_features(instance_level_devops_adoption: false)
end
it 'raises ResourceNotAvailable error' do
expect { resolved_enabled_namespaces }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
it 'generates ResourceNotAvailable error' do
expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ResourceNotAvailable) do
resolved_enabled_namespaces
end
end
end
end
......
......@@ -93,10 +93,10 @@ RSpec.describe Resolvers::BoardGroupings::EpicsResolver do
resolve_board_epics(group_board, { issue_filters: filters })
end
it 'raises an exception if both epic_id and epic_wildcard_id are present' do
expect do
it 'generates an error if both epic_id and epic_wildcard_id are present' do
expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ArgumentError) do
resolve_board_epics(group_board, { issue_filters: { epic_id: epic1.to_global_id, epic_wildcard_id: 'NONE' } })
end.to raise_error(Gitlab::Graphql::Errors::ArgumentError)
end
end
it 'accepts epic global id' do
......
......@@ -32,8 +32,10 @@ RSpec.describe Resolvers::Boards::EpicBoardsResolver do
stub_licensed_features(epics: true)
end
it 'raises an error if user cannot read epic boards' do
expect { result }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
it 'generates an error if user cannot read epic boards' do
expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ResourceNotAvailable) do
result
end
end
context 'when user is member of the group' do
......
......@@ -25,8 +25,10 @@ RSpec.describe Resolvers::Boards::EpicListsResolver do
stub_licensed_features(epics: true)
end
it 'raises an error if user cannot read epic lists' do
expect { result }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
it 'generates an error if user cannot read epic lists' do
expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ResourceNotAvailable) do
result
end
end
context 'when user is member of the group' do
......
......@@ -156,16 +156,20 @@ RSpec.describe Resolvers::DoraMetricsResolver, time_travel_to: '2021-05-01' do
context 'when the requested date range is too large' do
let(:args) { { metric: 'deployment_frequency', start_date: '2020-01-01'.to_datetime, end_date: '2021-05-01'.to_datetime } }
it 'raises an error' do
expect { resolve_metrics }.to raise_error('Date range must be shorter than 180 days.')
it 'generates an error' do
expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ArgumentError, 'Date range must be shorter than 180 days.') do
resolve_metrics
end
end
end
context 'when the start date equal to or later than the end date' do
let(:args) { { metric: 'deployment_frequency', start_date: '2021-04-01'.to_datetime, end_date: '2021-03-01'.to_datetime } }
it 'raises an error' do
expect { resolve_metrics }.to raise_error('The start date must be ealier than the end date.')
it 'generates an error' do
expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ArgumentError, 'The start date must be ealier than the end date.') do
resolve_metrics
end
end
end
......
......@@ -115,10 +115,12 @@ RSpec.describe Resolvers::EpicsResolver do
end
context 'with in param' do
it 'returns an error if param search is missing' do
it 'generates an error if param search is missing' do
error_message = "`search` should be present when including the `in` argument"
expect { resolve_epics(in: ['title']) }
.to raise_error(Gitlab::Graphql::Errors::ArgumentError, error_message)
expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ArgumentError, error_message) do
resolve_epics(in: ['title'])
end
end
it 'filters epics by description only' do
......
......@@ -92,8 +92,10 @@ RSpec.describe Resolvers::ExternalIssueResolver do
end
end
it 'raises a GraphQL exception' do
expect { batch_sync { resolve_external_issue({}) } }.to raise_error(GraphQL::ExecutionError, 'Jira service not configured.')
it 'generates an error' do
expect_graphql_error_to_be_created(GraphQL::ExecutionError, 'Jira service not configured.') do
batch_sync { resolve_external_issue({}) }
end
end
end
......@@ -104,8 +106,10 @@ RSpec.describe Resolvers::ExternalIssueResolver do
end
end
it 'raises a GraphQL exception' do
expect { batch_sync { resolve_external_issue({}) } }.to raise_error(GraphQL::ExecutionError, 'Jira service unavailable.')
it 'generates an error' do
expect_graphql_error_to_be_created(GraphQL::ExecutionError, 'Jira service unavailable.') do
batch_sync { resolve_external_issue({}) }
end
end
end
......
......@@ -31,8 +31,10 @@ RSpec.describe Resolvers::IncidentManagement::OncallShiftsResolver do
context 'when an error occurs while finding shifts' do
subject(:shifts) { sync(resolve_oncall_shifts(args, current_user: nil)) }
it 'raises ResourceNotAvailable error' do
expect { subject }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
it 'generates a ResourceNotAvailable error' do
expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ResourceNotAvailable) do
subject
end
end
end
......
......@@ -13,10 +13,10 @@ RSpec.describe Resolvers::Iterations::CadencesResolver do
shared_examples 'fetches iteration cadences' do
context 'when user does not have permissions to read iterations cadences' do
it 'raises error' do
expect do
it 'generates an error' do
expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ResourceNotAvailable) do
resolve_group_iteration_cadences
end.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
end
end
end
......@@ -45,12 +45,12 @@ RSpec.describe Resolvers::Iterations::CadencesResolver do
context 'when project does not have a parent group' do
let_it_be(:project) { create(:project, :private) }
it 'raises error' do
it 'generates an error' do
project.add_developer(current_user)
expect do
expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ResourceNotAvailable) do
resolve_group_iteration_cadences({}, project, { current_user: current_user })
end.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
end
end
end
end
......
......@@ -174,10 +174,10 @@ RSpec.describe Resolvers::IterationsResolver do
context 'by timeframe' do
context 'when start_date and end_date are present' do
context 'when start date is after end_date' do
it 'raises error' do
expect do
it 'generates an error' do
expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ArgumentError, 'start must be before end') do
resolve_group_iterations(timeframe: { start: now, end: now - 2.days })
end.to raise_error(Gitlab::Graphql::Errors::ArgumentError, "start must be before end")
end
end
end
end
......@@ -186,38 +186,38 @@ RSpec.describe Resolvers::IterationsResolver do
context 'by dates' do
context 'when start_date and end_date are present' do
context 'when start date is after end_date' do
it 'raises error' do
expect do
it 'generates an error' do
expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ArgumentError, 'startDate is after endDate') do
resolve_group_iterations(start_date: now, end_date: now - 2.days)
end.to raise_error(Gitlab::Graphql::Errors::ArgumentError, "startDate is after endDate")
end
end
end
end
context 'when only start_date is present' do
it 'raises error' do
expect do
it 'generates an error' do
expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ArgumentError, /Both startDate and endDate/) do
resolve_group_iterations(start_date: now)
end.to raise_error(Gitlab::Graphql::Errors::ArgumentError, /Both startDate and endDate/)
end
end
end
context 'when only end_date is present' do
it 'raises error' do
expect do
it 'generates an error' do
expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ArgumentError, /Both startDate and endDate/) do
resolve_group_iterations(end_date: now)
end.to raise_error(Gitlab::Graphql::Errors::ArgumentError, /Both startDate and endDate/)
end
end
end
end
context 'when user cannot read iterations' do
it 'raises error' do
it 'generates an error' do
unauthorized_user = create(:user)
expect do
expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ResourceNotAvailable) do
resolve_group_iterations({}, group, { current_user: unauthorized_user })
end.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
end
end
end
end
......
......@@ -54,8 +54,10 @@ RSpec.describe Resolvers::NetworkPolicyResolver do
stub_licensed_features(threat_monitoring: false)
end
it 'raises ResourceNotAvailable error' do
expect { resolve_network_policies }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
it 'generates a ResourceNotAvailable error' do
expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ResourceNotAvailable) do
resolve_network_policies
end
end
end
......@@ -67,8 +69,10 @@ RSpec.describe Resolvers::NetworkPolicyResolver do
context 'when NetworkPolicies::ResourcesService is not executed successfully' do
let(:service_result) { instance_double(ServiceResponse, success?: false, message: 'Error fetching the result') }
it 'raises Gitlab::Graphql::Errors::BaseError' do
expect { resolve_network_policies }.to raise_error(Gitlab::Graphql::Errors::BaseError, 'Error fetching the result')
it 'generates a Gitlab::Graphql::Errors::BaseError error' do
expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::BaseError, 'Error fetching the result') do
resolve_network_policies
end
end
end
......@@ -123,8 +127,10 @@ RSpec.describe Resolvers::NetworkPolicyResolver do
context 'when user is unauthorized' do
let(:user) { create(:user) }
it 'raises ResourceNotAvailable error' do
expect { resolve_network_policies }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
it 'generates a ResourceNotAvailable error' do
expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ResourceNotAvailable) do
resolve_network_policies
end
end
end
end
......
......@@ -37,7 +37,11 @@ RSpec.describe Resolvers::PathLocksResolver do
context 'user is unauthorized' do
let(:user) { create(:user) }
it { expect { resolve_path_locks }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable) }
it 'generates an error' do
expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ResourceNotAvailable) do
resolve_path_locks
end
end
end
end
end
......
......@@ -70,8 +70,10 @@ RSpec.describe Resolvers::TimeboxReportResolver do
stub_const('TimeboxReportService::EVENT_COUNT_LIMIT', 1)
end
it 'raises a GraphQL exception' do
expect { subject }.to raise_error(GraphQL::ExecutionError, 'Burnup chart could not be generated due to too many events')
it 'generates a GraphQL error' do
expect_graphql_error_to_be_created(GraphQL::ExecutionError, 'Burnup chart could not be generated due to too many events') do
subject
end
end
end
end
......
......@@ -48,8 +48,10 @@ RSpec.describe Resolvers::UserDiscussionsCountResolver do
context 'when a user does not have permission to view discussions' do
subject { batch_sync { resolve_user_discussions_count(private_epic) } }
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
end
......
......@@ -49,8 +49,10 @@ RSpec.describe Resolvers::UserNotesCountResolver do
context 'when a user does not have permission to view notes' do
subject { batch_sync { resolve_user_notes_count(private_epic) } }
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
end
......
......@@ -15,19 +15,31 @@ RSpec.describe Resolvers::Vulnerabilities::IssueLinksResolver do
context 'when the filter is a string' do
let(:filters) { { link_type: 'some string' } }
it { expect { subject }.to raise_error(Gitlab::Graphql::Errors::ArgumentError, 'Provide a valid vulnerability issue link type') }
it 'generates an error' do
expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ArgumentError, 'Provide a valid vulnerability issue link type') do
subject
end
end
end
context 'when the filter is a number' do
let(:filters) { { link_type: 99 } }
it { expect { subject }.to raise_error(Gitlab::Graphql::Errors::ArgumentError), 'Provide a valid vulnerability issue link type' }
it 'generates an error' do
expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ArgumentError, 'Provide a valid vulnerability issue link type') do
subject
end
end
end
context 'when the filter is a symbol' do
let(:filters) { { link_type: :CREATED } }
it { expect { subject }.to raise_error(Gitlab::Graphql::Errors::ArgumentError), 'Provide a valid vulnerability issue link type' }
it 'generates an error' do
expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ArgumentError, 'Provide a valid vulnerability issue link type') do
subject
end
end
end
end
end
......
......@@ -25,10 +25,10 @@ RSpec.describe Resolvers::BoardListIssuesResolver do
let(:wildcard_started) { 'STARTED' }
let(:filters) { { milestone_title: ["started"], milestone_wildcard_id: wildcard_started } }
it 'raises a mutually exclusive filter error when milestone wildcard and title are provided' do
expect do
it 'generates a mutually exclusive filter error when milestone wildcard and title are provided' do
expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ArgumentError) do
resolve_board_list_issues(args: { filters: filters })
end.to raise_error(Gitlab::Graphql::Errors::ArgumentError)
end
end
it 'returns the issues in the correct order' do
......
......@@ -26,8 +26,10 @@ RSpec.describe Resolvers::DesignManagement::VersionInCollectionResolver do
subject(:result) { resolve_version(issue.design_collection) }
context 'Neither id nor sha is passed as parameters' do
it 'raises an appropriate error' do
expect { result }.to raise_error(appropriate_error)
it 'generates an appropriate error' do
expect_graphql_error_to_be_created(appropriate_error) do
result
end
end
end
......
......@@ -22,8 +22,10 @@ RSpec.describe Resolvers::DesignManagement::VersionResolver do
context 'the current user is not authorized' do
let(:current_user) { create(:user) }
it 'raises an error on resolution' do
expect { resolve_version }.to raise_error(::Gitlab::Graphql::Errors::ResourceNotAvailable)
it 'generates an error on resolution' do
expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ResourceNotAvailable) do
resolve_version
end
end
end
......
......@@ -98,8 +98,10 @@ RSpec.describe Resolvers::DesignManagement::VersionsResolver do
}
end
it 'raises a suitable error' do
expect { result }.to raise_error(GraphQL::ExecutionError)
it 'generates a suitable error' do
expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ResourceNotAvailable) do
result
end
end
end
end
......
......@@ -86,10 +86,10 @@ RSpec.describe Resolvers::GroupIssuesResolver do
end
context 'release_tag filter' do
it 'returns an error when trying to filter by negated release_tag' do
expect do
it 'generates an error when trying to filter by negated release_tag' do
expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ArgumentError, 'releaseTag filter is not allowed when parent is a group.') do
resolve_issues(not: { release_tag: ['v1.0'] })
end.to raise_error(Gitlab::Graphql::Errors::ArgumentError, 'releaseTag filter is not allowed when parent is a group.')
end
end
end
end
......
......@@ -70,10 +70,10 @@ RSpec.describe Resolvers::IssueStatusCountsResolver do
end
context 'when both assignee_username and assignee_usernames are provided' do
it 'raises a mutually exclusive filter error' do
expect do
it 'generates a mutually exclusive filter error' do
expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ArgumentError, 'only one of [assigneeUsernames, assigneeUsername] arguments is allowed at the same time.') do
resolve_issue_status_counts(assignee_usernames: [current_user.username], assignee_username: current_user.username)
end.to raise_error(Gitlab::Graphql::Errors::ArgumentError, 'only one of [assigneeUsernames, assigneeUsername] arguments is allowed at the same time.')
end
end
end
......
......@@ -78,10 +78,10 @@ RSpec.describe Resolvers::IssuesResolver do
expect(resolve_issues(milestone_wildcard_id: wildcard_none)).to contain_exactly(issue2)
end
it 'raises a mutually exclusive filter error when wildcard and title are provided' do
expect do
it 'generates a mutually exclusive filter error when wildcard and title are provided' do
expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ArgumentError, 'only one of [milestoneTitle, milestoneWildcardId] arguments is allowed at the same time.') do
resolve_issues(milestone_title: ["started milestone"], milestone_wildcard_id: wildcard_started)
end.to raise_error(Gitlab::Graphql::Errors::ArgumentError, 'only one of [milestoneTitle, milestoneWildcardId] arguments is allowed at the same time.')
end
end
context 'negated filtering' do
......@@ -97,10 +97,10 @@ RSpec.describe Resolvers::IssuesResolver do
expect(resolve_issues(not: { milestone_wildcard_id: wildcard_upcoming })).to contain_exactly(issue6)
end
it 'raises a mutually exclusive filter error when wildcard and title are provided as negated filters' do
expect do
it 'generates a mutually exclusive filter error when wildcard and title are provided as negated filters' do
expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ArgumentError, 'only one of [milestoneTitle, milestoneWildcardId] arguments is allowed at the same time.') do
resolve_issues(not: { milestone_title: ["started milestone"], milestone_wildcard_id: wildcard_started })
end.to raise_error(Gitlab::Graphql::Errors::ArgumentError, 'only one of [milestoneTitle, milestoneWildcardId] arguments is allowed at the same time.')
end
end
end
end
......@@ -122,10 +122,10 @@ RSpec.describe Resolvers::IssuesResolver do
end
context 'when release_tag_wildcard_id is also provided' do
it 'raises a mutually eclusive argument error' do
expect do
it 'generates a mutually eclusive argument error' do
expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ArgumentError, 'only one of [releaseTag, releaseTagWildcardId] arguments is allowed at the same time.') do
resolve_issues(release_tag: [release1.tag], release_tag_wildcard_id: 'ANY')
end.to raise_error(Gitlab::Graphql::Errors::ArgumentError, 'only one of [releaseTag, releaseTagWildcardId] arguments is allowed at the same time.')
end
end
end
end
......@@ -191,10 +191,10 @@ RSpec.describe Resolvers::IssuesResolver do
end
context 'when both assignee_username and assignee_usernames are provided' do
it 'raises a mutually exclusive filter error' do
expect do
it 'generates a mutually exclusive filter error' do
expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ArgumentError, 'only one of [assigneeUsernames, assigneeUsername] arguments is allowed at the same time.') do
resolve_issues(assignee_usernames: [assignee.username], assignee_username: assignee.username)
end.to raise_error(Gitlab::Graphql::Errors::ArgumentError, 'only one of [assigneeUsernames, assigneeUsername] arguments is allowed at the same time.')
end
end
end
end
......@@ -331,11 +331,12 @@ RSpec.describe Resolvers::IssuesResolver do
stub_feature_flags(disable_anonymous_search: true)
end
it 'returns an error' do
it 'generates an error' do
error_message = "User must be authenticated to include the `search` argument."
expect { resolve(described_class, obj: public_project, args: { search: 'test' }, ctx: { current_user: nil }) }
.to raise_error(Gitlab::Graphql::Errors::ArgumentError, error_message)
expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ArgumentError, error_message) do
resolve(described_class, obj: public_project, args: { search: 'test' }, ctx: { current_user: nil })
end
end
end
......
......@@ -34,8 +34,10 @@ RSpec.describe Resolvers::Kas::AgentConfigurationsResolver do
allow(kas_client).to receive(:list_agent_config_files).and_raise(GRPC::DeadlineExceeded)
end
it 'raises a graphql error' do
expect { subject }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable, 'GRPC::DeadlineExceeded')
it 'generates a graphql error' do
expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ResourceNotAvailable, 'GRPC::DeadlineExceeded') do
subject
end
end
end
......
......@@ -28,7 +28,9 @@ RSpec.describe Resolvers::LabelsResolver do
describe '#resolve' do
context 'with unauthorized user' do
it 'returns no labels' do
expect { resolve_labels(project) }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ResourceNotAvailable) do
resolve_labels(project)
end
end
end
......
......@@ -25,32 +25,40 @@ RSpec.describe Resolvers::PackagePipelinesResolver do
context 'with invalid after' do
let(:args) { { first: 1, after: 'not_json_string' } }
it 'raises argument error' do
expect { subject }.to raise_error(Gitlab::Graphql::Errors::ArgumentError)
it 'generates an argument error' do
expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ArgumentError) do
subject
end
end
end
context 'with invalid after key' do
let(:args) { { first: 1, after: encode_cursor(foo: 3) } }
it 'raises argument error' do
expect { subject }.to raise_error(Gitlab::Graphql::Errors::ArgumentError)
it 'generates an argument error' do
expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ArgumentError) do
subject
end
end
end
context 'with invalid before' do
let(:args) { { last: 1, before: 'not_json_string' } }
it 'raises argument error' do
expect { subject }.to raise_error(Gitlab::Graphql::Errors::ArgumentError)
it 'generates an argument error' do
expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ArgumentError) do
subject
end
end
end
context 'with invalid before key' do
let(:args) { { last: 1, before: encode_cursor(foo: 3) } }
it 'raises argument error' do
expect { subject }.to raise_error(Gitlab::Graphql::Errors::ArgumentError)
it 'generates an argument error' do
expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ArgumentError) do
subject
end
end
end
......
......@@ -65,7 +65,11 @@ RSpec.describe Resolvers::PaginatedTreeResolver do
context 'when cursor is invalid' do
let(:args) { super().merge(after: 'invalid') }
it { expect { subject }.to raise_error(Gitlab::Graphql::Errors::ArgumentError) }
it 'generates an error' do
expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ArgumentError) do
subject
end
end
end
it 'returns all tree entries during cursor pagination' do
......
......@@ -103,27 +103,27 @@ RSpec.describe Resolvers::ProjectMilestonesResolver do
end
context 'when start date is after end_date' do
it 'raises error' do
expect do
it 'generates an error' do
expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ArgumentError, 'startDate is after endDate') do
resolve_project_milestones(start_date: Time.now, end_date: Time.now - 2.days)
end.to raise_error(Gitlab::Graphql::Errors::ArgumentError, "startDate is after endDate")
end
end
end
end
context 'when only start_date is present' do
it 'raises error' do
expect do
it 'generates an error' do
expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ArgumentError, /Both startDate and endDate/) do
resolve_project_milestones(start_date: Time.now)
end.to raise_error(Gitlab::Graphql::Errors::ArgumentError, /Both startDate and endDate/)
end
end
end
context 'when only end_date is present' do
it 'raises error' do
expect do
it 'generates an error' do
expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ArgumentError, /Both startDate and endDate/) do
resolve_project_milestones(end_date: Time.now)
end.to raise_error(Gitlab::Graphql::Errors::ArgumentError, /Both startDate and endDate/)
end
end
end
......@@ -174,12 +174,12 @@ RSpec.describe Resolvers::ProjectMilestonesResolver do
end
context 'when user cannot read milestones' do
it 'raises error' do
it 'generates an error' do
unauthorized_user = create(:user)
expect do
expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ResourceNotAvailable) do
resolve_project_milestones({}, { current_user: unauthorized_user })
end.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
end
end
end
end
......
......@@ -85,13 +85,15 @@ RSpec.describe Resolvers::ProjectPipelineResolver do
end
it 'errors when no iid or sha is passed' do
expect { resolve_pipeline(project, {}) }
.to raise_error(Gitlab::Graphql::Errors::ArgumentError)
expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ArgumentError) do
resolve_pipeline(project, {})
end
end
it 'errors when both iid and sha are passed' do
expect { resolve_pipeline(project, { iid: '1234', sha: 'sha' }) }
.to raise_error(Gitlab::Graphql::Errors::ArgumentError)
expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ArgumentError) do
resolve_pipeline(project, { iid: '1234', sha: 'sha' })
end
end
context 'when the pipeline is a dangling pipeline' do
......
......@@ -14,10 +14,10 @@ RSpec.describe Resolvers::Projects::JiraProjectsResolver do
let_it_be(:project) { create(:project) }
shared_examples 'no project service access' do
it 'raises error' do
expect do
it 'generates an error' do
expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ResourceNotAvailable) do
resolve_jira_projects
end.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
end
end
end
......@@ -89,11 +89,14 @@ RSpec.describe Resolvers::Projects::JiraProjectsResolver do
.to_raise(JIRA::HTTPError.new(double(message: '{"errorMessages":["Some failure"]}')))
end
it 'raises failure error' do
it 'generates a failure error' do
config_docs_link_url = Rails.application.routes.url_helpers.help_page_path('integration/jira/configure')
docs_link_start = '<a href="%{url}" target="_blank" rel="noopener noreferrer">'.html_safe % { url: config_docs_link_url }
error_message = 'An error occurred while requesting data from Jira: Some failure. Check your %{docs_link_start}Jira integration configuration</a> and try again.' % { docs_link_start: docs_link_start }
expect { resolve_jira_projects }.to raise_error(error_message)
expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::BaseError, error_message) do
resolve_jira_projects
end
end
end
end
......
......@@ -85,27 +85,30 @@ RSpec.describe Resolvers::TimelogResolver do
context 'when start_time and start_date are present' do
let(:args) { { start_time: 6.days.ago, start_date: 6.days.ago } }
it 'returns correct error' do
expect { timelogs }
.to raise_error(error_class, /Provide either a start date or time, but not both/)
it 'generates an error' do
expect_graphql_error_to_be_created(error_class, /Provide either a start date or time, but not both/) do
timelogs
end
end
end
context 'when end_time and end_date are present' do
let(:args) { { end_time: 2.days.ago, end_date: 2.days.ago } }
it 'returns correct error' do
expect { timelogs }
.to raise_error(error_class, /Provide either an end date or time, but not both/)
it 'generates an error' do
expect_graphql_error_to_be_created(error_class, /Provide either an end date or time, but not both/) do
timelogs
end
end
end
context 'when start argument is after end argument' do
let(:args) { { start_time: 2.days.ago, end_time: 6.days.ago } }
it 'returns correct error' do
expect { timelogs }
.to raise_error(error_class, /Start argument must be before End argument/)
it 'generates an error' do
expect_graphql_error_to_be_created(error_class, /Start argument must be before End argument/) do
timelogs
end
end
end
end
......@@ -276,9 +279,10 @@ RSpec.describe Resolvers::TimelogResolver do
let(:args) { {} }
let(:extra_args) { {} }
it 'returns correct error' do
expect { timelogs }
.to raise_error(error_class, /Provide at least one argument/)
it 'generates an error' do
expect_graphql_error_to_be_created(error_class, /Provide at least one argument/) do
timelogs
end
end
end
......
......@@ -76,8 +76,10 @@ RSpec.shared_examples 'querying members with a group' do
resolve(described_class, obj: resource, args: base_args.merge(args), ctx: { current_user: other_user })
end
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
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