2014-06-17 15:09:01 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2015-12-09 05:55:49 -05:00
|
|
|
describe Notes::CreateService, services: true do
|
2014-06-17 15:09:01 -04:00
|
|
|
let(:project) { create(:empty_project) }
|
|
|
|
let(:issue) { create(:issue, project: project) }
|
|
|
|
let(:user) { create(:user) }
|
2016-06-30 11:34:19 -04:00
|
|
|
let(:opts) do
|
|
|
|
{ note: 'Awesome comment', noteable_type: 'Issue', noteable_id: issue.id }
|
|
|
|
end
|
2014-06-17 15:09:01 -04:00
|
|
|
|
2016-07-11 18:12:31 -04:00
|
|
|
describe '#execute' do
|
2016-08-09 13:26:45 -04:00
|
|
|
before do
|
|
|
|
project.team << [user, :master]
|
|
|
|
end
|
|
|
|
|
2014-06-17 15:09:01 -04:00
|
|
|
context "valid params" do
|
|
|
|
before do
|
|
|
|
@note = Notes::CreateService.new(project, user, opts).execute
|
|
|
|
end
|
|
|
|
|
2015-02-12 13:17:35 -05:00
|
|
|
it { expect(@note).to be_valid }
|
2016-06-30 11:34:19 -04:00
|
|
|
it { expect(@note.note).to eq(opts[:note]) }
|
2016-08-09 13:26:45 -04:00
|
|
|
end
|
2016-06-30 11:34:19 -04:00
|
|
|
|
2016-08-09 13:26:45 -04: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 11:34:19 -04:00
|
|
|
|
2016-08-09 13:26:45 -04: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 11:34:19 -04:00
|
|
|
|
2016-08-09 13:26:45 -04:00
|
|
|
expect(note.note).to eq "HELLO\nWORLD"
|
|
|
|
end
|
2016-06-30 11:34:19 -04:00
|
|
|
end
|
2014-06-17 15:09:01 -04:00
|
|
|
end
|
|
|
|
end
|
2015-11-19 07:41:05 -05:00
|
|
|
|
|
|
|
describe "award emoji" do
|
2015-11-19 16:00:30 -05:00
|
|
|
before do
|
|
|
|
project.team << [user, :master]
|
|
|
|
end
|
2015-11-19 07:41:05 -05:00
|
|
|
|
2016-04-25 14:10:20 -04:00
|
|
|
it "creates an award emoji" do
|
2015-11-19 16:00:30 -05:00
|
|
|
opts = {
|
|
|
|
note: ':smile: ',
|
|
|
|
noteable_type: 'Issue',
|
|
|
|
noteable_id: issue.id
|
|
|
|
}
|
2016-04-25 14:10:20 -04:00
|
|
|
note = Notes::CreateService.new(project, user, opts).execute
|
2015-11-19 07:41:05 -05:00
|
|
|
|
2016-04-25 14:10:20 -04:00
|
|
|
expect(note).to be_valid
|
|
|
|
expect(note.name).to eq('smile')
|
2015-11-19 16:00:30 -05:00
|
|
|
end
|
2015-11-19 07:41:05 -05:00
|
|
|
|
2015-11-19 16:00:30 -05:00
|
|
|
it "creates regular note if emoji name is invalid" do
|
|
|
|
opts = {
|
2016-08-13 12:58:51 -04:00
|
|
|
note: ':smile: moretext:',
|
2015-11-19 16:00:30 -05:00
|
|
|
noteable_type: 'Issue',
|
|
|
|
noteable_id: issue.id
|
|
|
|
}
|
2016-04-25 14:10:20 -04:00
|
|
|
note = Notes::CreateService.new(project, user, opts).execute
|
2015-11-19 07:41:05 -05:00
|
|
|
|
2016-04-25 14:10:20 -04:00
|
|
|
expect(note).to be_valid
|
|
|
|
expect(note.note).to eq(opts[:note])
|
2015-11-19 16:00:30 -05:00
|
|
|
end
|
2016-05-12 03:23:21 -04:00
|
|
|
|
|
|
|
it "normalizes the emoji name" do
|
|
|
|
opts = {
|
|
|
|
note: ':+1:',
|
|
|
|
noteable_type: 'Issue',
|
|
|
|
noteable_id: issue.id
|
|
|
|
}
|
|
|
|
|
2016-05-17 13:28:17 -04:00
|
|
|
expect_any_instance_of(TodoService).to receive(:new_award_emoji).with(issue, user)
|
2016-05-12 03:23:21 -04:00
|
|
|
|
|
|
|
Notes::CreateService.new(project, user, opts).execute
|
|
|
|
end
|
2015-11-19 07:41:05 -05:00
|
|
|
end
|
2014-06-17 15:09:01 -04:00
|
|
|
end
|