2019-03-30 03:15:48 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-10-13 11:26:44 -04:00
|
|
|
require "spec_helper"
|
|
|
|
|
2020-06-24 11:08:50 -04:00
|
|
|
RSpec.describe NewNoteWorker do
|
2016-10-13 11:26:44 -04:00
|
|
|
context 'when Note found' do
|
|
|
|
let(:note) { create(:note) }
|
|
|
|
|
|
|
|
it "calls NotificationService#new_note" do
|
2019-11-14 01:06:26 -05:00
|
|
|
expect_next_instance_of(NotificationService) do |service|
|
|
|
|
expect(service).to receive(:new_note).with(note)
|
|
|
|
end
|
2016-10-13 11:26:44 -04:00
|
|
|
|
|
|
|
described_class.new.perform(note.id)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "calls Notes::PostProcessService#execute" do
|
2019-11-14 01:06:26 -05:00
|
|
|
expect_next_instance_of(Notes::PostProcessService) do |service|
|
|
|
|
expect(service).to receive(:execute)
|
|
|
|
end
|
2016-10-13 11:26:44 -04:00
|
|
|
|
|
|
|
described_class.new.perform(note.id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when Note not found' do
|
2020-04-01 11:07:45 -04:00
|
|
|
let(:unexistent_note_id) { non_existing_record_id }
|
2016-10-13 11:26:44 -04:00
|
|
|
|
|
|
|
it 'logs NewNoteWorker process skipping' do
|
2020-05-21 17:08:31 -04:00
|
|
|
expect(Gitlab::AppLogger).to receive(:error)
|
2020-04-01 11:07:45 -04:00
|
|
|
.with("NewNoteWorker: couldn't find note with ID=#{unexistent_note_id}, skipping job")
|
2016-10-13 11:26:44 -04:00
|
|
|
|
|
|
|
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-11-14 01:06:26 -05:00
|
|
|
it "does not call NotificationService" do
|
|
|
|
expect(NotificationService).not_to receive(:new)
|
2016-10-13 11:26:44 -04:00
|
|
|
|
|
|
|
described_class.new.perform(unexistent_note_id)
|
|
|
|
end
|
|
|
|
|
2019-11-14 01:06:26 -05:00
|
|
|
it "does not call Notes::PostProcessService" do
|
|
|
|
expect(Notes::PostProcessService).not_to receive(:new)
|
2016-10-13 11:26:44 -04:00
|
|
|
|
|
|
|
described_class.new.perform(unexistent_note_id)
|
|
|
|
end
|
|
|
|
end
|
2020-05-28 05:08:05 -04:00
|
|
|
|
2020-08-28 05:10:32 -04:00
|
|
|
context 'when note does not require notification' do
|
|
|
|
let(:note) { create(:note) }
|
2020-05-28 05:08:05 -04:00
|
|
|
|
2020-08-28 05:10:32 -04:00
|
|
|
before do
|
2020-09-01 05:10:28 -04:00
|
|
|
allow_next_found_instance_of(Note) do |note|
|
|
|
|
allow(note).to receive(:skip_notification?).and_return(true)
|
|
|
|
end
|
2020-08-28 05:10:32 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not create a new note notification' do
|
2020-05-28 05:08:05 -04:00
|
|
|
expect_any_instance_of(NotificationService).not_to receive(:new_note)
|
|
|
|
|
|
|
|
subject.perform(note.id)
|
|
|
|
end
|
|
|
|
end
|
2021-02-09 07:09:48 -05:00
|
|
|
|
2021-02-09 22:09:31 -05:00
|
|
|
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
|
|
|
|
|
2021-02-09 07:09:48 -05:00
|
|
|
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
|
2016-10-13 11:26:44 -04:00
|
|
|
end
|