gitlab-org--gitlab-foss/spec/services/notes/create_service_spec.rb

60 lines
1.4 KiB
Ruby
Raw Normal View History

2014-06-17 19:09:01 +00:00
require 'spec_helper'
2015-12-09 10:55:49 +00:00
describe Notes::CreateService, services: true do
2014-06-17 19:09:01 +00:00
let(:project) { create(:empty_project) }
let(:issue) { create(:issue, project: project) }
let(:user) { create(:user) }
describe :execute do
context "valid params" do
before do
project.team << [user, :master]
opts = {
note: 'Awesome comment',
noteable_type: 'Issue',
noteable_id: issue.id
}
2016-01-28 18:04:24 +00:00
2014-06-17 19:09:01 +00:00
@note = Notes::CreateService.new(project, user, opts).execute
end
it { expect(@note).to be_valid }
it { expect(@note.note).to eq('Awesome comment') }
2014-06-17 19:09:01 +00:00
end
end
2015-11-19 12:41:05 +00:00
describe "award emoji" do
2015-11-19 21:00:30 +00:00
before do
project.team << [user, :master]
end
2015-11-19 12:41:05 +00:00
2015-11-19 21:00:30 +00:00
it "creates emoji note" do
opts = {
note: ':smile: ',
noteable_type: 'Issue',
noteable_id: issue.id
}
2015-11-19 12:41:05 +00:00
2015-11-19 21:00:30 +00:00
@note = Notes::CreateService.new(project, user, opts).execute
2015-11-19 12:41:05 +00:00
2015-11-19 21:00:30 +00:00
expect(@note).to be_valid
expect(@note.note).to eq('smile')
expect(@note.is_award).to be_truthy
end
2015-11-19 12:41:05 +00:00
2015-11-19 21:00:30 +00:00
it "creates regular note if emoji name is invalid" do
opts = {
note: ':smile: moretext: ',
noteable_type: 'Issue',
noteable_id: issue.id
}
2015-11-19 12:41:05 +00:00
2015-11-19 21:00:30 +00:00
@note = Notes::CreateService.new(project, user, opts).execute
2015-11-19 12:41:05 +00:00
2015-11-19 21:00:30 +00:00
expect(@note).to be_valid
expect(@note.note).to eq(opts[:note])
expect(@note.is_award).to be_falsy
end
2015-11-19 12:41:05 +00:00
end
2014-06-17 19:09:01 +00:00
end