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

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

127 lines
3.7 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::IssueMessage do
2017-08-17 22:00:37 +05:30
subject { described_class.new(args) }
let(:args) do
{
user: {
name: 'Test User',
username: 'test.user',
avatar_url: 'http://someavatar.com'
},
project_name: 'project_name',
project_url: 'http://somewhere.com',
object_attributes: {
title: 'Issue title',
id: 10,
iid: 100,
assignee_id: 1,
url: 'http://url.com',
action: 'open',
state: 'opened',
description: 'issue description'
}
}
end
2022-01-12 12:59:36 +05:30
it_behaves_like Integrations::ChatMessage
2017-08-17 22:00:37 +05:30
context 'without markdown' do
let(:color) { '#C95823' }
2020-03-13 15:44:24 +05:30
describe '#initialize' do
2017-08-17 22:00:37 +05:30
before do
args[:object_attributes][:description] = nil
end
it 'returns a non-null description' do
expect(subject.description).to eq('')
end
end
context 'open' do
it 'returns a message regarding opening of issues' do
expect(subject.pretext).to eq(
2021-01-03 14:25:43 +05:30
'[<http://somewhere.com|project_name>] Issue <http://url.com|#100 Issue title> opened by Test User (test.user)')
2017-08-17 22:00:37 +05:30
expect(subject.attachments).to eq([
{
title: "#100 Issue title",
title_link: "http://url.com",
text: "issue description",
2017-09-10 17:25:29 +05:30
color: color
2017-08-17 22:00:37 +05:30
}
])
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(
2018-03-17 18:26:18 +05:30
'[<http://somewhere.com|project_name>] Issue <http://url.com|#100 Issue title> closed by Test User (test.user)')
expect(subject.attachments).to be_empty
end
end
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)')
2017-08-17 22:00:37 +05:30
expect(subject.attachments).to be_empty
end
end
end
context 'with markdown' do
before do
args[:markdown] = true
end
context 'open' do
it 'returns a message regarding opening of issues' do
expect(subject.pretext).to eq(
2021-01-03 14:25:43 +05:30
'[[project_name](http://somewhere.com)] Issue [#100 Issue title](http://url.com) opened by Test User (test.user)')
2017-08-17 22:00:37 +05:30
expect(subject.attachments).to eq('issue description')
expect(subject.activity).to eq({
2018-03-17 18:26:18 +05:30
title: 'Issue opened by Test User (test.user)',
2017-08-17 22:00:37 +05:30
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(
2018-03-17 18:26:18 +05:30
'[[project_name](http://somewhere.com)] Issue [#100 Issue title](http://url.com) closed by Test User (test.user)')
2017-08-17 22:00:37 +05:30
expect(subject.attachments).to be_empty
expect(subject.activity).to eq({
2018-03-17 18:26:18 +05:30
title: 'Issue closed by Test User (test.user)',
2017-08-17 22:00:37 +05:30
subtitle: 'in [project_name](http://somewhere.com)',
text: '[#100 Issue title](http://url.com)',
image: 'http://someavatar.com'
})
end
end
end
end