summaryrefslogtreecommitdiff
path: root/spec/services/notes/create_service_spec.rb
blob: 066461f5a1271c6216d6304a558137f07e6aeb38 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
require 'spec_helper'

describe Notes::CreateService do
  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
        }

        expect(project).to receive(:execute_hooks)
        expect(project).to receive(:execute_services)
        @note = Notes::CreateService.new(project, user, opts).execute
      end

      it { expect(@note).to be_valid }
      it { expect(@note.note).to eq('Awesome comment') }
    end
  end

  describe "award emoji" do
      before do
        project.team << [user, :master]
      end

      it "creates emoji note" do
        opts = {
          note: ':smile: ',
          noteable_type: 'Issue',
          noteable_id: issue.id
        }

        @note = Notes::CreateService.new(project, user, opts).execute

        expect(@note).to be_valid
        expect(@note.note).to eq('smile')
        expect(@note.is_award).to be_truthy
      end

      it "creates regular note if emoji name is invalid" do
        opts = {
          note: ':smile: moretext: ',
          noteable_type: 'Issue',
          noteable_id: issue.id
        }

        @note = Notes::CreateService.new(project, user, opts).execute

        expect(@note).to be_valid
        expect(@note.note).to eq(opts[:note])
        expect(@note.is_award).to be_falsy
      end
  end
end