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

89 lines
2.4 KiB
Ruby
Raw Normal View History

2019-07-07 11:18:12 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
require "spec_helper"
2020-07-28 23:09:34 +05:30
RSpec.describe NewNoteWorker do
2017-08-17 22:00:37 +05:30
context 'when Note found' do
let(:note) { create(:note) }
it "calls NotificationService#new_note" do
2019-12-26 22:10:19 +05:30
expect_next_instance_of(NotificationService) do |service|
expect(service).to receive(:new_note).with(note)
end
2017-08-17 22:00:37 +05:30
described_class.new.perform(note.id)
end
it "calls Notes::PostProcessService#execute" do
2019-12-26 22:10:19 +05:30
expect_next_instance_of(Notes::PostProcessService) do |service|
expect(service).to receive(:execute)
end
2017-08-17 22:00:37 +05:30
described_class.new.perform(note.id)
end
end
context 'when Note not found' do
2020-04-22 19:07:51 +05:30
let(:unexistent_note_id) { non_existing_record_id }
2017-08-17 22:00:37 +05:30
it 'logs NewNoteWorker process skipping' do
2020-06-23 00:09:42 +05:30
expect(Gitlab::AppLogger).to receive(:error)
2020-04-22 19:07:51 +05:30
.with("NewNoteWorker: couldn't find note with ID=#{unexistent_note_id}, skipping job")
2017-08-17 22:00:37 +05:30
described_class.new.perform(unexistent_note_id)
end
it 'does not raise errors' do
expect { described_class.new.perform(unexistent_note_id) }.not_to raise_error
end
2019-12-26 22:10:19 +05:30
it "does not call NotificationService" do
expect(NotificationService).not_to receive(:new)
2017-08-17 22:00:37 +05:30
described_class.new.perform(unexistent_note_id)
end
2019-12-26 22:10:19 +05:30
it "does not call Notes::PostProcessService" do
expect(Notes::PostProcessService).not_to receive(:new)
2017-08-17 22:00:37 +05:30
described_class.new.perform(unexistent_note_id)
end
end
2020-06-23 00:09:42 +05:30
2020-11-24 15:15:51 +05:30
context 'when note does not require notification' do
let(:note) { create(:note) }
before do
allow_next_found_instance_of(Note) do |note|
allow(note).to receive(:skip_notification?).and_return(true)
end
end
2020-06-23 00:09:42 +05:30
2020-11-24 15:15:51 +05:30
it 'does not create a new note notification' do
2020-06-23 00:09:42 +05:30
expect_any_instance_of(NotificationService).not_to receive(:new_note)
subject.perform(note.id)
end
end
2021-03-11 19:13:27 +05:30
context 'when Note author has been blocked' do
let_it_be(:note) { create(:note, author: create(:user, :blocked)) }
it "does not call NotificationService" do
expect(NotificationService).not_to receive(:new)
described_class.new.perform(note.id)
end
end
context 'when Note author has been deleted' do
let_it_be(:note) { create(:note, author: User.ghost) }
it "does not call NotificationService" do
expect(NotificationService).not_to receive(:new)
described_class.new.perform(note.id)
end
end
2017-08-17 22:00:37 +05:30
end