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' ...@@ -5,6 +5,8 @@ require 'spec_helper'
describe ErrorTracking::IssueDetailsService do describe ErrorTracking::IssueDetailsService do
include_context 'sentry error tracking context' include_context 'sentry error tracking context'
subject { described_class.new(project, user, params) }
describe '#execute' do describe '#execute' do
context 'with authorized user' do context 'with authorized user' do
context 'when issue_details returns a detailed error' do context 'when issue_details returns a detailed error' do
......
...@@ -5,6 +5,8 @@ require 'spec_helper' ...@@ -5,6 +5,8 @@ require 'spec_helper'
describe ErrorTracking::IssueLatestEventService do describe ErrorTracking::IssueLatestEventService do
include_context 'sentry error tracking context' include_context 'sentry error tracking context'
subject { described_class.new(project, user) }
describe '#execute' do describe '#execute' do
context 'with authorized user' do context 'with authorized user' do
context 'when issue_latest_event returns an error event' do context 'when issue_latest_event returns an error event' do
......
...@@ -7,16 +7,19 @@ describe ErrorTracking::IssueUpdateService do ...@@ -7,16 +7,19 @@ describe ErrorTracking::IssueUpdateService do
let(:arguments) { { issue_id: 1234, status: 'resolved' } } 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 shared_examples 'does not perform close issue flow' do
it 'does not call the close issue service' do it 'does not call the close issue service' do
update_service.execute
expect(issue_close_service) expect(issue_close_service)
.not_to receive(:execute) .not_to have_received(:execute)
end end
it 'does not create system note' do it 'does not create system note' do
expect(SystemNoteService).not_to receive(:close_after_error_tracking_resolve) expect(SystemNoteService).not_to receive(:close_after_error_tracking_resolve)
update_service.execute
end end
end end
...@@ -31,13 +34,13 @@ describe ErrorTracking::IssueUpdateService do ...@@ -31,13 +34,13 @@ describe ErrorTracking::IssueUpdateService do
end end
it 'returns the response' do 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 end
it 'updates any related issue' do 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 end
context 'related issue and resolving' do context 'related issue and resolving' do
...@@ -48,39 +51,46 @@ describe ErrorTracking::IssueUpdateService do ...@@ -48,39 +51,46 @@ describe ErrorTracking::IssueUpdateService do
let(:issue_close_service) { spy(:issue_close_service) } let(:issue_close_service) { spy(:issue_close_service) }
before do before do
allow_any_instance_of(SentryIssueFinder) allow_next_instance_of(SentryIssueFinder) do |finder|
.to receive(:execute) allow(finder).to receive(:execute).and_return(sentry_issue)
.and_return(sentry_issue) end
allow(Issues::CloseService) allow(Issues::CloseService)
.to receive(:new) .to receive(:new)
.and_return(issue_close_service) .and_return(issue_close_service)
end
after do allow(issue_close_service)
result .to receive(:execute)
.and_return(issue)
end end
it 'closes the issue' do it 'closes the issue' do
update_service.execute
expect(issue_close_service) expect(issue_close_service)
.to receive(:execute) .to have_received(:execute)
.with(issue, system_note: false) .with(issue, system_note: false)
.and_return(issue)
end end
it 'creates a system note' do context 'issues gets closed' do
expect(SystemNoteService).to receive(:close_after_error_tracking_resolve) let(:closed_issue) { create(:issue, :closed, project: project) }
end
it 'returns a response with closed issue' do before do
closed_issue = create(:issue, :closed, project: project) expect(issue_close_service)
.to receive(:execute)
.with(issue, system_note: false)
.and_return(closed_issue)
end
expect(issue_close_service) it 'creates a system note' do
.to receive(:execute) expect(SystemNoteService).to receive(:close_after_error_tracking_resolve)
.with(issue, system_note: false)
.and_return(closed_issue) 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 end
context 'issue is already closed' do context 'issue is already closed' do
......
...@@ -9,8 +9,6 @@ shared_context 'sentry error tracking context' do ...@@ -9,8 +9,6 @@ shared_context 'sentry error tracking context' do
let(:params) { {} } let(:params) { {} }
let(:result) { subject.execute } let(:result) { subject.execute }
subject { described_class.new(project, user, params) }
let(:error_tracking_setting) do let(:error_tracking_setting) do
create(:project_error_tracking_setting, api_url: sentry_url, token: token, project: project) create(:project_error_tracking_setting, api_url: sentry_url, token: token, project: project)
end 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