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
|
|
|
|
|
|
|
context 'when note is with review' do
|
|
|
|
it 'does not create a new note notification' do
|
|
|
|
note = create(:note, :with_review)
|
|
|
|
|
|
|
|
expect_any_instance_of(NotificationService).not_to receive(:new_note)
|
|
|
|
|
|
|
|
subject.perform(note.id)
|
|
|
|
end
|
|
|
|
end
|
2016-10-13 11:26:44 -04:00
|
|
|
end
|