debian-mirror-gitlab/spec/models/integrations/chat_message/note_message_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

190 lines
5.9 KiB
Ruby
Raw Normal View History

2019-07-07 11:18:12 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
require 'spec_helper'
2021-06-08 01:23:25 +05:30
RSpec.describe Integrations::ChatMessage::NoteMessage do
2017-08-17 22:00:37 +05:30
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',
2017-09-10 17:25:29 +05:30
url: 'http://somewhere.com'
2017-08-17 22:00:37 +05:30
},
2022-01-12 12:59:36 +05:30
commit: {
id: '5f163b2b95e6f53cbd428f5f0b103702a52b9a23',
message: "Added a commit message\ndetails\n123\n"
},
2017-08-17 22:00:37 +05:30
object_attributes: {
id: 10,
note: 'comment on a commit',
url: 'http://url.com',
noteable_type: 'Commit'
}
}
end
2022-01-12 12:59:36 +05:30
it_behaves_like Integrations::ChatMessage
2017-08-17 22:00:37 +05:30
2022-01-12 12:59:36 +05:30
context 'commit notes' do
2017-08-17 22:00:37 +05:30
context 'without markdown' do
it 'returns a message regarding notes on commits' do
2018-03-17 18:26:18 +05:30
expect(subject.pretext).to eq("Test User (test.user) <http://url.com|commented on " \
2017-08-17 22:00:37 +05:30
"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(
2018-03-17 18:26:18 +05:30
'Test User (test.user) [commented on commit 5f163b2b](http://url.com) in [project_name](http://somewhere.com): *Added a commit message*'
2017-08-17 22:00:37 +05:30
)
expect(subject.attachments).to eq('comment on a commit')
expect(subject.activity).to eq({
2018-03-17 18:26:18 +05:30
title: 'Test User (test.user) [commented on commit 5f163b2b](http://url.com)',
2017-08-17 22:00:37 +05:30
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
2018-03-17 18:26:18 +05:30
expect(subject.pretext).to eq("Test User (test.user) <http://url.com|commented on " \
2017-08-17 22:00:37 +05:30
"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(
2018-03-17 18:26:18 +05:30
'Test User (test.user) [commented on merge request !30](http://url.com) in [project_name](http://somewhere.com): *merge request title*')
2017-08-17 22:00:37 +05:30
expect(subject.attachments).to eq('comment on a merge request')
expect(subject.activity).to eq({
2018-03-17 18:26:18 +05:30
title: 'Test User (test.user) [commented on merge request !30](http://url.com)',
2017-08-17 22:00:37 +05:30
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(
2018-03-17 18:26:18 +05:30
"Test User (test.user) <http://url.com|commented on " \
2017-08-17 22:00:37 +05:30
"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(
2018-03-17 18:26:18 +05:30
'Test User (test.user) [commented on issue #20](http://url.com) in [project_name](http://somewhere.com): *issue title*')
2017-08-17 22:00:37 +05:30
expect(subject.attachments).to eq('comment on an issue')
expect(subject.activity).to eq({
2018-03-17 18:26:18 +05:30
title: 'Test User (test.user) [commented on issue #20](http://url.com)',
2017-08-17 22:00:37 +05:30
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
2018-03-17 18:26:18 +05:30
expect(subject.pretext).to eq("Test User (test.user) <http://url.com|commented on " \
2017-08-17 22:00:37 +05:30
"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(
2018-03-17 18:26:18 +05:30
'Test User (test.user) [commented on snippet $5](http://url.com) in [project_name](http://somewhere.com): *snippet title*')
2017-08-17 22:00:37 +05:30
expect(subject.attachments).to eq('comment on a snippet')
end
end
end
end