Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
d4acde2d
Commit
d4acde2d
authored
Mar 01, 2021
by
Andy Soiron
Committed by
Arturo Herrero
Mar 01, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cleanup and optimize chat service specs
parent
c4088b82
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
114 additions
and
124 deletions
+114
-124
spec/support/shared_examples/models/slack_mattermost_notifications_shared_examples.rb
.../models/slack_mattermost_notifications_shared_examples.rb
+114
-124
No files found.
spec/support/shared_examples/models/slack_mattermost_notifications_shared_examples.rb
View file @
d4acde2d
...
...
@@ -66,193 +66,183 @@ RSpec.shared_examples 'slack or mattermost notifications' do |service_name|
end
describe
"#execute"
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:project
)
{
create
(
:project
,
:repository
,
:wiki_repo
)
}
let
(
:username
)
{
'slack_username'
}
let
(
:channel
)
{
'slack_channel'
}
let
(
:issue_service_options
)
{
{
title:
'Awesome issue'
,
description:
'please fix'
}
}
let_it_be
(
:project
)
{
create
(
:project
,
:repository
,
:wiki_repo
)
}
let_it_be
(
:user
)
{
create
(
:user
)
}
let
(
:
data
)
do
Gitlab
::
DataBuilder
::
Push
.
build_sample
(
project
,
user
)
end
let
(
:
chat_service
)
{
described_class
.
new
(
{
project:
project
,
webhook:
webhook_url
,
branches_to_be_notified:
'all'
}.
merge
(
chat_service_params
))
}
let
(
:chat_service_params
)
{
{}
}
let
(
:data
)
{
Gitlab
::
DataBuilder
::
Push
.
build_sample
(
project
,
user
)
}
let!
(
:stubbed_resolved_hostname
)
do
stub_full_request
(
webhook_url
,
method: :post
).
request_pattern
.
uri_pattern
.
to_s
end
before
do
allow
(
chat_service
).
to
receive_messages
(
project:
project
,
project_id:
project
.
id
,
service_hook:
true
,
webhook:
webhook_url
)
subject
(
:execute_service
)
{
chat_service
.
execute
(
data
)
}
context
'with username for slack configured'
do
let
(
:chat_service_params
)
{
{
username:
'slack_username'
}
}
issue_service
=
Issues
::
CreateService
.
new
(
project
,
user
,
issue_service_options
)
@issue
=
issue_service
.
execute
@issues_sample_data
=
issue_service
.
hook_data
(
@issue
,
'open'
)
project
.
add_developer
(
user
)
opts
=
{
title:
'Awesome merge_request'
,
description:
'please fix'
,
source_branch:
'feature'
,
target_branch:
'master'
}
merge_service
=
MergeRequests
::
CreateService
.
new
(
project
,
user
,
opts
)
@merge_request
=
merge_service
.
execute
@merge_sample_data
=
merge_service
.
hook_data
(
@merge_request
,
'open'
)
opts
=
{
title:
"Awesome wiki_page"
,
content:
"Some text describing some thing or another"
,
format:
"md"
,
message:
"user created page: Awesome wiki_page"
}
@wiki_page
=
create
(
:wiki_page
,
wiki:
project
.
wiki
,
**
opts
)
@wiki_page_sample_data
=
Gitlab
::
DataBuilder
::
WikiPage
.
build
(
@wiki_page
,
user
,
'create'
)
it
'uses the username as an option'
do
expect
(
Slack
::
Messenger
).
to
execute_with_options
(
username:
'slack_username'
)
execute_service
end
end
context
'push events'
do
let
(
:data
)
{
Gitlab
::
DataBuilder
::
Push
.
build_sample
(
project
,
user
)
}
it
"calls
#{
service_name
}
API for push events"
do
chat_service
.
execute
(
data
)
execute_service
expect
(
WebMock
).
to
have_requested
(
:post
,
stubbed_resolved_hostname
).
once
end
it
"calls
#{
service_name
}
API for issue events"
do
chat_service
.
execute
(
@issues_sample_data
)
context
'with event channel'
do
let
(
:chat_service_params
)
{
{
push_channel:
'random'
}
}
expect
(
WebMock
).
to
have_requested
(
:post
,
stubbed_resolved_hostname
).
once
it
'uses the right channel for push event'
do
expect
(
Slack
::
Messenger
).
to
execute_with_options
(
channel:
[
'random'
])
execute_service
end
end
end
it
"calls
#{
service_name
}
API for merge requests events"
do
chat_service
.
execute
(
@merge_sample_data
)
context
'issue events'
do
let_it_be
(
:issue
)
{
create
(
:issue
)
}
let
(
:data
)
{
issue
.
to_hook_data
(
user
)
}
it
"calls
#{
service_name
}
API for issue events"
do
execute_service
expect
(
WebMock
).
to
have_requested
(
:post
,
stubbed_resolved_hostname
).
once
end
it
"calls
#{
service_name
}
API for wiki page events"
do
chat_service
.
execute
(
@wiki_page_sample_data
)
context
'whith event channel'
do
let
(
:chat_service_params
)
{
{
issue_channel:
'random'
}
}
expect
(
WebMock
).
to
have_requested
(
:post
,
stubbed_resolved_hostname
).
once
it
'uses the right channel for issue event'
do
expect
(
Slack
::
Messenger
).
to
execute_with_options
(
channel:
[
'random'
])
execute_service
end
it
"calls
#{
service_name
}
API for deployment events"
do
deployment_event_data
=
{
object_kind:
'deployment'
}
context
'for confidential issues'
do
before_all
do
issue
.
update!
(
confidential:
true
)
end
chat_service
.
execute
(
deployment_event_data
)
it
'falls back to issue channel'
do
expect
(
Slack
::
Messenger
).
to
execute_with_options
(
channel:
[
'random'
])
expect
(
WebMock
).
to
have_requested
(
:post
,
stubbed_resolved_hostname
).
on
ce
execute_servi
ce
end
it
'uses the username as an option for slack when configur
ed'
do
allow
(
chat_service
).
to
receive
(
:username
).
and_return
(
username
)
context
'and confidential_issue_channel is defin
ed'
do
let
(
:chat_service_params
)
{
{
issue_channel:
'random'
,
confidential_issue_channel:
'confidential'
}
}
expect
(
Slack
::
Messenger
).
to
execute_with_options
(
username:
username
)
it
'uses the confidential issue channel when it is defined'
do
expect
(
Slack
::
Messenger
).
to
execute_with_options
(
channel:
[
'confidential'
])
chat_service
.
execute
(
data
)
execute_service
end
end
end
end
it
'uses the channel as an option when it is configured'
do
allow
(
chat_service
).
to
receive
(
:channel
).
and_return
(
channel
)
expect
(
Slack
::
Messenger
).
to
execute_with_options
(
channel:
[
channel
])
chat_service
.
execute
(
data
)
end
context
"event channels"
do
it
"uses the right channel for push event"
do
chat_service
.
update!
(
push_channel:
"random"
)
context
'merge request events'
do
let_it_be
(
:merge_request
)
{
create
(
:merge_request
)
}
let
(
:data
)
{
merge_request
.
to_hook_data
(
user
)
}
expect
(
Slack
::
Messenger
).
to
execute_with_options
(
channel:
[
'random'
])
it
"calls
#{
service_name
}
API for merge requests events"
do
execute_service
chat_service
.
execute
(
data
)
expect
(
WebMock
).
to
have_requested
(
:post
,
stubbed_resolved_hostname
).
once
end
it
"uses the right channel for merge request event"
do
chat_service
.
update!
(
merge_request_channel:
"random"
)
context
'with event channel'
do
let
(
:chat_service_params
)
{
{
merge_request_channel:
'random'
}
}
it
'uses the right channel for merge request event'
do
expect
(
Slack
::
Messenger
).
to
execute_with_options
(
channel:
[
'random'
])
chat_service
.
execute
(
@merge_sample_data
)
execute_service
end
end
end
it
"uses the right channel for issue event"
do
chat_service
.
update!
(
issue_channel:
"random"
)
context
'wiki page events'
do
let_it_be
(
:wiki_page
)
{
create
(
:wiki_page
,
wiki:
project
.
wiki
,
message:
'user created page: Awesome wiki_page'
)
}
let
(
:data
)
{
Gitlab
::
DataBuilder
::
WikiPage
.
build
(
wiki_page
,
user
,
'create'
)
}
expect
(
Slack
::
Messenger
).
to
execute_with_options
(
channel:
[
'random'
])
it
"calls
#{
service_name
}
API for wiki page events"
do
execute_service
chat_service
.
execute
(
@issues_sample_data
)
expect
(
WebMock
).
to
have_requested
(
:post
,
stubbed_resolved_hostname
).
once
end
context
'
for confidential issues
'
do
let
(
:
issue_service_options
)
{
{
title:
'Secret'
,
confidential:
true
}
}
context
'
with event channel
'
do
let
(
:
chat_service_params
)
{
{
wiki_page_channel:
'random'
}
}
it
"uses confidential issue channel"
do
chat_service
.
update!
(
confidential_issue_channel:
'confidential'
)
expect
(
Slack
::
Messenger
).
to
execute_with_options
(
channel:
[
'confidential'
])
it
'uses the right channel for wiki event'
do
expect
(
Slack
::
Messenger
).
to
execute_with_options
(
channel:
[
'random'
])
chat_service
.
execute
(
@issues_sample_data
)
execute_service
end
end
end
it
'falls back to issue channel'
do
chat_service
.
update!
(
issue_channel:
'fallback_channel'
)
context
'deployment events'
do
let_it_be
(
:deployment
)
{
create
(
:deployment
)
}
let
(
:data
)
{
Gitlab
::
DataBuilder
::
Deployment
.
build
(
deployment
)
}
expect
(
Slack
::
Messenger
).
to
execute_with_options
(
channel:
[
'fallback_channel'
])
it
"calls
#{
service_name
}
API for deployment events"
do
execute_service
chat_service
.
execute
(
@issues_sample_data
)
expect
(
WebMock
).
to
have_requested
(
:post
,
stubbed_resolved_hostname
).
once
end
end
it
"uses the right channel for wiki event"
do
chat_service
.
update!
(
wiki_page_channel:
"random"
)
context
'note event'
do
let_it_be
(
:issue_note
)
{
create
(
:note_on_issue
,
project:
project
,
note:
"issue note"
)
}
let
(
:data
)
{
Gitlab
::
DataBuilder
::
Note
.
build
(
issue_note
,
user
)
}
expect
(
Slack
::
Messenger
).
to
execute_with_options
(
channel:
[
'random'
])
chat_service
.
execute
(
@wiki_page_sample_data
)
end
it
"calls
#{
service_name
}
API for note events"
do
execute_service
context
"note event"
do
let
(
:issue_note
)
do
create
(
:note_on_issue
,
project:
project
,
note:
"issue note"
)
expect
(
WebMock
).
to
have_requested
(
:post
,
stubbed_resolved_hostname
).
once
end
it
"uses the right channel"
do
chat_service
.
update!
(
note_channel:
"random"
)
note_data
=
Gitlab
::
DataBuilder
::
Note
.
build
(
issue_note
,
user
)
context
'with event channel'
do
let
(
:chat_service_params
)
{
{
note_channel:
'random'
}
}
it
'uses the right channel'
do
expect
(
Slack
::
Messenger
).
to
execute_with_options
(
channel:
[
'random'
])
chat_service
.
execute
(
note_data
)
execute_service
end
context
'for confidential notes'
do
before
do
issue_note
.
noteable
.
update!
(
confidential:
true
)
before
_all
do
issue_note
.
update!
(
confidential:
true
)
end
it
"uses confidential channel"
do
chat_service
.
update!
(
confidential_note_channel:
"confidential"
)
note_data
=
Gitlab
::
DataBuilder
::
Note
.
build
(
issue_note
,
user
)
expect
(
Slack
::
Messenger
).
to
execute_with_options
(
channel:
[
'confidential'
])
it
'falls back to note channel'
do
expect
(
Slack
::
Messenger
).
to
execute_with_options
(
channel:
[
'random'
])
chat_service
.
execute
(
note_data
)
execute_service
end
it
'falls back to note channel'
do
chat_service
.
update!
(
note_channel:
"fallback_channel"
)
note_data
=
Gitlab
::
DataBuilder
::
Note
.
build
(
issue_note
,
user
)
context
'and confidential_note_channel is defined'
do
let
(
:chat_service_params
)
{
{
note_channel:
'random'
,
confidential_note_channel:
'confidential'
}
}
expect
(
Slack
::
Messenger
).
to
execute_with_options
(
channel:
[
'fallback_channel'
])
it
'uses confidential channel'
do
expect
(
Slack
::
Messenger
).
to
execute_with_options
(
channel:
[
'confidential'
])
chat_service
.
execute
(
note_data
)
execute_service
end
end
end
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment