Commit 90072022 authored by Bob Van Landuyt's avatar Bob Van Landuyt

Merge branch '198012-refactor-specs-in-error_tracking-issue_update_service_spec-rb' into 'master'

Refactor issue update service spec

Closes #198012

See merge request gitlab-org/gitlab!23663
parents d6254835 cd77d2c9
......@@ -5,6 +5,8 @@ require 'spec_helper'
describe ErrorTracking::IssueDetailsService do
include_context 'sentry error tracking context'
subject { described_class.new(project, user, params) }
describe '#execute' do
context 'with authorized user' do
context 'when issue_details returns a detailed error' do
......
......@@ -5,6 +5,8 @@ require 'spec_helper'
describe ErrorTracking::IssueLatestEventService do
include_context 'sentry error tracking context'
subject { described_class.new(project, user) }
describe '#execute' do
context 'with authorized user' do
context 'when issue_latest_event returns an error event' do
......
......@@ -7,16 +7,19 @@ describe ErrorTracking::IssueUpdateService do
let(:arguments) { { issue_id: 1234, status: 'resolved' } }
subject { described_class.new(project, user, arguments) }
subject(:update_service) { described_class.new(project, user, arguments) }
shared_examples 'does not perform close issue flow' do
it 'does not call the close issue service' do
update_service.execute
expect(issue_close_service)
.not_to receive(:execute)
.not_to have_received(:execute)
end
it 'does not create system note' do
expect(SystemNoteService).not_to receive(:close_after_error_tracking_resolve)
update_service.execute
end
end
......@@ -31,13 +34,13 @@ describe ErrorTracking::IssueUpdateService do
end
it 'returns the response' do
expect(result).to eq(update_issue_response.merge(status: :success, closed_issue_iid: nil))
expect(update_service.execute).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)
expect(update_service).to receive(:update_related_issue)
result
update_service.execute
end
context 'related issue and resolving' do
......@@ -48,39 +51,46 @@ describe ErrorTracking::IssueUpdateService do
let(:issue_close_service) { spy(:issue_close_service) }
before do
allow_any_instance_of(SentryIssueFinder)
.to receive(:execute)
.and_return(sentry_issue)
allow_next_instance_of(SentryIssueFinder) do |finder|
allow(finder).to receive(:execute).and_return(sentry_issue)
end
allow(Issues::CloseService)
.to receive(:new)
.and_return(issue_close_service)
end
after do
result
allow(issue_close_service)
.to receive(:execute)
.and_return(issue)
end
it 'closes the issue' do
update_service.execute
expect(issue_close_service)
.to receive(:execute)
.to have_received(: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
context 'issues gets closed' do
let(:closed_issue) { create(:issue, :closed, project: project) }
it 'returns a response with closed issue' do
closed_issue = create(:issue, :closed, project: project)
before do
expect(issue_close_service)
.to receive(:execute)
.with(issue, system_note: false)
.and_return(closed_issue)
end
expect(issue_close_service)
.to receive(:execute)
.with(issue, system_note: false)
.and_return(closed_issue)
it 'creates a system note' do
expect(SystemNoteService).to receive(:close_after_error_tracking_resolve)
update_service.execute
end
expect(result).to eq(status: :success, updated: true, closed_issue_iid: closed_issue.iid)
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
end
context 'issue is already closed' do
......
......@@ -9,8 +9,6 @@ shared_context 'sentry error tracking context' do
let(:params) { {} }
let(:result) { subject.execute }
subject { described_class.new(project, user, params) }
let(:error_tracking_setting) do
create(:project_error_tracking_setting, api_url: sentry_url, token: token, project: project)
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment