2020-01-21 09:08:43 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 15:08:50 +00:00
|
|
|
RSpec.describe ErrorTracking::IssueUpdateService do
|
2020-01-21 09:08:43 +00:00
|
|
|
include_context 'sentry error tracking context'
|
|
|
|
|
2020-04-01 15:07:45 +00:00
|
|
|
let(:arguments) { { issue_id: non_existing_record_id, status: 'resolved' } }
|
2020-01-21 09:08:43 +00:00
|
|
|
|
2020-02-04 12:09:00 +00:00
|
|
|
subject(:update_service) { described_class.new(project, user, arguments) }
|
2020-01-21 09:08:43 +00:00
|
|
|
|
|
|
|
shared_examples 'does not perform close issue flow' do
|
|
|
|
it 'does not call the close issue service' do
|
2020-02-04 12:09:00 +00:00
|
|
|
update_service.execute
|
|
|
|
|
2020-01-21 09:08:43 +00:00
|
|
|
expect(issue_close_service)
|
2020-02-04 12:09:00 +00:00
|
|
|
.not_to have_received(:execute)
|
2020-01-21 09:08:43 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not create system note' do
|
|
|
|
expect(SystemNoteService).not_to receive(:close_after_error_tracking_resolve)
|
2020-02-04 12:09:00 +00:00
|
|
|
update_service.execute
|
2020-01-21 09:08:43 +00:00
|
|
|
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
|
2020-02-04 12:09:00 +00:00
|
|
|
expect(update_service.execute).to eq(update_issue_response.merge(status: :success, closed_issue_iid: nil))
|
2020-01-21 09:08:43 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'updates any related issue' do
|
2020-02-04 12:09:00 +00:00
|
|
|
expect(update_service).to receive(:update_related_issue)
|
2020-01-21 09:08:43 +00:00
|
|
|
|
2020-02-04 12:09:00 +00:00
|
|
|
update_service.execute
|
2020-01-21 09:08:43 +00:00
|
|
|
end
|
|
|
|
|
2020-02-26 15:08:56 +00:00
|
|
|
it 'clears the reactive cache' do
|
|
|
|
expect(error_tracking_setting).to receive(:expire_issues_cache)
|
|
|
|
|
|
|
|
result
|
|
|
|
end
|
|
|
|
|
2020-01-21 09:08:43 +00:00
|
|
|
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
|
2020-02-04 12:09:00 +00:00
|
|
|
allow_next_instance_of(SentryIssueFinder) do |finder|
|
|
|
|
allow(finder).to receive(:execute).and_return(sentry_issue)
|
|
|
|
end
|
2020-01-21 09:08:43 +00:00
|
|
|
|
|
|
|
allow(Issues::CloseService)
|
|
|
|
.to receive(:new)
|
|
|
|
.and_return(issue_close_service)
|
|
|
|
|
2020-02-04 12:09:00 +00:00
|
|
|
allow(issue_close_service)
|
|
|
|
.to receive(:execute)
|
|
|
|
.and_return(issue)
|
2020-01-21 09:08:43 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'closes the issue' do
|
2020-02-04 12:09:00 +00:00
|
|
|
update_service.execute
|
|
|
|
|
2020-01-21 09:08:43 +00:00
|
|
|
expect(issue_close_service)
|
2020-02-04 12:09:00 +00:00
|
|
|
.to have_received(:execute)
|
2020-01-21 09:08:43 +00:00
|
|
|
.with(issue, system_note: false)
|
|
|
|
end
|
|
|
|
|
2020-02-04 12:09:00 +00:00
|
|
|
context 'issues gets closed' do
|
|
|
|
let(:closed_issue) { create(:issue, :closed, project: project) }
|
2020-01-21 09:08:43 +00:00
|
|
|
|
2020-02-04 12:09:00 +00:00
|
|
|
before do
|
|
|
|
expect(issue_close_service)
|
|
|
|
.to receive(:execute)
|
|
|
|
.with(issue, system_note: false)
|
|
|
|
.and_return(closed_issue)
|
|
|
|
end
|
2020-01-21 09:08:43 +00:00
|
|
|
|
2020-02-04 12:09:00 +00:00
|
|
|
it 'creates a system note' do
|
|
|
|
expect(SystemNoteService).to receive(:close_after_error_tracking_resolve)
|
|
|
|
|
|
|
|
update_service.execute
|
|
|
|
end
|
2020-01-21 09:08:43 +00:00
|
|
|
|
2020-02-04 12:09:00 +00:00
|
|
|
it 'returns a response with closed issue' do
|
|
|
|
expect(update_service.execute).to eq(status: :success, updated: true, closed_issue_iid: closed_issue.iid)
|
|
|
|
end
|
2020-01-21 09:08:43 +00:00
|
|
|
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
|
2021-08-11 21:10:33 +00:00
|
|
|
|
|
|
|
context '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 } }
|
|
|
|
|
|
|
|
before do
|
|
|
|
error_tracking_setting.update!(integrated: true)
|
|
|
|
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')
|
|
|
|
end
|
|
|
|
end
|
2020-01-21 09:08:43 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
include_examples 'error tracking service unauthorized user'
|
|
|
|
include_examples 'error tracking service disabled'
|
|
|
|
end
|
|
|
|
end
|