2019-03-30 03:15:48 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-10-13 11:26:44 -04:00
|
|
|
require "spec_helper"
|
|
|
|
|
|
|
|
describe NewNoteWorker do
|
|
|
|
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
|
|
|
|
let(:unexistent_note_id) { 999 }
|
|
|
|
|
|
|
|
it 'logs NewNoteWorker process skipping' do
|
2017-06-21 09:48:12 -04:00
|
|
|
expect(Rails.logger).to receive(:error)
|
|
|
|
.with("NewNoteWorker: couldn't find note with ID=999, 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
|
|
|
|
end
|