summaryrefslogtreecommitdiff
path: root/spec/services/error_tracking
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2019-11-08 21:06:38 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2019-11-08 21:06:38 +0000
commitae72d71da85732ec9ceb9723953fe6ca1df0fdf6 (patch)
tree9e1096312c5fc03a7657ae9586a6714f04ddf8ad /spec/services/error_tracking
parent759bab058520a21d87087355dc193f634176e98a (diff)
downloadgitlab-ce-ae72d71da85732ec9ceb9723953fe6ca1df0fdf6.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/services/error_tracking')
-rw-r--r--spec/services/error_tracking/issue_details_service_spec.rb48
-rw-r--r--spec/services/error_tracking/issue_latest_event_service_spec.rb48
-rw-r--r--spec/services/error_tracking/list_issues_service_spec.rb91
-rw-r--r--spec/services/error_tracking/list_projects_service_spec.rb2
4 files changed, 102 insertions, 87 deletions
diff --git a/spec/services/error_tracking/issue_details_service_spec.rb b/spec/services/error_tracking/issue_details_service_spec.rb
new file mode 100644
index 00000000000..4d5505bb5a9
--- /dev/null
+++ b/spec/services/error_tracking/issue_details_service_spec.rb
@@ -0,0 +1,48 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe ErrorTracking::IssueDetailsService do
+ let_it_be(:user) { create(:user) }
+ let_it_be(:project) { create(:project) }
+
+ let(:sentry_url) { 'https://sentrytest.gitlab.com/api/0/projects/sentry-org/sentry-project' }
+ let(:token) { 'test-token' }
+ let(:result) { subject.execute }
+
+ let(:error_tracking_setting) do
+ create(:project_error_tracking_setting, api_url: sentry_url, token: token, project: project)
+ end
+
+ subject { described_class.new(project, user) }
+
+ before do
+ expect(project).to receive(:error_tracking_setting).at_least(:once).and_return(error_tracking_setting)
+
+ project.add_reporter(user)
+ end
+
+ describe '#execute' do
+ context 'with authorized user' do
+ context 'when issue_details returns a detailed error' do
+ let(:detailed_error) { build(:detailed_error_tracking_error) }
+
+ before do
+ expect(error_tracking_setting)
+ .to receive(:issue_details).and_return(issue: detailed_error)
+ end
+
+ it 'returns the detailed error' do
+ expect(result).to eq(status: :success, issue: detailed_error)
+ end
+ end
+
+ include_examples 'error tracking service data not ready', :issue_details
+ include_examples 'error tracking service sentry error handling', :issue_details
+ include_examples 'error tracking service http status handling', :issue_details
+ end
+
+ include_examples 'error tracking service unauthorized user'
+ include_examples 'error tracking service disabled'
+ end
+end
diff --git a/spec/services/error_tracking/issue_latest_event_service_spec.rb b/spec/services/error_tracking/issue_latest_event_service_spec.rb
new file mode 100644
index 00000000000..cda15042814
--- /dev/null
+++ b/spec/services/error_tracking/issue_latest_event_service_spec.rb
@@ -0,0 +1,48 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe ErrorTracking::IssueLatestEventService do
+ let_it_be(:user) { create(:user) }
+ let_it_be(:project) { create(:project) }
+
+ let(:sentry_url) { 'https://sentrytest.gitlab.com/api/0/projects/sentry-org/sentry-project' }
+ let(:token) { 'test-token' }
+ let(:result) { subject.execute }
+
+ let(:error_tracking_setting) do
+ create(:project_error_tracking_setting, api_url: sentry_url, token: token, project: project)
+ end
+
+ subject { described_class.new(project, user) }
+
+ before do
+ expect(project).to receive(:error_tracking_setting).at_least(:once).and_return(error_tracking_setting)
+
+ project.add_reporter(user)
+ end
+
+ describe '#execute' do
+ context 'with authorized user' do
+ context 'when issue_latest_event returns an error event' do
+ let(:error_event) { build(:error_tracking_error_event) }
+
+ before do
+ expect(error_tracking_setting)
+ .to receive(:issue_latest_event).and_return(latest_event: error_event)
+ end
+
+ it 'returns the error event' do
+ expect(result).to eq(status: :success, latest_event: error_event)
+ end
+ end
+
+ include_examples 'error tracking service data not ready', :issue_latest_event
+ include_examples 'error tracking service sentry error handling', :issue_latest_event
+ include_examples 'error tracking service http status handling', :issue_latest_event
+ end
+
+ include_examples 'error tracking service unauthorized user'
+ include_examples 'error tracking service disabled'
+ end
+end
diff --git a/spec/services/error_tracking/list_issues_service_spec.rb b/spec/services/error_tracking/list_issues_service_spec.rb
index 3a8f3069911..fce790f708d 100644
--- a/spec/services/error_tracking/list_issues_service_spec.rb
+++ b/spec/services/error_tracking/list_issues_service_spec.rb
@@ -37,93 +37,12 @@ describe ErrorTracking::ListIssuesService do
end
end
- context 'when list_sentry_issues returns nil' do
- before do
- expect(error_tracking_setting)
- .to receive(:list_sentry_issues).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
-
- context 'when list_sentry_issues returns error' do
- before do
- allow(error_tracking_setting)
- .to receive(:list_sentry_issues)
- .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
-
- context 'when list_sentry_issues returns error with http_status' do
- before do
- allow(error_tracking_setting)
- .to receive(:list_sentry_issues)
- .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
+ include_examples 'error tracking service data not ready', :list_sentry_issues
+ include_examples 'error tracking service sentry error handling', :list_sentry_issues
+ include_examples 'error tracking service http status handling', :list_sentry_issues
end
- 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
-
- 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
-
- describe '#sentry_external_url' do
- let(:external_url) { 'https://sentrytest.gitlab.com/sentry-org/sentry-project' }
-
- it 'calls ErrorTracking::ProjectErrorTrackingSetting' do
- expect(error_tracking_setting).to receive(:sentry_external_url).and_call_original
-
- subject.external_url
- end
+ include_examples 'error tracking service unauthorized user'
+ include_examples 'error tracking service disabled'
end
end
diff --git a/spec/services/error_tracking/list_projects_service_spec.rb b/spec/services/error_tracking/list_projects_service_spec.rb
index a272a604184..cd4b835e097 100644
--- a/spec/services/error_tracking/list_projects_service_spec.rb
+++ b/spec/services/error_tracking/list_projects_service_spec.rb
@@ -127,7 +127,7 @@ describe ErrorTracking::ListProjectsService do
end
it 'returns error' do
- expect(result).to include(status: :error, message: 'access denied')
+ expect(result).to include(status: :error, message: 'Access denied', http_status: :unauthorized)
end
end