2019-04-11 08:17:24 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-01-28 13:04:24 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 11:08:50 -04:00
|
|
|
RSpec.describe Notes::PostProcessService do
|
2017-08-02 15:55:11 -04:00
|
|
|
let(:project) { create(:project) }
|
2016-01-28 13:04:24 -05:00
|
|
|
let(:issue) { create(:issue, project: project) }
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
2016-07-11 18:12:31 -04:00
|
|
|
describe '#execute' do
|
2016-01-28 13:04:24 -05:00
|
|
|
before do
|
2018-07-11 10:36:08 -04:00
|
|
|
project.add_maintainer(user)
|
2016-01-28 13:04:24 -05:00
|
|
|
note_opts = {
|
|
|
|
note: 'Awesome comment',
|
|
|
|
noteable_type: 'Issue',
|
|
|
|
noteable_id: issue.id
|
|
|
|
}
|
|
|
|
|
|
|
|
@note = Notes::CreateService.new(project, user, note_opts).execute
|
|
|
|
end
|
|
|
|
|
2016-01-28 13:23:37 -05:00
|
|
|
it do
|
2016-01-28 13:04:24 -05:00
|
|
|
expect(project).to receive(:execute_hooks)
|
2021-06-30 02:07:17 -04:00
|
|
|
expect(project).to receive(:execute_integrations)
|
2016-02-18 18:53:22 -05:00
|
|
|
|
2017-07-25 13:09:00 -04:00
|
|
|
described_class.new(@note).execute
|
2016-01-28 13:23:37 -05:00
|
|
|
end
|
2018-04-03 07:00:33 -04:00
|
|
|
|
|
|
|
context 'with a confidential issue' do
|
|
|
|
let(:issue) { create(:issue, :confidential, project: project) }
|
|
|
|
|
2021-06-30 02:07:17 -04:00
|
|
|
it "doesn't call note hooks/integrations" do
|
2018-04-03 07:00:33 -04:00
|
|
|
expect(project).not_to receive(:execute_hooks).with(anything, :note_hooks)
|
2021-06-30 02:07:17 -04:00
|
|
|
expect(project).not_to receive(:execute_integrations).with(anything, :note_hooks)
|
2018-04-03 07:00:33 -04:00
|
|
|
|
|
|
|
described_class.new(@note).execute
|
|
|
|
end
|
|
|
|
|
2021-06-30 02:07:17 -04:00
|
|
|
it "calls confidential-note hooks/integrations" do
|
2018-04-03 07:00:33 -04:00
|
|
|
expect(project).to receive(:execute_hooks).with(anything, :confidential_note_hooks)
|
2021-06-30 02:07:17 -04:00
|
|
|
expect(project).to receive(:execute_integrations).with(anything, :confidential_note_hooks)
|
2018-04-03 07:00:33 -04:00
|
|
|
|
|
|
|
described_class.new(@note).execute
|
|
|
|
end
|
|
|
|
end
|
2020-05-13 14:08:47 -04:00
|
|
|
|
|
|
|
context 'when the noteable is a design' do
|
|
|
|
let_it_be(:noteable) { create(:design, :with_file) }
|
|
|
|
let_it_be(:discussion_note) { create_note }
|
|
|
|
|
|
|
|
subject { described_class.new(note).execute }
|
|
|
|
|
|
|
|
def create_note(in_reply_to: nil)
|
|
|
|
create(:diff_note_on_design, noteable: noteable, in_reply_to: in_reply_to)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the note is the start of a new discussion' do
|
|
|
|
let(:note) { discussion_note }
|
|
|
|
|
|
|
|
it 'creates a new system note' do
|
|
|
|
expect { subject }.to change { Note.system.count }.by(1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the note is a reply within a discussion' do
|
|
|
|
let_it_be(:note) { create_note(in_reply_to: discussion_note) }
|
|
|
|
|
|
|
|
it 'does not create a new system note' do
|
|
|
|
expect { subject }.not_to change { Note.system.count }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-01-28 13:04:24 -05:00
|
|
|
end
|
|
|
|
end
|