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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Integrations::ChatMessage::NoteMessage do
subject { described_class.new(args) }
let(:color) { '#345' }
let(:args) do
{
user: {
name: 'Test User',
username: 'test.user',
avatar_url: 'http://fakeavatar'
},
project_name: 'project_name',
project_url: 'http://somewhere.com',
repository: {
name: 'project_name',
url: 'http://somewhere.com'
},
object_attributes: {
id: 10,
note: 'comment on a commit',
url: 'http://url.com',
noteable_type: 'Commit'
}
}
end
context 'commit notes' do
before do
args[:object_attributes][:note] = 'comment on a commit'
args[:object_attributes][:noteable_type] = 'Commit'
args[:commit] = {
id: '5f163b2b95e6f53cbd428f5f0b103702a52b9a23',
message: "Added a commit message\ndetails\n123\n"
}
end
context 'without markdown' do
it 'returns a message regarding notes on commits' do
expect(subject.pretext).to eq("Test User (test.user) <http://url.com|commented on " \
"commit 5f163b2b> in <http://somewhere.com|project_name>: " \
"*Added a commit message*")
expect(subject.attachments).to eq([{
text: 'comment on a commit',
color: color
}])
end
end
context 'with markdown' do
before do
args[:markdown] = true
end
it 'returns a message regarding notes on commits' do
expect(subject.pretext).to eq(
'Test User (test.user) [commented on commit 5f163b2b](http://url.com) in [project_name](http://somewhere.com): *Added a commit message*'
)
expect(subject.attachments).to eq('comment on a commit')
expect(subject.activity).to eq({
title: 'Test User (test.user) [commented on commit 5f163b2b](http://url.com)',
subtitle: 'in [project_name](http://somewhere.com)',
text: 'Added a commit message',
image: 'http://fakeavatar'
})
end
end
end
context 'merge request notes' do
before do
args[:object_attributes][:note] = 'comment on a merge request'
args[:object_attributes][:noteable_type] = 'MergeRequest'
args[:merge_request] = {
id: 1,
iid: 30,
title: "merge request title\ndetails\n"
}
end
context 'without markdown' do
it 'returns a message regarding notes on a merge request' do
expect(subject.pretext).to eq("Test User (test.user) <http://url.com|commented on " \
"merge request !30> in <http://somewhere.com|project_name>: " \
"*merge request title*")
expect(subject.attachments).to eq([{
text: 'comment on a merge request',
color: color
}])
end
end
context 'with markdown' do
before do
args[:markdown] = true
end
it 'returns a message regarding notes on a merge request' do
expect(subject.pretext).to eq(
'Test User (test.user) [commented on merge request !30](http://url.com) in [project_name](http://somewhere.com): *merge request title*')
expect(subject.attachments).to eq('comment on a merge request')
expect(subject.activity).to eq({
title: 'Test User (test.user) [commented on merge request !30](http://url.com)',
subtitle: 'in [project_name](http://somewhere.com)',
text: 'merge request title',
image: 'http://fakeavatar'
})
end
end
end
context 'issue notes' do
before do
args[:object_attributes][:note] = 'comment on an issue'
args[:object_attributes][:noteable_type] = 'Issue'
args[:issue] = {
id: 1,
iid: 20,
title: "issue title\ndetails\n"
}
end
context 'without markdown' do
it 'returns a message regarding notes on an issue' do
expect(subject.pretext).to eq(
"Test User (test.user) <http://url.com|commented on " \
"issue #20> in <http://somewhere.com|project_name>: " \
"*issue title*")
expect(subject.attachments).to eq([{
text: 'comment on an issue',
color: color
}])
end
end
context 'with markdown' do
before do
args[:markdown] = true
end
it 'returns a message regarding notes on an issue' do
expect(subject.pretext).to eq(
'Test User (test.user) [commented on issue #20](http://url.com) in [project_name](http://somewhere.com): *issue title*')
expect(subject.attachments).to eq('comment on an issue')
expect(subject.activity).to eq({
title: 'Test User (test.user) [commented on issue #20](http://url.com)',
subtitle: 'in [project_name](http://somewhere.com)',
text: 'issue title',
image: 'http://fakeavatar'
})
end
end
end
context 'project snippet notes' do
before do
args[:object_attributes][:note] = 'comment on a snippet'
args[:object_attributes][:noteable_type] = 'Snippet'
args[:snippet] = {
id: 5,
title: "snippet title\ndetails\n"
}
end
context 'without markdown' do
it 'returns a message regarding notes on a project snippet' do
expect(subject.pretext).to eq("Test User (test.user) <http://url.com|commented on " \
"snippet $5> in <http://somewhere.com|project_name>: " \
"*snippet title*")
expect(subject.attachments).to eq([{
text: 'comment on a snippet',
color: color
}])
end
end
context 'with markdown' do
before do
args[:markdown] = true
end
it 'returns a message regarding notes on a project snippet' do
expect(subject.pretext).to eq(
'Test User (test.user) [commented on snippet $5](http://url.com) in [project_name](http://somewhere.com): *snippet title*')
expect(subject.attachments).to eq('comment on a snippet')
end
end
end
end
|