blob: 7ba3fe942542a09dd85a916a29017cdc6457cab2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
# frozen_string_literal: true
require "spec_helper"
RSpec.describe NewNoteWorker do
context 'when Note found' do
let(:note) { create(:note) }
it "calls NotificationService#new_note" do
expect_next_instance_of(NotificationService) do |service|
expect(service).to receive(:new_note).with(note)
end
described_class.new.perform(note.id)
end
it "calls Notes::PostProcessService#execute" do
expect_next_instance_of(Notes::PostProcessService) do |service|
expect(service).to receive(:execute)
end
described_class.new.perform(note.id)
end
end
context 'when Note not found' do
let(:unexistent_note_id) { non_existing_record_id }
it 'logs NewNoteWorker process skipping' do
expect(Gitlab::AppLogger).to receive(:error)
.with("NewNoteWorker: couldn't find note with ID=#{unexistent_note_id}, skipping job")
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
it "does not call NotificationService" do
expect(NotificationService).not_to receive(:new)
described_class.new.perform(unexistent_note_id)
end
it "does not call Notes::PostProcessService" do
expect(Notes::PostProcessService).not_to receive(:new)
described_class.new.perform(unexistent_note_id)
end
end
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
it 'does not create a new note notification' do
expect_any_instance_of(NotificationService).not_to receive(:new_note)
subject.perform(note.id)
end
end
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
end
|