debian-mirror-gitlab/spec/workers/new_issue_worker_spec.rb

60 lines
1.9 KiB
Ruby
Raw Normal View History

2019-07-07 11:18:12 +05:30
# frozen_string_literal: true
2017-09-10 17:25:29 +05:30
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe NewIssueWorker do
2017-09-10 17:25:29 +05:30
describe '#perform' do
let(:worker) { described_class.new }
context 'when an issue not found' do
it 'does not call Services' do
expect(EventCreateService).not_to receive(:new)
expect(NotificationService).not_to receive(:new)
2020-11-24 15:15:51 +05:30
worker.perform(non_existing_record_id, create(:user).id)
2017-09-10 17:25:29 +05:30
end
it 'logs an error' do
2020-11-24 15:15:51 +05:30
expect(Gitlab::AppLogger).to receive(:error).with("NewIssueWorker: couldn't find Issue with ID=#{non_existing_record_id}, skipping job")
2017-09-10 17:25:29 +05:30
2020-11-24 15:15:51 +05:30
worker.perform(non_existing_record_id, create(:user).id)
2017-09-10 17:25:29 +05:30
end
end
context 'when a user not found' do
it 'does not call Services' do
expect(EventCreateService).not_to receive(:new)
expect(NotificationService).not_to receive(:new)
2020-11-24 15:15:51 +05:30
worker.perform(create(:issue).id, non_existing_record_id)
2017-09-10 17:25:29 +05:30
end
it 'logs an error' do
2020-04-22 19:07:51 +05:30
issue = create(:issue)
2020-11-24 15:15:51 +05:30
expect(Gitlab::AppLogger).to receive(:error).with("NewIssueWorker: couldn't find User with ID=#{non_existing_record_id}, skipping job")
2017-09-10 17:25:29 +05:30
2020-11-24 15:15:51 +05:30
worker.perform(issue.id, non_existing_record_id)
2017-09-10 17:25:29 +05:30
end
end
context 'when everything is ok' do
2020-11-24 15:15:51 +05:30
let_it_be(:user) { create_default(:user) }
let_it_be(:project) { create(:project, :public) }
let_it_be(:mentioned) { create(:user) }
let_it_be(:issue) { create(:issue, project: project, description: "issue for #{mentioned.to_reference}") }
2017-09-10 17:25:29 +05:30
it 'creates a new event record' do
2018-03-17 18:26:18 +05:30
expect { worker.perform(issue.id, user.id) }.to change { Event.count }.from(0).to(1)
2017-09-10 17:25:29 +05:30
end
2018-03-17 18:26:18 +05:30
it 'creates a notification for the mentioned user' do
expect(Notify).to receive(:new_issue_email).with(mentioned.id, issue.id, NotificationReason::MENTIONED)
2020-11-24 15:15:51 +05:30
.and_return(double(deliver_later: true))
2017-09-10 17:25:29 +05:30
worker.perform(issue.id, user.id)
end
end
end
end