diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-21 09:08:43 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-21 09:08:43 +0000 |
commit | afe057a8ff8546f0032e439a9a200307fb6de86a (patch) | |
tree | 0f6699ac8a4863344f4f4db6500d33ce509e44c5 /spec | |
parent | ab0dd39a49e43f6beed9bdb6414a0f04bcf671b4 (diff) | |
download | gitlab-ce-afe057a8ff8546f0032e439a9a200307fb6de86a.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
7 files changed, 140 insertions, 54 deletions
diff --git a/spec/controllers/projects/error_tracking_controller_spec.rb b/spec/controllers/projects/error_tracking_controller_spec.rb index 588c4b05528..22826938de2 100644 --- a/spec/controllers/projects/error_tracking_controller_spec.rb +++ b/spec/controllers/projects/error_tracking_controller_spec.rb @@ -301,7 +301,7 @@ describe Projects::ErrorTrackingController do context 'update result is successful' do before do expect(issue_update_service).to receive(:execute) - .and_return(status: :success, updated: true) + .and_return(status: :success, updated: true, closed_issue_iid: 1234) update_issue end diff --git a/spec/fixtures/api/schemas/error_tracking/update_issue.json b/spec/fixtures/api/schemas/error_tracking/update_issue.json index 72514ce647d..75f2c1152d9 100644 --- a/spec/fixtures/api/schemas/error_tracking/update_issue.json +++ b/spec/fixtures/api/schemas/error_tracking/update_issue.json @@ -6,9 +6,15 @@ "properties" : { "result": { "type": "object", + "required" : [ + "status", + "updated", + "closed_issue_iid" + ], "properties": { "status": { "type": "string" }, - "updated": { "type": "boolean" } + "updated": { "type": "boolean" }, + "closed_issue_iid": { "type": ["integer", "null"] } } } }, diff --git a/spec/services/error_tracking/issue_details_service_spec.rb b/spec/services/error_tracking/issue_details_service_spec.rb index 4d5505bb5a9..26bb3b44126 100644 --- a/spec/services/error_tracking/issue_details_service_spec.rb +++ b/spec/services/error_tracking/issue_details_service_spec.rb @@ -3,24 +3,7 @@ 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 + include_context 'sentry error tracking context' describe '#execute' do context 'with authorized user' do 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 cda15042814..7f53eabd717 100644 --- a/spec/services/error_tracking/issue_latest_event_service_spec.rb +++ b/spec/services/error_tracking/issue_latest_event_service_spec.rb @@ -3,24 +3,7 @@ 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 + include_context 'sentry error tracking context' describe '#execute' do context 'with authorized user' do diff --git a/spec/services/error_tracking/issue_update_service_spec.rb b/spec/services/error_tracking/issue_update_service_spec.rb new file mode 100644 index 00000000000..ad1dafe6ccc --- /dev/null +++ b/spec/services/error_tracking/issue_update_service_spec.rb @@ -0,0 +1,106 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe ErrorTracking::IssueUpdateService do + include_context 'sentry error tracking context' + + let(:arguments) { { issue_id: 1234, status: 'resolved' } } + + subject { described_class.new(project, user, arguments) } + + shared_examples 'does not perform close issue flow' do + it 'does not call the close issue service' do + expect(issue_close_service) + .not_to receive(:execute) + end + + it 'does not create system note' do + expect(SystemNoteService).not_to receive(:close_after_error_tracking_resolve) + end + end + + describe '#execute' do + context 'with authorized user' do + context 'when update_issue returns success' do + let(:update_issue_response) { { updated: true } } + + before do + expect(error_tracking_setting) + .to receive(:update_issue).and_return(update_issue_response) + end + + it 'returns the response' do + expect(result).to eq(update_issue_response.merge(status: :success, closed_issue_iid: nil)) + end + + it 'updates any related issue' do + expect(subject).to receive(:update_related_issue) + + result + end + + context '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) } + + before do + allow_any_instance_of(SentryIssueFinder) + .to receive(:execute) + .and_return(sentry_issue) + + allow(Issues::CloseService) + .to receive(:new) + .and_return(issue_close_service) + end + + after do + result + end + + it 'closes the issue' do + expect(issue_close_service) + .to receive(:execute) + .with(issue, system_note: false) + .and_return(issue) + end + + it 'creates a system note' do + expect(SystemNoteService).to receive(:close_after_error_tracking_resolve) + end + + it 'returns a response with closed issue' do + closed_issue = create(:issue, :closed, project: project) + + expect(issue_close_service) + .to receive(:execute) + .with(issue, system_note: false) + .and_return(closed_issue) + + expect(result).to eq(status: :success, updated: true, closed_issue_iid: closed_issue.iid) + end + + context '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 + let(:arguments) { { issue_id: sentry_issue.sentry_issue_identifier, status: 'ignored' } } + + include_examples 'does not perform close issue flow' + end + end + end + + include_examples 'error tracking service sentry error handling', :update_issue + 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 ecb6bcc541b..1e39146fd18 100644 --- a/spec/services/error_tracking/list_issues_service_spec.rb +++ b/spec/services/error_tracking/list_issues_service_spec.rb @@ -3,8 +3,8 @@ require 'spec_helper' describe ErrorTracking::ListIssuesService do - let_it_be(:user) { create(:user) } - let_it_be(:project) { create(:project) } + include_context 'sentry error tracking context' + let(:params) { { search_term: 'something', sort: 'last_seen', cursor: 'some-cursor' } } let(:list_sentry_issues_args) do { @@ -16,22 +16,8 @@ describe ErrorTracking::ListIssuesService do } end - 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, params) } - 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 list_sentry_issues returns issues' do diff --git a/spec/support/shared_contexts/sentry_error_tracking_shared_context.rb b/spec/support/shared_contexts/sentry_error_tracking_shared_context.rb new file mode 100644 index 00000000000..ba729f21e58 --- /dev/null +++ b/spec/support/shared_contexts/sentry_error_tracking_shared_context.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +shared_context 'sentry error tracking context' 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 } + + subject { described_class.new(project, user) } + + let(:error_tracking_setting) do + create(:project_error_tracking_setting, api_url: sentry_url, token: token, project: project) + end + + before do + expect(project).to receive(:error_tracking_setting).at_least(:once).and_return(error_tracking_setting) + + project.add_reporter(user) + end +end |