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:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-07-19 17:16:28 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2023-07-19 17:16:28 +0300
commite4384360a16dd9a19d4d2d25d0ef1f2b862ed2a6 (patch)
tree2fcdfa7dcdb9db8f5208b2562f4b4e803d671243 /spec/services/error_tracking
parentffda4e7bcac36987f936b4ba515995a6698698f0 (diff)
Add latest changes from gitlab-org/gitlab@16-2-stable-eev16.2.0-rc42
Diffstat (limited to 'spec/services/error_tracking')
-rw-r--r--spec/services/error_tracking/issue_details_service_spec.rb33
-rw-r--r--spec/services/error_tracking/issue_latest_event_service_spec.rb35
-rw-r--r--spec/services/error_tracking/issue_update_service_spec.rb40
-rw-r--r--spec/services/error_tracking/list_issues_service_spec.rb88
4 files changed, 158 insertions, 38 deletions
diff --git a/spec/services/error_tracking/issue_details_service_spec.rb b/spec/services/error_tracking/issue_details_service_spec.rb
index 7ac41ffead6..b1c963e2487 100644
--- a/spec/services/error_tracking/issue_details_service_spec.rb
+++ b/spec/services/error_tracking/issue_details_service_spec.rb
@@ -5,7 +5,7 @@ require 'spec_helper'
RSpec.describe ErrorTracking::IssueDetailsService, feature_category: :error_tracking do
include_context 'sentry error tracking context'
- subject { described_class.new(project, user, params) }
+ subject(:service) { described_class.new(project, user, params) }
describe '#execute' do
context 'with authorized user' do
@@ -41,26 +41,41 @@ RSpec.describe ErrorTracking::IssueDetailsService, feature_category: :error_trac
include_examples 'error tracking service http status handling', :issue_details
context 'with integrated error tracking' do
- let_it_be(:error) { create(:error_tracking_error, project: project) }
-
- let(:params) { { issue_id: error.id } }
+ let(:error_repository) { instance_double(Gitlab::ErrorTracking::ErrorRepository) }
+ let(:params) { { issue_id: issue_id } }
before do
error_tracking_setting.update!(integrated: true)
+
+ allow(service).to receive(:error_repository).and_return(error_repository)
end
- it 'returns the error in detailed format' do
- expect(result[:status]).to eq(:success)
- expect(result[:issue].to_json).to eq(error.to_sentry_detailed_error.to_json)
+ context 'when error is found' do
+ let(:error) { build_stubbed(:error_tracking_open_api_error, project_id: project.id) }
+ let(:issue_id) { error.fingerprint }
+
+ before do
+ allow(error_repository).to receive(:find_error).with(issue_id).and_return(error)
+ end
+
+ it 'returns the error in detailed format' do
+ expect(result[:status]).to eq(:success)
+ expect(result[:issue]).to eq(error)
+ end
end
context 'when error does not exist' do
- let(:params) { { issue_id: non_existing_record_id } }
+ let(:issue_id) { non_existing_record_id }
+
+ before do
+ allow(error_repository).to receive(:find_error).with(issue_id)
+ .and_raise(Gitlab::ErrorTracking::ErrorRepository::DatabaseError.new('Error not found'))
+ end
it 'returns the error in detailed format' do
expect(result).to match(
status: :error,
- message: /Couldn't find ErrorTracking::Error/,
+ message: /Error not found/,
http_status: :bad_request
)
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 bfde14c7ef1..7e0e8dd56a0 100644
--- a/spec/services/error_tracking/issue_latest_event_service_spec.rb
+++ b/spec/services/error_tracking/issue_latest_event_service_spec.rb
@@ -7,7 +7,7 @@ RSpec.describe ErrorTracking::IssueLatestEventService, feature_category: :error_
let(:params) { {} }
- subject { described_class.new(project, user, params) }
+ subject(:service) { described_class.new(project, user, params) }
describe '#execute' do
context 'with authorized user' do
@@ -29,27 +29,42 @@ RSpec.describe ErrorTracking::IssueLatestEventService, feature_category: :error_
include_examples 'error tracking service http status handling', :issue_latest_event
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) }
-
- let(:params) { { issue_id: error.id } }
+ let(:error_repository) { instance_double(Gitlab::ErrorTracking::ErrorRepository) }
+ let(:params) { { issue_id: issue_id } }
before do
error_tracking_setting.update!(integrated: true)
+
+ allow(service).to receive(:error_repository).and_return(error_repository)
end
- it 'returns the latest event in expected format' do
- expect(result[:status]).to eq(:success)
- expect(result[:latest_event].to_json).to eq(event.to_sentry_error_event.to_json)
+ context 'when error is found' do
+ let(:error) { build_stubbed(:error_tracking_open_api_error, project_id: project.id) }
+ let(:event) { build_stubbed(:error_tracking_open_api_error_event, fingerprint: error.fingerprint) }
+ let(:issue_id) { error.fingerprint }
+
+ before do
+ allow(error_repository).to receive(:last_event_for).with(issue_id).and_return(event)
+ end
+
+ it 'returns the latest event in expected format' do
+ expect(result[:status]).to eq(:success)
+ expect(result[:latest_event]).to eq(event)
+ end
end
context 'when error does not exist' do
- let(:params) { { issue_id: non_existing_record_id } }
+ let(:issue_id) { non_existing_record_id }
+
+ before do
+ allow(error_repository).to receive(:last_event_for).with(issue_id)
+ .and_raise(Gitlab::ErrorTracking::ErrorRepository::DatabaseError.new('Error not found'))
+ end
it 'returns the error in detailed format' do
expect(result).to match(
status: :error,
- message: /Couldn't find ErrorTracking::Error/,
+ message: /Error not found/,
http_status: :bad_request
)
end
diff --git a/spec/services/error_tracking/issue_update_service_spec.rb b/spec/services/error_tracking/issue_update_service_spec.rb
index 4dae6cc2fa0..989ebc86abe 100644
--- a/spec/services/error_tracking/issue_update_service_spec.rb
+++ b/spec/services/error_tracking/issue_update_service_spec.rb
@@ -113,17 +113,45 @@ RSpec.describe ErrorTracking::IssueUpdateService, feature_category: :error_track
include_examples 'error tracking service sentry error handling', :update_issue
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 } }
+ let(:error_repository) { instance_double(Gitlab::ErrorTracking::ErrorRepository) }
+ let(:error) { build_stubbed(:error_tracking_open_api_error, project_id: project.id) }
+ let(:issue_id) { error.fingerprint }
+ let(:arguments) { { issue_id: issue_id, status: 'resolved' } }
before do
error_tracking_setting.update!(integrated: true)
+
+ allow(update_service).to receive(:error_repository).and_return(error_repository)
+ allow(error_repository).to receive(:update_error)
+ .with(issue_id, status: 'resolved').and_return(updated)
end
- it 'resolves the error and responds with expected format' do
- expect(update_service.execute).to eq(update_issue_response)
- expect(error.reload.status).to eq('resolved')
+ context 'when update succeeded' do
+ let(:updated) { true }
+
+ it 'returns success with updated true' do
+ expect(project.error_tracking_setting).to receive(:expire_issues_cache)
+
+ expect(update_service.execute).to eq(
+ status: :success,
+ updated: true,
+ closed_issue_iid: nil
+ )
+ end
+ end
+
+ context 'when update failed' do
+ let(:updated) { false }
+
+ it 'returns success with updated false' do
+ expect(project.error_tracking_setting).to receive(:expire_issues_cache)
+
+ expect(update_service.execute).to eq(
+ status: :success,
+ updated: false,
+ closed_issue_iid: nil
+ )
+ end
end
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 2c35c2b8acd..5a6e9b56f6c 100644
--- a/spec/services/error_tracking/list_issues_service_spec.rb
+++ b/spec/services/error_tracking/list_issues_service_spec.rb
@@ -7,10 +7,10 @@ RSpec.describe ErrorTracking::ListIssuesService, feature_category: :error_tracki
let(:params) { {} }
- subject { described_class.new(project, user, params) }
+ subject(:service) { described_class.new(project, user, params) }
describe '#execute' do
- context 'Sentry backend' do
+ context 'with Sentry backend' do
let(:params) { { search_term: 'something', sort: 'last_seen', cursor: 'some-cursor' } }
let(:list_sentry_issues_args) do
@@ -42,7 +42,7 @@ RSpec.describe ErrorTracking::ListIssuesService, feature_category: :error_tracki
expect(result).to eq(status: :success, pagination: {}, issues: issues)
end
- it 'returns bad request for an issue_status not on the whitelist' do
+ it 'returns bad request with invalid issue_status' do
params[:issue_status] = 'assigned'
expect(error_tracking_setting).not_to receive(:list_sentry_issues)
@@ -65,22 +65,84 @@ RSpec.describe ErrorTracking::ListIssuesService, feature_category: :error_tracki
end
end
- context 'GitLab backend' do
- let_it_be(:error1) { create(:error_tracking_error, name: 'foo', project: project) }
- let_it_be(:error2) { create(:error_tracking_error, name: 'bar', project: project) }
+ context 'with integrated error tracking' do
+ let(:error_repository) { instance_double(Gitlab::ErrorTracking::ErrorRepository) }
+ let(:errors) { [] }
+ let(:pagination) { Gitlab::ErrorTracking::ErrorRepository::Pagination.new(nil, nil) }
+ let(:opts) { default_opts }
- let(:params) { { limit: '1' } }
+ let(:default_opts) do
+ {
+ filters: { status: described_class::DEFAULT_ISSUE_STATUS },
+ query: nil,
+ sort: described_class::DEFAULT_SORT,
+ limit: described_class::DEFAULT_LIMIT,
+ cursor: nil
+ }
+ end
+
+ let(:params) { {} }
before do
error_tracking_setting.update!(integrated: true)
+
+ allow(service).to receive(:error_repository).and_return(error_repository)
end
- it 'returns the error in expected format' do
- expect(result[:status]).to eq(:success)
- expect(result[:issues].size).to eq(1)
- expect(result[:issues].first.to_json).to eq(error2.to_sentry_error.to_json)
- expect(result[:pagination][:next][:cursor]).to be_present
- expect(result[:pagination][:previous]).to be_nil
+ context 'when errors are found' do
+ let(:error) { build_stubbed(:error_tracking_open_api_error, project_id: project.id) }
+ let(:errors) { [error] }
+
+ before do
+ allow(error_repository).to receive(:list_errors)
+ .with(**opts)
+ .and_return([errors, pagination])
+ end
+
+ context 'without params' do
+ it 'returns the errors without pagination' do
+ expect(result[:status]).to eq(:success)
+ expect(result[:issues]).to eq(errors)
+ expect(result[:pagination]).to eq({})
+ expect(error_repository).to have_received(:list_errors).with(**opts)
+ end
+ end
+
+ context 'with pagination' do
+ context 'with next page' do
+ before do
+ pagination.next = 'next cursor'
+ end
+
+ it 'has next cursor' do
+ expect(result[:pagination]).to eq(next: { cursor: 'next cursor' })
+ end
+ end
+
+ context 'with prev page' do
+ before do
+ pagination.prev = 'prev cursor'
+ end
+
+ it 'has prev cursor' do
+ expect(result[:pagination]).to eq(previous: { cursor: 'prev cursor' })
+ end
+ end
+
+ context 'with next and prev page' do
+ before do
+ pagination.next = 'next cursor'
+ pagination.prev = 'prev cursor'
+ end
+
+ it 'has both cursors' do
+ expect(result[:pagination]).to eq(
+ next: { cursor: 'next cursor' },
+ previous: { cursor: 'prev cursor' }
+ )
+ end
+ end
+ end
end
end
end