2019-12-26 22:10:19 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
RSpec.shared_examples 'error tracking service data not ready' do |service_call|
|
2019-12-26 22:10:19 +05:30
|
|
|
context "when #{service_call} returns nil" do
|
|
|
|
before do
|
|
|
|
expect(error_tracking_setting)
|
|
|
|
.to receive(service_call).and_return(nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'result is not ready' do
|
|
|
|
expect(result).to eq(
|
|
|
|
status: :error, http_status: :no_content, message: 'Not ready. Try again later')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
RSpec.shared_examples 'error tracking service sentry error handling' do |service_call|
|
2019-12-26 22:10:19 +05:30
|
|
|
context "when #{service_call} returns error" do
|
|
|
|
before do
|
|
|
|
allow(error_tracking_setting)
|
|
|
|
.to receive(service_call)
|
|
|
|
.and_return(
|
|
|
|
error: 'Sentry response status code: 401',
|
|
|
|
error_type: ErrorTracking::ProjectErrorTrackingSetting::SENTRY_API_ERROR_TYPE_NON_20X_RESPONSE
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns the error' do
|
|
|
|
expect(result).to eq(
|
|
|
|
status: :error,
|
|
|
|
http_status: :bad_request,
|
|
|
|
message: 'Sentry response status code: 401'
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
RSpec.shared_examples 'error tracking service http status handling' do |service_call|
|
2019-12-26 22:10:19 +05:30
|
|
|
context "when #{service_call} returns error with http_status" do
|
|
|
|
before do
|
|
|
|
allow(error_tracking_setting)
|
|
|
|
.to receive(service_call)
|
|
|
|
.and_return(
|
|
|
|
error: 'Sentry API response is missing keys. key not found: "id"',
|
|
|
|
error_type: ErrorTracking::ProjectErrorTrackingSetting::SENTRY_API_ERROR_TYPE_MISSING_KEYS
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns the error with correct http_status' do
|
|
|
|
expect(result).to eq(
|
|
|
|
status: :error,
|
|
|
|
http_status: :internal_server_error,
|
|
|
|
message: 'Sentry API response is missing keys. key not found: "id"'
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
RSpec.shared_examples 'error tracking service unauthorized user' do
|
2019-12-26 22:10:19 +05:30
|
|
|
context 'with unauthorized user' do
|
|
|
|
let(:unauthorized_user) { create(:user) }
|
|
|
|
|
|
|
|
subject { described_class.new(project, unauthorized_user) }
|
|
|
|
|
|
|
|
it 'returns error' do
|
|
|
|
result = subject.execute
|
|
|
|
|
|
|
|
expect(result).to include(
|
|
|
|
status: :error,
|
|
|
|
message: 'Access denied',
|
|
|
|
http_status: :unauthorized
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
RSpec.shared_examples 'error tracking service disabled' do
|
2019-12-26 22:10:19 +05:30
|
|
|
context 'with error tracking disabled' do
|
|
|
|
before do
|
|
|
|
error_tracking_setting.enabled = false
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'raises error' do
|
|
|
|
result = subject.execute
|
|
|
|
|
|
|
|
expect(result).to include(status: :error, message: 'Error Tracking is not enabled')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|