2020-08-26 20:10:33 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
RSpec.describe IssueRebalancingWorker do
|
|
|
|
describe '#perform' do
|
|
|
|
let_it_be(:issue) { create(:issue) }
|
|
|
|
|
|
|
|
it 'runs an instance of IssueRebalancingService' do
|
|
|
|
service = double(execute: nil)
|
|
|
|
expect(IssueRebalancingService).to receive(:new).with(issue).and_return(service)
|
|
|
|
|
2020-09-01 05:10:28 -04:00
|
|
|
described_class.new.perform(nil, issue.project_id)
|
2020-08-26 20:10:33 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'anticipates the inability to find the issue' do
|
2020-09-01 05:10:28 -04:00
|
|
|
expect(Gitlab::ErrorTracking).to receive(:log_exception).with(ActiveRecord::RecordNotFound, include(project_id: -1))
|
2020-08-26 20:10:33 -04:00
|
|
|
expect(IssueRebalancingService).not_to receive(:new)
|
|
|
|
|
2020-09-01 05:10:28 -04:00
|
|
|
described_class.new.perform(nil, -1)
|
2020-08-26 20:10:33 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'anticipates there being too many issues' do
|
|
|
|
service = double
|
|
|
|
allow(service).to receive(:execute) { raise IssueRebalancingService::TooManyIssues }
|
|
|
|
expect(IssueRebalancingService).to receive(:new).with(issue).and_return(service)
|
2020-09-01 05:10:28 -04:00
|
|
|
expect(Gitlab::ErrorTracking).to receive(:log_exception).with(IssueRebalancingService::TooManyIssues, include(project_id: issue.project_id))
|
2020-08-26 20:10:33 -04:00
|
|
|
|
2020-09-01 05:10:28 -04:00
|
|
|
described_class.new.perform(nil, issue.project_id)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'takes no action if the value is nil' do
|
|
|
|
expect(IssueRebalancingService).not_to receive(:new)
|
|
|
|
expect(Gitlab::ErrorTracking).not_to receive(:log_exception)
|
|
|
|
|
|
|
|
described_class.new.perform(nil, nil)
|
2020-08-26 20:10:33 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|