2015-02-19 05:02:57 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-07-10 14:24:02 +00:00
|
|
|
describe ChatMessage::IssueMessage do
|
2016-11-25 19:36:37 +00:00
|
|
|
subject { described_class.new(args) }
|
2015-02-19 05:02:57 +00:00
|
|
|
|
2015-06-22 20:00:54 +00:00
|
|
|
let(:args) do
|
2015-02-19 05:02:57 +00:00
|
|
|
{
|
|
|
|
user: {
|
2015-03-06 16:31:49 +00:00
|
|
|
name: 'Test User',
|
2017-04-04 15:10:21 +00:00
|
|
|
username: 'test.user',
|
|
|
|
avatar_url: 'http://someavatar.com'
|
2015-02-19 05:02:57 +00:00
|
|
|
},
|
|
|
|
project_name: 'project_name',
|
2016-12-19 12:34:03 +00:00
|
|
|
project_url: 'http://somewhere.com',
|
2015-02-19 05:02:57 +00:00
|
|
|
|
|
|
|
object_attributes: {
|
|
|
|
title: 'Issue title',
|
|
|
|
id: 10,
|
|
|
|
iid: 100,
|
|
|
|
assignee_id: 1,
|
2016-12-19 12:34:03 +00:00
|
|
|
url: 'http://url.com',
|
2015-02-19 05:02:57 +00:00
|
|
|
action: 'open',
|
|
|
|
state: 'opened',
|
|
|
|
description: 'issue description'
|
|
|
|
}
|
|
|
|
}
|
2015-06-22 20:00:54 +00:00
|
|
|
end
|
2015-02-19 05:02:57 +00:00
|
|
|
|
2017-04-04 15:10:21 +00:00
|
|
|
context 'without markdown' do
|
|
|
|
let(:color) { '#C95823' }
|
2015-02-19 05:02:57 +00:00
|
|
|
|
2017-04-04 15:10:21 +00:00
|
|
|
context '#initialize' do
|
|
|
|
before do
|
|
|
|
args[:object_attributes][:description] = nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a non-null description' do
|
|
|
|
expect(subject.description).to eq('')
|
|
|
|
end
|
2016-03-28 11:15:41 +00:00
|
|
|
end
|
|
|
|
|
2017-04-04 15:10:21 +00:00
|
|
|
context 'open' do
|
|
|
|
it 'returns a message regarding opening of issues' do
|
|
|
|
expect(subject.pretext).to eq(
|
2017-10-06 20:00:50 +00:00
|
|
|
'[<http://somewhere.com|project_name>] Issue opened by Test User (test.user)')
|
2017-04-04 15:10:21 +00:00
|
|
|
expect(subject.attachments).to eq([
|
|
|
|
{
|
|
|
|
title: "#100 Issue title",
|
|
|
|
title_link: "http://url.com",
|
|
|
|
text: "issue description",
|
2017-05-03 11:22:03 +00:00
|
|
|
color: color
|
2017-04-04 15:10:21 +00:00
|
|
|
}
|
|
|
|
])
|
|
|
|
end
|
2016-03-28 11:15:41 +00:00
|
|
|
end
|
|
|
|
|
2017-04-04 15:10:21 +00:00
|
|
|
context 'close' do
|
|
|
|
before do
|
|
|
|
args[:object_attributes][:action] = 'close'
|
|
|
|
args[:object_attributes][:state] = 'closed'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a message regarding closing of issues' do
|
|
|
|
expect(subject.pretext). to eq(
|
2017-10-06 20:00:50 +00:00
|
|
|
'[<http://somewhere.com|project_name>] Issue <http://url.com|#100 Issue title> closed by Test User (test.user)')
|
2017-04-04 15:10:21 +00:00
|
|
|
expect(subject.attachments).to be_empty
|
|
|
|
end
|
2015-02-19 05:02:57 +00:00
|
|
|
end
|
2017-11-06 13:48:34 +00:00
|
|
|
|
|
|
|
context 'reopen' do
|
|
|
|
before do
|
|
|
|
args[:object_attributes][:action] = 'reopen'
|
|
|
|
args[:object_attributes][:state] = 'opened'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a message regarding reopening of issues' do
|
|
|
|
expect(subject.pretext)
|
|
|
|
.to eq('[<http://somewhere.com|project_name>] Issue <http://url.com|#100 Issue title> opened by Test User (test.user)')
|
|
|
|
expect(subject.attachments).to be_empty
|
|
|
|
end
|
|
|
|
end
|
2015-02-19 05:02:57 +00:00
|
|
|
end
|
|
|
|
|
2017-04-04 15:10:21 +00:00
|
|
|
context 'with markdown' do
|
2015-02-19 05:02:57 +00:00
|
|
|
before do
|
2017-04-04 15:10:21 +00:00
|
|
|
args[:markdown] = true
|
2015-02-19 05:02:57 +00:00
|
|
|
end
|
2015-09-16 11:19:46 +00:00
|
|
|
|
2017-04-04 15:10:21 +00:00
|
|
|
context 'open' do
|
|
|
|
it 'returns a message regarding opening of issues' do
|
|
|
|
expect(subject.pretext).to eq(
|
2017-10-06 20:00:50 +00:00
|
|
|
'[[project_name](http://somewhere.com)] Issue opened by Test User (test.user)')
|
2017-04-04 15:10:21 +00:00
|
|
|
expect(subject.attachments).to eq('issue description')
|
|
|
|
expect(subject.activity).to eq({
|
2017-10-06 20:00:50 +00:00
|
|
|
title: 'Issue opened by Test User (test.user)',
|
2017-04-04 15:10:21 +00:00
|
|
|
subtitle: 'in [project_name](http://somewhere.com)',
|
|
|
|
text: '[#100 Issue title](http://url.com)',
|
|
|
|
image: 'http://someavatar.com'
|
|
|
|
})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'close' do
|
|
|
|
before do
|
|
|
|
args[:object_attributes][:action] = 'close'
|
|
|
|
args[:object_attributes][:state] = 'closed'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a message regarding closing of issues' do
|
|
|
|
expect(subject.pretext). to eq(
|
2017-10-06 20:00:50 +00:00
|
|
|
'[[project_name](http://somewhere.com)] Issue [#100 Issue title](http://url.com) closed by Test User (test.user)')
|
2017-04-04 15:10:21 +00:00
|
|
|
expect(subject.attachments).to be_empty
|
|
|
|
expect(subject.activity).to eq({
|
2017-10-06 20:00:50 +00:00
|
|
|
title: 'Issue closed by Test User (test.user)',
|
2017-04-04 15:10:21 +00:00
|
|
|
subtitle: 'in [project_name](http://somewhere.com)',
|
|
|
|
text: '[#100 Issue title](http://url.com)',
|
|
|
|
image: 'http://someavatar.com'
|
|
|
|
})
|
|
|
|
end
|
2015-02-19 05:02:57 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|