2015-04-26 12:48:37 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2015-12-23 02:04:40 +05:30
|
|
|
describe SlackService::IssueMessage, models: true do
|
2015-04-26 12:48:37 +05:30
|
|
|
subject { SlackService::IssueMessage.new(args) }
|
|
|
|
|
2015-09-11 14:41:01 +05:30
|
|
|
let(:args) do
|
2015-04-26 12:48:37 +05:30
|
|
|
{
|
|
|
|
user: {
|
|
|
|
name: 'Test User',
|
|
|
|
username: 'Test User'
|
|
|
|
},
|
|
|
|
project_name: 'project_name',
|
|
|
|
project_url: 'somewhere.com',
|
|
|
|
|
|
|
|
object_attributes: {
|
|
|
|
title: 'Issue title',
|
|
|
|
id: 10,
|
|
|
|
iid: 100,
|
|
|
|
assignee_id: 1,
|
|
|
|
url: 'url',
|
|
|
|
action: 'open',
|
|
|
|
state: 'opened',
|
|
|
|
description: 'issue description'
|
|
|
|
}
|
|
|
|
}
|
2015-09-11 14:41:01 +05:30
|
|
|
end
|
2015-04-26 12:48:37 +05:30
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
let(:color) { '#C95823' }
|
|
|
|
|
|
|
|
context '#initialize' do
|
|
|
|
before do
|
|
|
|
args[:object_attributes][:description] = nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a non-null description' do
|
|
|
|
expect(subject.description).to eq('')
|
|
|
|
end
|
|
|
|
end
|
2015-04-26 12:48:37 +05:30
|
|
|
|
|
|
|
context 'open' do
|
|
|
|
it 'returns a message regarding opening of issues' do
|
|
|
|
expect(subject.pretext).to eq(
|
2016-06-02 11:05:42 +05:30
|
|
|
'<somewhere.com|[project_name>] Issue opened by Test User')
|
2015-04-26 12:48:37 +05:30
|
|
|
expect(subject.attachments).to eq([
|
|
|
|
{
|
2016-06-02 11:05:42 +05:30
|
|
|
title: "#100 Issue title",
|
|
|
|
title_link: "url",
|
2015-04-26 12:48:37 +05:30
|
|
|
text: "issue description",
|
|
|
|
color: color,
|
|
|
|
}
|
|
|
|
])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'close' do
|
|
|
|
before do
|
|
|
|
args[:object_attributes][:action] = 'close'
|
|
|
|
args[:object_attributes][:state] = 'closed'
|
|
|
|
end
|
2016-06-02 11:05:42 +05:30
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
it 'returns a message regarding closing of issues' do
|
|
|
|
expect(subject.pretext). to eq(
|
2016-06-02 11:05:42 +05:30
|
|
|
'<somewhere.com|[project_name>] Issue <url|#100 Issue title> closed by Test User')
|
2015-04-26 12:48:37 +05:30
|
|
|
expect(subject.attachments).to be_empty
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|