2014-06-17 19:09:01 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-07-10 14:24:02 +00:00
|
|
|
describe Notes::CreateService do
|
2017-08-02 19:55:11 +00:00
|
|
|
let(:project) { create(:project) }
|
2014-06-17 19:09:01 +00:00
|
|
|
let(:issue) { create(:issue, project: project) }
|
|
|
|
let(:user) { create(:user) }
|
2016-06-30 15:34:19 +00:00
|
|
|
let(:opts) do
|
|
|
|
{ note: 'Awesome comment', noteable_type: 'Issue', noteable_id: issue.id }
|
|
|
|
end
|
2014-06-17 19:09:01 +00:00
|
|
|
|
2016-07-11 22:12:31 +00:00
|
|
|
describe '#execute' do
|
2016-08-09 17:26:45 +00:00
|
|
|
before do
|
2017-12-22 08:18:28 +00:00
|
|
|
project.add_master(user)
|
2016-08-09 17:26:45 +00:00
|
|
|
end
|
|
|
|
|
2014-06-17 19:09:01 +00:00
|
|
|
context "valid params" do
|
2016-10-13 15:26:44 +00:00
|
|
|
it 'returns a valid note' do
|
2017-01-20 10:28:40 +00:00
|
|
|
note = described_class.new(project, user, opts).execute
|
2016-10-13 15:26:44 +00:00
|
|
|
|
|
|
|
expect(note).to be_valid
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a persisted note' do
|
2017-01-20 10:28:40 +00:00
|
|
|
note = described_class.new(project, user, opts).execute
|
2016-10-13 15:26:44 +00:00
|
|
|
|
|
|
|
expect(note).to be_persisted
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'note has valid content' do
|
2017-01-20 10:28:40 +00:00
|
|
|
note = described_class.new(project, user, opts).execute
|
2016-10-13 15:26:44 +00:00
|
|
|
|
|
|
|
expect(note.note).to eq(opts[:note])
|
2014-06-17 19:09:01 +00:00
|
|
|
end
|
|
|
|
|
2017-01-05 13:36:06 +00:00
|
|
|
it 'note belongs to the correct project' do
|
2017-01-20 10:28:40 +00:00
|
|
|
note = described_class.new(project, user, opts).execute
|
2017-01-05 13:36:06 +00:00
|
|
|
|
|
|
|
expect(note.project).to eq(project)
|
|
|
|
end
|
|
|
|
|
2016-10-13 15:26:44 +00:00
|
|
|
it 'TodoService#new_note is called' do
|
2017-01-05 13:36:06 +00:00
|
|
|
note = build(:note, project: project)
|
|
|
|
allow(Note).to receive(:new).with(opts) { note }
|
2016-10-13 15:26:44 +00:00
|
|
|
|
|
|
|
expect_any_instance_of(TodoService).to receive(:new_note).with(note, user)
|
|
|
|
|
2017-01-20 10:28:40 +00:00
|
|
|
described_class.new(project, user, opts).execute
|
2016-10-13 15:26:44 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'enqueues NewNoteWorker' do
|
2017-01-05 13:36:06 +00:00
|
|
|
note = build(:note, id: 999, project: project)
|
|
|
|
allow(Note).to receive(:new).with(opts) { note }
|
2016-10-13 15:26:44 +00:00
|
|
|
|
|
|
|
expect(NewNoteWorker).to receive(:perform_async).with(note.id)
|
|
|
|
|
2017-01-20 10:28:40 +00:00
|
|
|
described_class.new(project, user, opts).execute
|
2016-10-13 15:26:44 +00:00
|
|
|
end
|
2016-08-09 17:26:45 +00:00
|
|
|
end
|
2016-06-30 15:34:19 +00:00
|
|
|
|
2016-08-09 17:26:45 +00:00
|
|
|
describe 'note with commands' do
|
|
|
|
describe '/close, /label, /assign & /milestone' do
|
|
|
|
let(:note_text) { %(HELLO\n/close\n/assign @#{user.username}\nWORLD) }
|
2016-06-30 15:34:19 +00:00
|
|
|
|
2016-08-09 17:26:45 +00:00
|
|
|
it 'saves the note and does not alter the note text' do
|
|
|
|
expect_any_instance_of(Issues::UpdateService).to receive(:execute).and_call_original
|
|
|
|
|
|
|
|
note = described_class.new(project, user, opts.merge(note: note_text)).execute
|
2016-06-30 15:34:19 +00:00
|
|
|
|
2016-08-09 17:26:45 +00:00
|
|
|
expect(note.note).to eq "HELLO\nWORLD"
|
|
|
|
end
|
2016-06-30 15:34:19 +00:00
|
|
|
end
|
2016-11-24 14:05:15 +00:00
|
|
|
|
|
|
|
describe '/merge with sha option' do
|
|
|
|
let(:note_text) { %(HELLO\n/merge\nWORLD) }
|
|
|
|
let(:params) { opts.merge(note: note_text, merge_request_diff_head_sha: 'sha') }
|
|
|
|
|
|
|
|
it 'saves the note and exectues merge command' do
|
|
|
|
note = described_class.new(project, user, params).execute
|
|
|
|
|
|
|
|
expect(note.note).to eq "HELLO\nWORLD"
|
|
|
|
end
|
|
|
|
end
|
2014-06-17 19:09:01 +00:00
|
|
|
end
|
2017-01-05 13:36:06 +00:00
|
|
|
|
|
|
|
describe 'personal snippet note' do
|
|
|
|
subject { described_class.new(nil, user, params).execute }
|
|
|
|
|
|
|
|
let(:snippet) { create(:personal_snippet) }
|
|
|
|
let(:params) do
|
|
|
|
{ note: 'comment', noteable_type: 'Snippet', noteable_id: snippet.id }
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a valid note' do
|
|
|
|
expect(subject).to be_valid
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a persisted note' do
|
|
|
|
expect(subject).to be_persisted
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'note has valid content' do
|
|
|
|
expect(subject.note).to eq(params[:note])
|
|
|
|
end
|
|
|
|
end
|
2015-11-19 12:41:05 +00:00
|
|
|
|
2017-02-28 20:38:19 +00:00
|
|
|
describe 'note with emoji only' do
|
|
|
|
it 'creates regular note' do
|
|
|
|
opts = {
|
|
|
|
note: ':smile: ',
|
|
|
|
noteable_type: 'Issue',
|
|
|
|
noteable_id: issue.id
|
|
|
|
}
|
|
|
|
note = described_class.new(project, user, opts).execute
|
2016-05-12 07:23:21 +00:00
|
|
|
|
2017-02-28 20:38:19 +00:00
|
|
|
expect(note).to be_valid
|
|
|
|
expect(note.note).to eq(':smile:')
|
|
|
|
end
|
2016-05-12 07:23:21 +00:00
|
|
|
end
|
2015-11-19 12:41:05 +00:00
|
|
|
end
|
2014-06-17 19:09:01 +00:00
|
|
|
end
|