diff options
Diffstat (limited to 'spec/requests/api/graphql/project/error_tracking/sentry_errors_request_spec.rb')
-rw-r--r-- | spec/requests/api/graphql/project/error_tracking/sentry_errors_request_spec.rb | 53 |
1 files changed, 26 insertions, 27 deletions
diff --git a/spec/requests/api/graphql/project/error_tracking/sentry_errors_request_spec.rb b/spec/requests/api/graphql/project/error_tracking/sentry_errors_request_spec.rb index 80376f56ee8..a540386a9de 100644 --- a/spec/requests/api/graphql/project/error_tracking/sentry_errors_request_spec.rb +++ b/spec/requests/api/graphql/project/error_tracking/sentry_errors_request_spec.rb @@ -3,6 +3,7 @@ require 'spec_helper' RSpec.describe 'sentry errors requests' do include GraphqlHelpers + let_it_be(:project) { create(:project, :repository) } let_it_be(:project_setting) { create(:project_error_tracking_setting, project: project) } let_it_be(:current_user) { project.owner } @@ -30,7 +31,7 @@ RSpec.describe 'sentry errors requests' do let(:error_data) { graphql_data.dig('project', 'sentryErrors', 'detailedError') } - it 'returns a successful response', :aggregate_failures, :quarantine do + it 'returns a successful response', :aggregate_failures do post_graphql(query, current_user: current_user) expect(response).to have_gitlab_http_status(:success) @@ -48,11 +49,9 @@ RSpec.describe 'sentry errors requests' do end end - context 'reactive cache returns data' do + context 'when reactive cache returns data' do before do - allow_any_instance_of(ErrorTracking::ProjectErrorTrackingSetting) - .to receive(:issue_details) - .and_return(issue: sentry_detailed_error) + stub_setting_for(:issue_details, issue: sentry_detailed_error) post_graphql(query, current_user: current_user) end @@ -72,7 +71,7 @@ RSpec.describe 'sentry errors requests' do end end - context 'user does not have permission' do + context 'when user does not have permission' do let(:current_user) { create(:user) } it 'is expected to return an empty error' do @@ -81,11 +80,9 @@ RSpec.describe 'sentry errors requests' do end end - context 'sentry api returns an error' do + context 'when sentry api returns an error' do before do - expect_any_instance_of(ErrorTracking::ProjectErrorTrackingSetting) - .to receive(:issue_details) - .and_return(error: 'error message') + stub_setting_for(:issue_details, error: 'error message') post_graphql(query, current_user: current_user) end @@ -140,11 +137,11 @@ RSpec.describe 'sentry errors requests' do end end - context 'reactive cache returns data' do + context 'when reactive cache returns data' do before do - expect_any_instance_of(ErrorTracking::ProjectErrorTrackingSetting) - .to receive(:list_sentry_issues) - .and_return(issues: [sentry_error], pagination: pagination) + stub_setting_for(:list_sentry_issues, + issues: [sentry_error], + pagination: pagination) post_graphql(query, current_user: current_user) end @@ -177,11 +174,9 @@ RSpec.describe 'sentry errors requests' do end end - context 'sentry api itself errors out' do + context 'when sentry api itself errors out' do before do - expect_any_instance_of(ErrorTracking::ProjectErrorTrackingSetting) - .to receive(:list_sentry_issues) - .and_return(error: 'error message') + stub_setting_for(:list_sentry_issues, error: 'error message') post_graphql(query, current_user: current_user) end @@ -223,18 +218,16 @@ RSpec.describe 'sentry errors requests' do end end - context 'reactive cache returns data' do + context 'when reactive cache returns data' do before do - allow_any_instance_of(ErrorTracking::ProjectErrorTrackingSetting) - .to receive(:issue_latest_event) - .and_return(latest_event: sentry_stack_trace) + stub_setting_for(:issue_latest_event, latest_event: sentry_stack_trace) post_graphql(query, current_user: current_user) end it_behaves_like 'setting stack trace error' - context 'user does not have permission' do + context 'when user does not have permission' do let(:current_user) { create(:user) } it 'is expected to return an empty error' do @@ -243,11 +236,9 @@ RSpec.describe 'sentry errors requests' do end end - context 'sentry api returns an error' do + context 'when sentry api returns an error' do before do - expect_any_instance_of(ErrorTracking::ProjectErrorTrackingSetting) - .to receive(:issue_latest_event) - .and_return(error: 'error message') + stub_setting_for(:issue_latest_event, error: 'error message') post_graphql(query, current_user: current_user) end @@ -257,4 +248,12 @@ RSpec.describe 'sentry errors requests' do end end end + + private + + def stub_setting_for(method, **return_value) + allow_next_found_instance_of(ErrorTracking::ProjectErrorTrackingSetting) do |setting| + allow(setting).to receive(method).and_return(**return_value) + end + end end |