2019-08-22 10:57:44 +00:00
# frozen_string_literal: true
2017-04-04 15:10:21 +00:00
require 'spec_helper'
2020-06-24 18:09:03 +00:00
RSpec . describe MicrosoftTeams :: Notifier do
2017-04-04 15:10:21 +00:00
subject { described_class . new ( webhook_url ) }
2022-08-02 03:09:33 +00:00
let ( :webhook_url ) { 'https://example.gitlab.com/' }
2017-04-04 15:10:21 +00:00
let ( :header ) { { 'Content-Type' = > 'application/json' } }
let ( :options ) do
{
title : 'JohnDoe4/project2' ,
2018-06-11 08:28:30 +00:00
summary : '[[JohnDoe4/project2](http://localhost/namespace2/gitlabhq)] Issue [#1 Awesome issue](http://localhost/namespace2/gitlabhq/issues/1) opened by user6' ,
2017-04-04 15:10:21 +00:00
activity : {
title : 'Issue opened by user6' ,
subtitle : 'in [JohnDoe4/project2](http://localhost/namespace2/gitlabhq)' ,
text : '[#1 Awesome issue](http://localhost/namespace2/gitlabhq/issues/1)' ,
image : 'http://someimage.com'
} ,
2020-02-04 12:09:00 +00:00
attachments : " [GitLab](https://gitlab.com) \n \n - _Ruby_ \n - **Go** \n "
2017-04-04 15:10:21 +00:00
}
end
let ( :body ) do
{
'sections' = > [
{
'activityTitle' = > 'Issue opened by user6' ,
'activitySubtitle' = > 'in [JohnDoe4/project2](http://localhost/namespace2/gitlabhq)' ,
'activityText' = > '[#1 Awesome issue](http://localhost/namespace2/gitlabhq/issues/1)' ,
'activityImage' = > 'http://someimage.com'
} ,
{
2020-02-04 12:09:00 +00:00
text : " [GitLab](https://gitlab.com) \n \n - _Ruby_ \n - **Go** \n "
2017-04-04 15:10:21 +00:00
}
] ,
'title' = > 'JohnDoe4/project2' ,
'summary' = > '[[JohnDoe4/project2](http://localhost/namespace2/gitlabhq)] Issue [#1 Awesome issue](http://localhost/namespace2/gitlabhq/issues/1) opened by user6'
}
end
describe '#ping' do
before do
stub_request ( :post , webhook_url ) . with ( body : JSON ( body ) , headers : { 'Content-Type' = > 'application/json' } ) . to_return ( status : 200 , body : " " , headers : { } )
end
2018-10-30 10:53:01 +00:00
it 'expects to receive successful answer' do
2017-04-04 15:10:21 +00:00
expect ( subject . ping ( options ) ) . to be true
end
end
2020-02-04 12:09:00 +00:00
describe '#body' do
it 'returns Markdown-based body when HTML was passed' do
2020-11-19 00:09:41 +00:00
expect ( subject . send ( :body , ** options ) ) . to eq ( body . to_json )
2020-02-04 12:09:00 +00:00
end
it 'fails when empty Hash was passed' do
2020-11-19 00:09:41 +00:00
expect { subject . send ( :body , ** { } ) } . to raise_error ( ArgumentError )
2020-02-04 12:09:00 +00:00
end
end
2017-04-04 15:10:21 +00:00
end