2014-09-02 18:07:02 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
describe Notes::CreateService do
|
|
|
|
let(:project) { create(:project) }
|
2014-09-02 18:07:02 +05:30
|
|
|
let(:issue) { create(:issue, project: project) }
|
|
|
|
let(:user) { create(:user) }
|
2016-09-13 17:45:13 +05:30
|
|
|
let(:opts) do
|
|
|
|
{ note: 'Awesome comment', noteable_type: 'Issue', noteable_id: issue.id }
|
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
|
2016-08-24 12:49:21 +05:30
|
|
|
describe '#execute' do
|
2016-09-13 17:45:13 +05:30
|
|
|
before do
|
2018-03-17 18:26:18 +05:30
|
|
|
project.add_master(user)
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
|
|
|
|
2014-09-02 18:07:02 +05:30
|
|
|
context "valid params" do
|
2017-08-17 22:00:37 +05:30
|
|
|
it 'returns a valid note' do
|
|
|
|
note = described_class.new(project, user, opts).execute
|
|
|
|
|
|
|
|
expect(note).to be_valid
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
it 'returns a persisted note' do
|
|
|
|
note = described_class.new(project, user, opts).execute
|
|
|
|
|
|
|
|
expect(note).to be_persisted
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'note has valid content' do
|
|
|
|
note = described_class.new(project, user, opts).execute
|
|
|
|
|
|
|
|
expect(note.note).to eq(opts[:note])
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'note belongs to the correct project' do
|
|
|
|
note = described_class.new(project, user, opts).execute
|
|
|
|
|
|
|
|
expect(note.project).to eq(project)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'TodoService#new_note is called' do
|
|
|
|
note = build(:note, project: project)
|
|
|
|
allow(Note).to receive(:new).with(opts) { note }
|
|
|
|
|
|
|
|
expect_any_instance_of(TodoService).to receive(:new_note).with(note, user)
|
|
|
|
|
|
|
|
described_class.new(project, user, opts).execute
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'enqueues NewNoteWorker' do
|
|
|
|
note = build(:note, id: 999, project: project)
|
|
|
|
allow(Note).to receive(:new).with(opts) { note }
|
|
|
|
|
|
|
|
expect(NewNoteWorker).to receive(:perform_async).with(note.id)
|
|
|
|
|
|
|
|
described_class.new(project, user, opts).execute
|
|
|
|
end
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
describe 'note with commands' do
|
|
|
|
describe '/close, /label, /assign & /milestone' do
|
|
|
|
let(:note_text) { %(HELLO\n/close\n/assign @#{user.username}\nWORLD) }
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
expect(note.note).to eq "HELLO\nWORLD"
|
|
|
|
end
|
|
|
|
end
|
2015-11-26 14:37:03 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
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') }
|
2015-11-26 14:37:03 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
it 'saves the note and exectues merge command' do
|
|
|
|
note = described_class.new(project, user, params).execute
|
2015-11-26 14:37:03 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(note.note).to eq "HELLO\nWORLD"
|
|
|
|
end
|
|
|
|
end
|
2015-11-26 14:37:03 +05:30
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
describe 'personal snippet note' do
|
|
|
|
subject { described_class.new(nil, user, params).execute }
|
2016-06-16 23:09:34 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
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
|
2016-06-16 23:09:34 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
it 'returns a persisted note' do
|
|
|
|
expect(subject).to be_persisted
|
|
|
|
end
|
2015-11-26 14:37:03 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
it 'note has valid content' do
|
|
|
|
expect(subject.note).to eq(params[:note])
|
|
|
|
end
|
|
|
|
end
|
2015-11-26 14:37:03 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
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
|
|
|
|
|
|
|
|
expect(note).to be_valid
|
|
|
|
expect(note.note).to eq(':smile:')
|
|
|
|
end
|
2015-11-26 14:37:03 +05:30
|
|
|
end
|
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|