Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/services/error_tracking')
-rw-r--r--spec/services/error_tracking/base_service_spec.rb11
-rw-r--r--spec/services/error_tracking/collect_error_service_spec.rb15
-rw-r--r--spec/services/error_tracking/issue_details_service_spec.rb16
-rw-r--r--spec/services/error_tracking/issue_latest_event_service_spec.rb16
-rw-r--r--spec/services/error_tracking/issue_update_service_spec.rb21
5 files changed, 54 insertions, 25 deletions
diff --git a/spec/services/error_tracking/base_service_spec.rb b/spec/services/error_tracking/base_service_spec.rb
index 2f2052f0189..de3523cb847 100644
--- a/spec/services/error_tracking/base_service_spec.rb
+++ b/spec/services/error_tracking/base_service_spec.rb
@@ -4,8 +4,8 @@ require 'spec_helper'
RSpec.describe ErrorTracking::BaseService do
describe '#compose_response' do
- let(:project) { double('project') }
- let(:user) { double('user', id: non_existing_record_id) }
+ let(:project) { build_stubbed(:project) }
+ let(:user) { build_stubbed(:user, id: non_existing_record_id) }
let(:service) { described_class.new(project, user) }
it 'returns bad_request error when response has an error key' do
@@ -19,7 +19,10 @@ RSpec.describe ErrorTracking::BaseService do
end
it 'returns server error when response has missing key error_type' do
- data = { error: 'Unexpected Error', error_type: ErrorTracking::ProjectErrorTrackingSetting::SENTRY_API_ERROR_TYPE_MISSING_KEYS }
+ data = {
+ error: 'Unexpected Error',
+ error_type: ErrorTracking::ProjectErrorTrackingSetting::SENTRY_API_ERROR_TYPE_MISSING_KEYS
+ }
result = service.send(:compose_response, data)
@@ -48,7 +51,7 @@ RSpec.describe ErrorTracking::BaseService do
context 'when parse_response is implemented' do
before do
- expect(service).to receive(:parse_response) do |response|
+ allow(service).to receive(:parse_response) do |response|
{ animal: response[:thing] }
end
end
diff --git a/spec/services/error_tracking/collect_error_service_spec.rb b/spec/services/error_tracking/collect_error_service_spec.rb
index faca3c12a48..159c070c683 100644
--- a/spec/services/error_tracking/collect_error_service_spec.rb
+++ b/spec/services/error_tracking/collect_error_service_spec.rb
@@ -52,12 +52,13 @@ RSpec.describe ErrorTracking::CollectErrorService do
end
context 'with unusual payload' do
- let(:modified_event) { parsed_event }
- let(:event) { described_class.new(project, nil, event: modified_event).execute }
+ let(:event) { ErrorTracking::ErrorEvent.last! }
context 'when transaction is missing' do
it 'builds actor from stacktrace' do
- modified_event.delete('transaction')
+ parsed_event.delete('transaction')
+
+ subject.execute
expect(event.error.actor).to eq 'find()'
end
@@ -65,7 +66,9 @@ RSpec.describe ErrorTracking::CollectErrorService do
context 'when transaction is an empty string' do \
it 'builds actor from stacktrace' do
- modified_event['transaction'] = ''
+ parsed_event['transaction'] = ''
+
+ subject.execute
expect(event.error.actor).to eq 'find()'
end
@@ -73,7 +76,9 @@ RSpec.describe ErrorTracking::CollectErrorService do
context 'when timestamp is numeric' do
it 'parses timestamp' do
- modified_event['timestamp'] = '1631015580.50'
+ parsed_event['timestamp'] = '1631015580.50'
+
+ subject.execute
expect(event.occurred_at).to eq '2021-09-07T11:53:00.5'
end
diff --git a/spec/services/error_tracking/issue_details_service_spec.rb b/spec/services/error_tracking/issue_details_service_spec.rb
index 8cc2688d198..29f8154a27c 100644
--- a/spec/services/error_tracking/issue_details_service_spec.rb
+++ b/spec/services/error_tracking/issue_details_service_spec.rb
@@ -14,7 +14,7 @@ RSpec.describe ErrorTracking::IssueDetailsService do
let(:params) { { issue_id: detailed_error.id } }
before do
- expect(error_tracking_setting)
+ allow(error_tracking_setting)
.to receive(:issue_details).and_return(issue: detailed_error)
end
@@ -40,7 +40,7 @@ RSpec.describe ErrorTracking::IssueDetailsService do
include_examples 'error tracking service sentry error handling', :issue_details
include_examples 'error tracking service http status handling', :issue_details
- context 'integrated error tracking' do
+ context 'with integrated error tracking' do
let_it_be(:error) { create(:error_tracking_error, project: project) }
let(:params) { { issue_id: error.id } }
@@ -53,6 +53,18 @@ RSpec.describe ErrorTracking::IssueDetailsService do
expect(result[:status]).to eq(:success)
expect(result[:issue].to_json).to eq(error.to_sentry_detailed_error.to_json)
end
+
+ context 'when error does not exist' do
+ let(:params) { { issue_id: non_existing_record_id } }
+
+ it 'returns the error in detailed format' do
+ expect(result).to match(
+ status: :error,
+ message: /Couldn't find ErrorTracking::Error/,
+ http_status: :bad_request
+ )
+ end
+ end
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
index e914cb1241e..aa2430ddffb 100644
--- a/spec/services/error_tracking/issue_latest_event_service_spec.rb
+++ b/spec/services/error_tracking/issue_latest_event_service_spec.rb
@@ -15,7 +15,7 @@ RSpec.describe ErrorTracking::IssueLatestEventService do
let(:error_event) { build(:error_tracking_sentry_error_event) }
before do
- expect(error_tracking_setting)
+ allow(error_tracking_setting)
.to receive(:issue_latest_event).and_return(latest_event: error_event)
end
@@ -28,7 +28,7 @@ RSpec.describe ErrorTracking::IssueLatestEventService do
include_examples 'error tracking service sentry error handling', :issue_latest_event
include_examples 'error tracking service http status handling', :issue_latest_event
- context 'integrated error tracking' do
+ context 'with integrated error tracking' do
let_it_be(:error) { create(:error_tracking_error, project: project) }
let_it_be(:event) { create(:error_tracking_error_event, error: error) }
@@ -42,6 +42,18 @@ RSpec.describe ErrorTracking::IssueLatestEventService do
expect(result[:status]).to eq(:success)
expect(result[:latest_event].to_json).to eq(event.to_sentry_error_event.to_json)
end
+
+ context 'when error does not exist' do
+ let(:params) { { issue_id: non_existing_record_id } }
+
+ it 'returns the error in detailed format' do
+ expect(result).to match(
+ status: :error,
+ message: /Couldn't find ErrorTracking::Error/,
+ http_status: :bad_request
+ )
+ end
+ end
end
end
diff --git a/spec/services/error_tracking/issue_update_service_spec.rb b/spec/services/error_tracking/issue_update_service_spec.rb
index 31a66654100..a06c3588264 100644
--- a/spec/services/error_tracking/issue_update_service_spec.rb
+++ b/spec/services/error_tracking/issue_update_service_spec.rb
@@ -13,8 +13,7 @@ RSpec.describe ErrorTracking::IssueUpdateService do
it 'does not call the close issue service' do
update_service.execute
- expect(issue_close_service)
- .not_to have_received(:execute)
+ expect(issue_close_service).not_to have_received(:execute)
end
it 'does not create system note' do
@@ -29,8 +28,7 @@ RSpec.describe ErrorTracking::IssueUpdateService do
let(:update_issue_response) { { updated: true } }
before do
- expect(error_tracking_setting)
- .to receive(:update_issue).and_return(update_issue_response)
+ allow(error_tracking_setting).to receive(:update_issue).and_return(update_issue_response)
end
it 'returns the response' do
@@ -49,12 +47,11 @@ RSpec.describe ErrorTracking::IssueUpdateService do
result
end
- context 'related issue and resolving' do
+ context 'with related issue and resolving' do
let(:issue) { create(:issue, project: project) }
let(:sentry_issue) { create(:sentry_issue, issue: issue) }
let(:arguments) { { issue_id: sentry_issue.sentry_issue_identifier, status: 'resolved' } }
-
- let(:issue_close_service) { spy(:issue_close_service) }
+ let(:issue_close_service) { instance_double('Issues::CloseService') }
before do
allow_next_instance_of(SentryIssueFinder) do |finder|
@@ -78,11 +75,11 @@ RSpec.describe ErrorTracking::IssueUpdateService do
.with(issue, system_note: false)
end
- context 'issues gets closed' do
+ context 'when issue gets closed' do
let(:closed_issue) { create(:issue, :closed, project: project) }
before do
- expect(issue_close_service)
+ allow(issue_close_service)
.to receive(:execute)
.with(issue, system_note: false)
.and_return(closed_issue)
@@ -99,13 +96,13 @@ RSpec.describe ErrorTracking::IssueUpdateService do
end
end
- context 'issue is already closed' do
+ context 'when issue is already closed' do
let(:issue) { create(:issue, :closed, project: project) }
include_examples 'does not perform close issue flow'
end
- context 'status is not resolving' do
+ context 'when status is not resolving' do
let(:arguments) { { issue_id: sentry_issue.sentry_issue_identifier, status: 'ignored' } }
include_examples 'does not perform close issue flow'
@@ -115,7 +112,7 @@ RSpec.describe ErrorTracking::IssueUpdateService do
include_examples 'error tracking service sentry error handling', :update_issue
- context 'integrated error tracking' do
+ context 'with integrated error tracking' do
let(:error) { create(:error_tracking_error, project: project) }
let(:arguments) { { issue_id: error.id, status: 'resolved' } }
let(:update_issue_response) { { updated: true, status: :success, closed_issue_iid: nil } }