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 :: MergeMessage 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 : {
2021-04-29 21:17:54 +05:30
title : " Merge request title \n Second line " ,
2017-08-17 22:00:37 +05:30
id : 10 ,
iid : 100 ,
assignee_id : 1 ,
url : 'http://url.com' ,
state : 'opened' ,
description : 'merge request description' ,
source_branch : 'source_branch' ,
2017-09-10 17:25:29 +05:30
target_branch : 'target_branch'
2017-08-17 22:00:37 +05:30
}
}
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 ) { '#345' }
context 'open' do
it 'returns a message regarding opening of merge requests' do
expect ( subject . pretext ) . to eq (
2021-04-29 21:17:54 +05:30
'Test User (test.user) opened merge request <http://somewhere.com/-/merge_requests/100|!100 *Merge request title*> in <http://somewhere.com|project_name>' )
2017-08-17 22:00:37 +05:30
expect ( subject . attachments ) . to be_empty
end
end
context 'close' do
before do
args [ :object_attributes ] [ :state ] = 'closed'
end
it 'returns a message regarding closing of merge requests' do
expect ( subject . pretext ) . to eq (
2021-04-29 21:17:54 +05:30
'Test User (test.user) closed merge request <http://somewhere.com/-/merge_requests/100|!100 *Merge request title*> in <http://somewhere.com|project_name>' )
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 merge requests' do
expect ( subject . pretext ) . to eq (
2021-04-29 21:17:54 +05:30
'Test User (test.user) opened merge request [!100 *Merge request title*](http://somewhere.com/-/merge_requests/100) in [project_name](http://somewhere.com)' )
2017-08-17 22:00:37 +05:30
expect ( subject . attachments ) . to be_empty
expect ( subject . activity ) . to eq ( {
2021-04-29 21:17:54 +05:30
title : 'Merge request opened by Test User (test.user)' ,
2017-08-17 22:00:37 +05:30
subtitle : 'in [project_name](http://somewhere.com)' ,
2021-04-29 21:17:54 +05:30
text : '[!100 *Merge request title*](http://somewhere.com/-/merge_requests/100)' ,
2017-08-17 22:00:37 +05:30
image : 'http://someavatar.com'
} )
end
end
context 'close' do
before do
args [ :object_attributes ] [ :state ] = 'closed'
end
it 'returns a message regarding closing of merge requests' do
expect ( subject . pretext ) . to eq (
2021-04-29 21:17:54 +05:30
'Test User (test.user) closed merge request [!100 *Merge request title*](http://somewhere.com/-/merge_requests/100) in [project_name](http://somewhere.com)' )
2017-08-17 22:00:37 +05:30
expect ( subject . attachments ) . to be_empty
expect ( subject . activity ) . to eq ( {
2021-04-29 21:17:54 +05:30
title : 'Merge request closed by Test User (test.user)' ,
2017-08-17 22:00:37 +05:30
subtitle : 'in [project_name](http://somewhere.com)' ,
2021-04-29 21:17:54 +05:30
text : '[!100 *Merge request title*](http://somewhere.com/-/merge_requests/100)' ,
2017-08-17 22:00:37 +05:30
image : 'http://someavatar.com'
} )
end
end
end
2020-11-24 15:15:51 +05:30
context 'approved' do
before do
args [ :object_attributes ] [ :action ] = 'approved'
end
it 'returns a message regarding completed approval of merge requests' do
expect ( subject . pretext ) . to eq (
2021-04-29 21:17:54 +05:30
'Test User (test.user) approved merge request <http://somewhere.com/-/merge_requests/100|!100 *Merge request title*> ' \
2020-11-24 15:15:51 +05:30
'in <http://somewhere.com|project_name>' )
expect ( subject . attachments ) . to be_empty
end
end
context 'unapproved' do
before do
args [ :object_attributes ] [ :action ] = 'unapproved'
end
it 'returns a message regarding revocation of completed approval of merge requests' do
expect ( subject . pretext ) . to eq (
2021-04-29 21:17:54 +05:30
'Test User (test.user) unapproved merge request <http://somewhere.com/-/merge_requests/100|!100 *Merge request title*> ' \
2020-11-24 15:15:51 +05:30
'in <http://somewhere.com|project_name>' )
expect ( subject . attachments ) . to be_empty
end
end
context 'approval' do
before do
args [ :object_attributes ] [ :action ] = 'approval'
end
it 'returns a message regarding added approval of merge requests' do
expect ( subject . pretext ) . to eq (
2021-04-29 21:17:54 +05:30
'Test User (test.user) added their approval to merge request <http://somewhere.com/-/merge_requests/100|!100 *Merge request title*> ' \
2020-11-24 15:15:51 +05:30
'in <http://somewhere.com|project_name>' )
expect ( subject . attachments ) . to be_empty
end
end
context 'unapproval' do
before do
args [ :object_attributes ] [ :action ] = 'unapproval'
end
it 'returns a message regarding revoking approval of merge requests' do
expect ( subject . pretext ) . to eq (
2021-04-29 21:17:54 +05:30
'Test User (test.user) removed their approval from merge request <http://somewhere.com/-/merge_requests/100|!100 *Merge request title*> ' \
2020-11-24 15:15:51 +05:30
'in <http://somewhere.com|project_name>' )
expect ( subject . attachments ) . to be_empty
end
end
2017-08-17 22:00:37 +05:30
end