Skip to content
Snippets Groups Projects
Commit e207f4ad authored by Brett Walker's avatar Brett Walker
Browse files

Fix specs checking for an error to be raised

now those exceptions are being returned in GraphQL,
not raised
parent 18fce204
No related branches found
No related tags found
No related merge requests found
Pipeline #348717749 failed
Pipeline: GitLab

#348717817

    Showing
    with 100 additions and 89 deletions
    ......@@ -3,7 +3,7 @@
    module Types
    # rubocop: disable Graphql/AuthorizeTypes
    class QueryComplexityType < ::Types::BaseObject
    ANALYZER = GraphQL::Analysis::QueryComplexity.new { |_query, complexity| complexity }
    ANALYZER = GraphQL::Analysis::AST::QueryComplexity
    graphql_name 'QueryComplexity'
    ......@@ -23,7 +23,7 @@ class QueryComplexityType < ::Types::BaseObject
    description: 'GraphQL query complexity score.'
    def score
    ::GraphQL::Analysis.analyze_query(query, [ANALYZER]).first
    ::GraphQL::Analysis::AST.analyze_query(query, [ANALYZER]).first
    end
    end
    # rubocop: enable Graphql/AuthorizeTypes
    ......
    ......@@ -28,10 +28,9 @@
    end
    shared_examples 'raises error on mutually exclusive arguments' do
    it 'raises an exception if mutually exclusive arguments are present' do
    expect do
    resolve_board_list_issues({ filters: filters })
    end.to raise_error(Gitlab::Graphql::Errors::ArgumentError)
    it 'returns an error if mutually exclusive arguments are present' do
    expect(resolve_board_list_issues({ filters: filters }))
    .to be_instance_of(Gitlab::Graphql::Errors::ArgumentError)
    end
    end
    ......
    ......@@ -115,10 +115,11 @@
    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
    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.')
    it 'returns a mutually exclusive filter error when wildcard and list are provided' do
    result = resolve_issues(iteration_id: [iteration1.to_global_id], iteration_wildcard_id: 'CURRENT')
    expect(result).to be_instance_of(Gitlab::Graphql::Errors::ArgumentError)
    expect(result.message).to eq('only one of [iterationId, iterationWildcardId] arguments is allowed at the same time.')
    end
    end
    ......@@ -178,10 +179,11 @@
    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
    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.')
    it 'returns a mutually exclusive filter error when wildcard and list are provided' do
    result = resolve_issues(not: { iteration_id: [iteration1.to_global_id], iteration_wildcard_id: 'CURRENT' })
    expect(result).to be_instance_of(Gitlab::Graphql::Errors::ArgumentError)
    expect(result.message).to eq('only one of [iterationId, iterationWildcardId] arguments is allowed at the same time.')
    end
    end
    ......
    ......@@ -46,7 +46,7 @@
    context 'when user does not have permissions' do
    it 'does not allow the move' do
    expect { subject }.to raise_error
    expect(subject).to be_instance_of(Gitlab::Graphql::Errors::ResourceNotAvailable)
    end
    end
    ......
    ......@@ -20,12 +20,11 @@ def resolve_current_license(current_user: admin)
    end
    context 'when current user is unauthorized' do
    it 'raises error' do
    it 'returns an error' do
    unauthorized_user = create(:user)
    expect do
    resolve_current_license(current_user: unauthorized_user)
    end.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
    expect(resolve_current_license(current_user: unauthorized_user))
    .to be_instance_of(Gitlab::Graphql::Errors::ResourceNotAvailable)
    end
    end
    ......
    ......@@ -20,12 +20,11 @@ def resolve_license_history_entries(current_user: admin)
    end
    context 'when current user is unauthorized' do
    it 'raises error' do
    it 'returns an error' do
    unauthorized_user = create(:user)
    expect do
    resolve_license_history_entries(current_user: unauthorized_user)
    end.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
    expect(resolve_license_history_entries(current_user: unauthorized_user))
    .to be_instance_of(Gitlab::Graphql::Errors::ResourceNotAvailable)
    end
    end
    ......
    ......@@ -40,8 +40,8 @@ def resolve_enabled_namespaces(args = {}, context = {})
    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 'returns ResourceNotAvailable error' do
    expect(resolved_enabled_namespaces).to be_instance_of(Gitlab::Graphql::Errors::ResourceNotAvailable)
    end
    end
    ......@@ -50,8 +50,8 @@ def resolve_enabled_namespaces(args = {}, context = {})
    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 'returns ResourceNotAvailable error' do
    expect(resolved_enabled_namespaces).to be_instance_of(Gitlab::Graphql::Errors::ResourceNotAvailable)
    end
    end
    end
    ......@@ -75,8 +75,8 @@ def resolve_enabled_namespaces(args = {}, context = {})
    root_group_1.add_guest(user)
    end
    it 'raises ResourceNotAvailable error' do
    expect { resolved_enabled_namespaces }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
    it 'returns ResourceNotAvailable error' do
    expect(resolved_enabled_namespaces).to be_instance_of(Gitlab::Graphql::Errors::ResourceNotAvailable)
    end
    end
    ......@@ -85,8 +85,8 @@ def resolve_enabled_namespaces(args = {}, context = {})
    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 'returns ResourceNotAvailable error' do
    expect(resolved_enabled_namespaces).to be_instance_of(Gitlab::Graphql::Errors::ResourceNotAvailable)
    end
    end
    end
    ......
    ......@@ -93,10 +93,9 @@
    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
    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)
    it 'returns an exception if both epic_id and epic_wildcard_id are present' do
    expect(resolve_board_epics(group_board, { issue_filters: { epic_id: epic1.to_global_id, epic_wildcard_id: 'NONE' } }))
    .to be_instance_of(Gitlab::Graphql::Errors::ArgumentError)
    end
    it 'accepts epic global id' do
    ......
    ......@@ -32,8 +32,8 @@
    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 'returns an error if user cannot read epic boards' do
    expect(result).to be_instance_of(Gitlab::Graphql::Errors::ResourceNotAvailable)
    end
    context 'when user is member of the group' do
    ......
    ......@@ -25,8 +25,8 @@
    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 'returns an error if user cannot read epic lists' do
    expect(result).to be_instance_of(Gitlab::Graphql::Errors::ResourceNotAvailable)
    end
    context 'when user is member of the group' do
    ......
    ......@@ -162,16 +162,16 @@
    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 92 days.')
    it 'returns an error' do
    expect(resolve_metrics.message).to eq('Date range must be shorter than 92 days.')
    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 'returns an error' do
    expect(resolve_metrics.message).to eq('The start date must be ealier than the end date.')
    end
    end
    ......
    ......@@ -118,9 +118,11 @@
    context 'with in param' do
    it 'returns an error if param search is missing' do
    result = resolve_epics(in: ['title'])
    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(result).to be_instance_of(Gitlab::Graphql::Errors::ArgumentError)
    expect(result.message).to eq(error_message)
    end
    it 'filters epics by description only' do
    ......
    ......@@ -93,7 +93,10 @@
    end
    it 'raises a GraphQL exception' do
    expect { batch_sync { resolve_external_issue({}) } }.to raise_error(GraphQL::ExecutionError, 'Jira service not configured.')
    result = batch_sync { resolve_external_issue({}) }
    expect(result).to be_instance_of(GraphQL::ExecutionError)
    expect(result.message).to eq('Jira service not configured.')
    end
    end
    ......@@ -105,7 +108,10 @@
    end
    it 'raises a GraphQL exception' do
    expect { batch_sync { resolve_external_issue({}) } }.to raise_error(GraphQL::ExecutionError, 'Jira service unavailable.')
    result = batch_sync { resolve_external_issue({}) }
    expect(result).to be_instance_of(GraphQL::ExecutionError)
    expect(result.message).to eq('Jira service unavailable.')
    end
    end
    ......
    ......@@ -31,8 +31,8 @@
    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 'returns ResourceNotAvailable error' do
    expect(subject).to be_instance_of(Gitlab::Graphql::Errors::ResourceNotAvailable)
    end
    end
    ......
    ......@@ -13,10 +13,9 @@
    shared_examples 'fetches iteration cadences' do
    context 'when user does not have permissions to read iterations cadences' do
    it 'raises error' do
    expect do
    resolve_group_iteration_cadences
    end.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
    it 'returns error' do
    expect(resolve_group_iteration_cadences)
    .to be_instance_of(Gitlab::Graphql::Errors::ResourceNotAvailable)
    end
    end
    ......@@ -52,9 +51,8 @@
    it 'raises error' do
    project.add_developer(current_user)
    expect do
    resolve_group_iteration_cadences({}, project, { current_user: current_user })
    end.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
    expect(resolve_group_iteration_cadences({}, project, { current_user: current_user }))
    .to be_instance_of(Gitlab::Graphql::Errors::ResourceNotAvailable)
    end
    end
    end
    ......
    ......@@ -122,10 +122,11 @@ def resolve_group_iterations(args = {}, obj = group, context = { current_user: c
    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
    resolve_group_iterations(timeframe: { start: now, end: now - 2.days })
    end.to raise_error(Gitlab::Graphql::Errors::ArgumentError, "start must be before end")
    it 'returns an error' do
    result = resolve_group_iterations(timeframe: { start: now, end: now - 2.days })
    expect(result).to be_instance_of(Gitlab::Graphql::Errors::ArgumentError)
    expect(result.messsage).to eq('start must be before end')
    end
    end
    end
    ......@@ -134,38 +135,40 @@ def resolve_group_iterations(args = {}, obj = group, context = { current_user: c
    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
    resolve_group_iterations(start_date: now, end_date: now - 2.days)
    end.to raise_error(Gitlab::Graphql::Errors::ArgumentError, "startDate is after endDate")
    it 'returns an error' do
    result = resolve_group_iterations(start_date: now, end_date: now - 2.days)
    expect(result).to be_instance_of(Gitlab::Graphql::Errors::ArgumentError)
    expect(result.message).to eq('startDate is after endDate')
    end
    end
    end
    context 'when only start_date is present' do
    it 'raises error' do
    expect do
    resolve_group_iterations(start_date: now)
    end.to raise_error(Gitlab::Graphql::Errors::ArgumentError, /Both startDate and endDate/)
    it 'returns an error' do
    result = resolve_group_iterations(start_date: now)
    expect(result).to be_instance_of(Gitlab::Graphql::Errors::ArgumentError)
    expect(result.message).to match(/Both startDate and endDate/)
    end
    end
    context 'when only end_date is present' do
    it 'raises error' do
    expect do
    resolve_group_iterations(end_date: now)
    end.to raise_error(Gitlab::Graphql::Errors::ArgumentError, /Both startDate and endDate/)
    it 'returns an error' do
    result = resolve_group_iterations(end_date: now)
    expect(result).to be_instance_of(Gitlab::Graphql::Errors::ArgumentError)
    expect(result.message).to match(/Both startDate and endDate/)
    end
    end
    end
    context 'when user cannot read iterations' do
    it 'raises error' do
    it 'returns an error' do
    unauthorized_user = create(:user)
    expect do
    resolve_group_iterations({}, group, { current_user: unauthorized_user })
    end.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
    expect(resolve_group_iterations({}, group, { current_user: unauthorized_user }))
    .to be_instance_of(Gitlab::Graphql::Errors::ResourceNotAvailable)
    end
    end
    end
    ......
    ......@@ -37,8 +37,9 @@
    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 'returns a graphql error' do
    expect(subject).to be_instance_of(Gitlab::Graphql::Errors::ResourceNotAvailable)
    expect(subject.message).to eq('GRPC::DeadlineExceeded')
    end
    end
    ......
    ......@@ -54,8 +54,8 @@
    stub_licensed_features(threat_monitoring: false)
    end
    it 'raises ResourceNotAvailable error' do
    expect { resolve_network_policies }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
    it 'returns ResourceNotAvailable error' do
    expect(resolve_network_policies).to be_instance_of(Gitlab::Graphql::Errors::ResourceNotAvailable)
    end
    end
    ......@@ -67,8 +67,11 @@
    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 'returns Gitlab::Graphql::Errors::BaseError' do
    result = resolve_network_policies
    expect(result).to be_instance_of(Gitlab::Graphql::Errors::BaseError)
    expect(result.message).to eq('Error fetching the result')
    end
    end
    ......@@ -123,8 +126,8 @@
    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 'returns ResourceNotAvailable error' do
    expect(resolve_network_policies).to be_instance_of(Gitlab::Graphql::Errors::ResourceNotAvailable)
    end
    end
    end
    ......
    ......@@ -37,7 +37,7 @@
    context 'user is unauthorized' do
    let(:user) { create(:user) }
    it { expect { resolve_path_locks }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable) }
    it { expect(resolve_path_locks).to be_instance_of(Gitlab::Graphql::Errors::ResourceNotAvailable) }
    end
    end
    end
    ......
    ......@@ -41,8 +41,8 @@
    stub_licensed_features(security_orchestration_policies: false)
    end
    it 'raises ResourceNotAvailable error' do
    expect { resolve_scan_policies }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
    it 'returns ResourceNotAvailable error' do
    expect(resolve_scan_policies).to be_instance_of(Gitlab::Graphql::Errors::ResourceNotAvailable)
    end
    end
    ......@@ -67,8 +67,8 @@
    context 'when user is unauthorized' do
    let(:user) { create(:user) }
    it 'raises ResourceNotAvailable error' do
    expect { resolve_scan_policies }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
    it 'returns ResourceNotAvailable error' do
    expect(resolve_scan_policies).to be_instance_of(Gitlab::Graphql::Errors::ResourceNotAvailable)
    end
    end
    ......
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Finish editing this message first!
    Please register or to comment