2019-04-03 19:10:21 +00:00
# frozen_string_literal: true
2015-05-01 03:16:19 +00:00
require 'spec_helper'
2017-07-10 14:24:02 +00:00
describe SystemNoteService do
2017-07-07 15:43:37 +00:00
include Gitlab :: Routing
2017-12-28 11:17:31 +00:00
include RepoHelpers
2018-05-22 16:37:35 +00:00
include AssetsHelpers
2016-11-09 21:55:21 +00:00
2020-01-10 09:07:49 +00:00
let_it_be ( :group ) { create ( :group ) }
let_it_be ( :project ) { create ( :project , :repository , group : group ) }
let_it_be ( :author ) { create ( :user ) }
2015-05-01 03:16:19 +00:00
let ( :noteable ) { create ( :issue , project : project ) }
2017-05-04 12:11:15 +00:00
let ( :issue ) { noteable }
2015-05-01 03:16:19 +00:00
2015-05-09 22:18:50 +00:00
describe '.add_commits' do
2019-10-03 12:06:00 +00:00
let ( :new_commits ) { double }
let ( :old_commits ) { double }
let ( :oldrev ) { double }
2015-05-01 03:16:19 +00:00
2019-10-03 12:06:00 +00:00
it 'calls CommitService' do
expect_next_instance_of ( :: SystemNotes :: CommitService ) do | service |
expect ( service ) . to receive ( :add_commits ) . with ( new_commits , old_commits , oldrev )
2016-09-30 01:51:33 +00:00
end
2019-10-03 12:06:00 +00:00
described_class . add_commits ( noteable , project , author , new_commits , old_commits , oldrev )
2015-05-01 03:16:19 +00:00
end
end
2018-07-21 12:57:52 +00:00
describe '.tag_commit' do
2019-10-03 12:06:00 +00:00
let ( :tag_name ) { double }
2018-07-21 12:57:52 +00:00
2019-10-03 12:06:00 +00:00
it 'calls CommitService' do
expect_next_instance_of ( :: SystemNotes :: CommitService ) do | service |
expect ( service ) . to receive ( :tag_commit ) . with ( tag_name )
end
2018-07-23 20:16:00 +00:00
2019-10-03 12:06:00 +00:00
described_class . tag_commit ( noteable , project , author , tag_name )
2018-07-21 12:57:52 +00:00
end
end
2015-05-09 22:18:50 +00:00
describe '.change_assignee' do
2019-10-08 15:06:04 +00:00
let ( :assignee ) { double }
2015-05-09 22:18:50 +00:00
2019-10-08 15:06:04 +00:00
it 'calls IssuableService' do
expect_next_instance_of ( :: SystemNotes :: IssuablesService ) do | service |
expect ( service ) . to receive ( :change_assignee ) . with ( assignee )
2015-05-09 22:18:50 +00:00
end
2019-10-08 15:06:04 +00:00
described_class . change_assignee ( noteable , project , author , assignee )
2015-05-09 22:18:50 +00:00
end
end
2019-04-07 18:35:16 +00:00
describe '.change_issuable_assignees' do
2019-10-08 15:06:04 +00:00
let ( :assignees ) { [ double , double ] }
2019-08-27 11:00:34 +00:00
2019-10-08 15:06:04 +00:00
it 'calls IssuableService' do
expect_next_instance_of ( :: SystemNotes :: IssuablesService ) do | service |
expect ( service ) . to receive ( :change_issuable_assignees ) . with ( assignees )
2019-08-27 11:00:34 +00:00
end
2019-10-08 15:06:04 +00:00
described_class . change_issuable_assignees ( noteable , project , author , assignees )
2019-08-27 11:00:34 +00:00
end
2017-05-04 12:11:15 +00:00
end
2020-01-24 12:09:01 +00:00
describe '.close_after_error_tracking_resolve' do
it 'calls IssuableService' do
expect_next_instance_of ( :: SystemNotes :: IssuablesService ) do | service |
expect ( service ) . to receive ( :close_after_error_tracking_resolve )
end
described_class . close_after_error_tracking_resolve ( noteable , project , author )
end
end
2015-05-09 22:18:50 +00:00
describe '.change_milestone' do
2019-10-08 15:06:04 +00:00
let ( :milestone ) { double }
2019-04-08 15:33:30 +00:00
2019-10-08 15:06:04 +00:00
it 'calls IssuableService' do
expect_next_instance_of ( :: SystemNotes :: IssuablesService ) do | service |
expect ( service ) . to receive ( :change_milestone ) . with ( milestone )
2017-08-03 17:37:32 +00:00
end
2019-10-08 15:06:04 +00:00
described_class . change_milestone ( noteable , project , author , milestone )
2015-05-01 03:16:19 +00:00
end
end
2018-09-09 18:08:21 +00:00
describe '.change_due_date' do
2020-01-17 18:08:41 +00:00
let ( :due_date ) { double }
2018-09-09 18:08:21 +00:00
2020-01-17 18:08:41 +00:00
it 'calls TimeTrackingService' do
expect_next_instance_of ( :: SystemNotes :: TimeTrackingService ) do | service |
expect ( service ) . to receive ( :change_due_date ) . with ( due_date )
2018-09-09 18:08:21 +00:00
end
2020-01-17 18:08:41 +00:00
described_class . change_due_date ( noteable , project , author , due_date )
2018-09-09 18:08:21 +00:00
end
end
2015-05-09 22:18:50 +00:00
describe '.change_status' do
2019-10-08 15:06:04 +00:00
let ( :status ) { double }
let ( :source ) { double }
2019-04-08 15:33:30 +00:00
2019-10-08 15:06:04 +00:00
it 'calls IssuableService' do
expect_next_instance_of ( :: SystemNotes :: IssuablesService ) do | service |
expect ( service ) . to receive ( :change_status ) . with ( status , source )
2017-04-04 10:36:58 +00:00
end
2019-04-08 15:33:30 +00:00
2019-10-08 15:06:04 +00:00
described_class . change_status ( noteable , project , author , status , source )
2015-05-09 22:18:50 +00:00
end
end
2015-05-01 03:16:19 +00:00
2017-02-17 13:56:13 +00:00
describe '.merge_when_pipeline_succeeds' do
2019-10-23 09:06:03 +00:00
it 'calls MergeRequestsService' do
sha = double
2015-11-18 10:17:41 +00:00
2019-10-23 09:06:03 +00:00
expect_next_instance_of ( :: SystemNotes :: MergeRequestsService ) do | service |
expect ( service ) . to receive ( :merge_when_pipeline_succeeds ) . with ( sha )
end
2015-11-18 10:17:41 +00:00
2019-10-23 09:06:03 +00:00
described_class . merge_when_pipeline_succeeds ( noteable , project , author , sha )
2015-11-24 13:59:02 +00:00
end
end
2017-02-17 13:56:13 +00:00
describe '.cancel_merge_when_pipeline_succeeds' do
2019-10-23 09:06:03 +00:00
it 'calls MergeRequestsService' do
expect_next_instance_of ( :: SystemNotes :: MergeRequestsService ) do | service |
expect ( service ) . to receive ( :cancel_merge_when_pipeline_succeeds )
end
2015-11-24 13:59:02 +00:00
2019-10-23 09:06:03 +00:00
described_class . cancel_merge_when_pipeline_succeeds ( noteable , project , author )
2015-11-18 10:17:41 +00:00
end
end
2019-06-26 12:24:09 +00:00
describe '.abort_merge_when_pipeline_succeeds' do
2019-10-23 09:06:03 +00:00
it 'calls MergeRequestsService' do
reason = double
2019-06-26 12:24:09 +00:00
2019-10-23 09:06:03 +00:00
expect_next_instance_of ( :: SystemNotes :: MergeRequestsService ) do | service |
expect ( service ) . to receive ( :abort_merge_when_pipeline_succeeds ) . with ( reason )
end
2019-06-26 12:24:09 +00:00
2019-10-23 09:06:03 +00:00
described_class . abort_merge_when_pipeline_succeeds ( noteable , project , author , reason )
2019-06-26 12:24:09 +00:00
end
end
2015-05-27 01:49:04 +00:00
describe '.change_title' do
2019-10-08 15:06:04 +00:00
let ( :title ) { double }
2015-05-27 01:49:04 +00:00
2019-10-08 15:06:04 +00:00
it 'calls IssuableService' do
expect_next_instance_of ( :: SystemNotes :: IssuablesService ) do | service |
expect ( service ) . to receive ( :change_title ) . with ( title )
2017-03-15 13:19:45 +00:00
end
2015-05-27 01:49:04 +00:00
2019-10-08 15:06:04 +00:00
described_class . change_title ( noteable , project , author , title )
2015-05-27 01:49:04 +00:00
end
end
2017-04-28 23:54:37 +00:00
describe '.change_description' do
2019-10-08 15:06:04 +00:00
it 'calls IssuableService' do
expect_next_instance_of ( :: SystemNotes :: IssuablesService ) do | service |
expect ( service ) . to receive ( :change_description )
2017-04-28 23:54:37 +00:00
end
2019-10-08 15:06:04 +00:00
described_class . change_description ( noteable , project , author )
2017-04-28 23:54:37 +00:00
end
end
2016-05-18 17:56:13 +00:00
describe '.change_issue_confidentiality' do
2019-10-08 15:06:04 +00:00
it 'calls IssuableService' do
expect_next_instance_of ( :: SystemNotes :: IssuablesService ) do | service |
expect ( service ) . to receive ( :change_issue_confidentiality )
2017-03-15 13:19:45 +00:00
end
2016-04-20 22:41:11 +00:00
2019-10-08 15:06:04 +00:00
described_class . change_issue_confidentiality ( noteable , project , author )
2016-04-20 22:41:11 +00:00
end
end
2015-05-29 01:00:37 +00:00
describe '.change_branch' do
2019-10-23 09:06:03 +00:00
it 'calls MergeRequestsService' do
old_branch = double
new_branch = double
branch_type = double
2015-05-29 01:00:37 +00:00
2019-10-23 09:06:03 +00:00
expect_next_instance_of ( :: SystemNotes :: MergeRequestsService ) do | service |
expect ( service ) . to receive ( :change_branch ) . with ( branch_type , old_branch , new_branch )
2015-05-29 01:00:37 +00:00
end
2019-10-23 09:06:03 +00:00
described_class . change_branch ( noteable , project , author , branch_type , old_branch , new_branch )
2015-05-29 01:00:37 +00:00
end
end
2015-10-15 08:41:46 +00:00
describe '.change_branch_presence' do
2019-10-23 09:06:03 +00:00
it 'calls MergeRequestsService' do
presence = double
branch = double
branch_type = double
2015-10-15 08:41:46 +00:00
2019-10-23 09:06:03 +00:00
expect_next_instance_of ( :: SystemNotes :: MergeRequestsService ) do | service |
expect ( service ) . to receive ( :change_branch_presence ) . with ( branch_type , branch , presence )
2015-10-15 08:41:46 +00:00
end
2019-10-23 09:06:03 +00:00
described_class . change_branch_presence ( noteable , project , author , branch_type , branch , presence )
2015-10-15 08:41:46 +00:00
end
end
2016-02-17 06:11:48 +00:00
describe '.new_issue_branch' do
2019-10-23 09:06:03 +00:00
it 'calls MergeRequestsService' do
branch = double
branch_project = double
2016-02-17 06:11:48 +00:00
2019-10-23 09:06:03 +00:00
expect_next_instance_of ( :: SystemNotes :: MergeRequestsService ) do | service |
expect ( service ) . to receive ( :new_issue_branch ) . with ( branch , branch_project : branch_project )
2019-06-28 22:08:26 +00:00
end
2019-10-23 09:06:03 +00:00
described_class . new_issue_branch ( noteable , project , author , branch , branch_project : branch_project )
2016-02-17 06:11:48 +00:00
end
end
2018-10-19 07:16:58 +00:00
describe '.new_merge_request' do
2019-10-23 09:06:03 +00:00
it 'calls MergeRequestsService' do
merge_request = double
2018-10-19 07:16:58 +00:00
2019-10-23 09:06:03 +00:00
expect_next_instance_of ( :: SystemNotes :: MergeRequestsService ) do | service |
expect ( service ) . to receive ( :new_merge_request ) . with ( merge_request )
end
2018-10-19 07:16:58 +00:00
2019-10-23 09:06:03 +00:00
described_class . new_merge_request ( noteable , project , author , merge_request )
2018-10-19 07:16:58 +00:00
end
end
2019-07-20 09:06:19 +00:00
describe '.zoom_link_added' do
2019-10-10 15:06:07 +00:00
it 'calls ZoomService' do
expect_next_instance_of ( :: SystemNotes :: ZoomService ) do | service |
expect ( service ) . to receive ( :zoom_link_added )
end
2019-07-20 09:06:19 +00:00
2019-10-10 15:06:07 +00:00
described_class . zoom_link_added ( noteable , project , author )
2019-07-20 09:06:19 +00:00
end
end
describe '.zoom_link_removed' do
2019-10-10 15:06:07 +00:00
it 'calls ZoomService' do
expect_next_instance_of ( :: SystemNotes :: ZoomService ) do | service |
expect ( service ) . to receive ( :zoom_link_removed )
end
2019-07-20 09:06:19 +00:00
2019-10-10 15:06:07 +00:00
described_class . zoom_link_removed ( noteable , project , author )
2019-07-20 09:06:19 +00:00
end
end
2015-05-09 22:18:50 +00:00
describe '.cross_reference' do
2019-10-08 15:06:04 +00:00
let ( :mentioner ) { double }
2015-05-01 03:16:19 +00:00
2019-10-08 15:06:04 +00:00
it 'calls IssuableService' do
expect_next_instance_of ( :: SystemNotes :: IssuablesService ) do | service |
expect ( service ) . to receive ( :cross_reference ) . with ( mentioner )
2015-05-09 22:18:50 +00:00
end
2017-03-15 13:19:45 +00:00
2019-10-08 15:06:04 +00:00
described_class . cross_reference ( double , mentioner , double )
2015-05-01 03:16:19 +00:00
end
end
2015-05-11 03:51:49 +00:00
describe '.cross_reference_disallowed?' do
2019-10-08 15:06:04 +00:00
let ( :mentioner ) { double }
2015-05-11 03:51:49 +00:00
2019-10-08 15:06:04 +00:00
it 'calls IssuableService' do
expect_next_instance_of ( :: SystemNotes :: IssuablesService ) do | service |
expect ( service ) . to receive ( :cross_reference_disallowed? ) . with ( mentioner )
2015-05-11 03:51:49 +00:00
end
2019-10-08 15:06:04 +00:00
described_class . cross_reference_disallowed? ( double , mentioner )
2015-06-14 15:41:11 +00:00
end
2015-05-11 03:51:49 +00:00
end
2015-05-01 03:16:19 +00:00
describe '.cross_reference_exists?' do
2019-10-08 15:06:04 +00:00
let ( :mentioner ) { double }
2016-02-04 17:36:16 +00:00
2019-10-08 15:06:04 +00:00
it 'calls IssuableService' do
expect_next_instance_of ( :: SystemNotes :: IssuablesService ) do | service |
expect ( service ) . to receive ( :cross_reference_exists? ) . with ( mentioner )
2016-02-04 17:36:16 +00:00
end
2019-10-08 15:06:04 +00:00
described_class . cross_reference_exists? ( double , mentioner )
2016-02-04 17:36:16 +00:00
end
2015-05-01 03:16:19 +00:00
end
2015-12-17 22:08:14 +00:00
2016-02-16 10:47:00 +00:00
describe '.noteable_moved' do
2019-10-08 15:06:04 +00:00
let ( :noteable_ref ) { double }
let ( :direction ) { double }
2016-02-16 10:47:00 +00:00
2019-10-08 15:06:04 +00:00
it 'calls IssuableService' do
expect_next_instance_of ( :: SystemNotes :: IssuablesService ) do | service |
expect ( service ) . to receive ( :noteable_moved ) . with ( noteable_ref , direction )
2016-02-16 10:47:00 +00:00
end
2019-10-08 15:06:04 +00:00
described_class . noteable_moved ( double , double , noteable_ref , double , direction : direction )
2016-02-15 14:14:57 +00:00
end
end
2019-06-28 13:25:56 +00:00
describe 'Jira integration' do
2017-03-27 21:14:01 +00:00
include JiraServiceHelper
2017-08-02 19:55:11 +00:00
let ( :project ) { create ( :jira_project , :repository ) }
2016-09-29 21:11:32 +00:00
let ( :author ) { create ( :user ) }
let ( :issue ) { create ( :issue , project : project ) }
2017-03-27 21:14:01 +00:00
let ( :merge_request ) { create ( :merge_request , :simple , target_project : project , source_project : project ) }
2016-09-29 21:11:32 +00:00
let ( :jira_issue ) { ExternalIssue . new ( " JIRA-1 " , project ) }
let ( :jira_tracker ) { project . jira_service }
let ( :commit ) { project . commit }
let ( :comment_url ) { jira_api_comment_url ( jira_issue . id ) }
2018-08-20 18:34:07 +00:00
let ( :success_message ) { " SUCCESS: Successfully posted to http://jira.example.net. " }
2016-09-29 21:11:32 +00:00
2016-11-17 20:46:31 +00:00
before do
stub_jira_urls ( jira_issue . id )
jira_service_settings
end
2015-12-17 22:08:14 +00:00
2017-05-18 06:07:48 +00:00
def cross_reference ( type , link_exists = false )
noteable = type == 'commit' ? commit : merge_request
links = [ ]
if link_exists
url = if type == 'commit'
" #{ Settings . gitlab . base_url } / #{ project . namespace . path } / #{ project . path } /commit/ #{ commit . id } "
else
2020-01-21 00:08:46 +00:00
" #{ Settings . gitlab . base_url } / #{ project . namespace . path } / #{ project . path } /-/merge_requests/ #{ merge_request . iid } "
2017-05-18 06:07:48 +00:00
end
2018-01-11 16:34:01 +00:00
2017-05-18 06:07:48 +00:00
link = double ( object : { 'url' = > url } )
links << link
expect ( link ) . to receive ( :save! )
end
allow ( JIRA :: Resource :: Remotelink ) . to receive ( :all ) . and_return ( links )
described_class . cross_reference ( jira_issue , noteable , author )
end
2017-02-22 17:46:57 +00:00
noteable_types = %w( merge_requests commit )
2016-11-14 21:30:01 +00:00
noteable_types . each do | type |
context " when noteable is a #{ type } " do
it " blocks cross reference when #{ type . underscore } _events is false " do
jira_tracker . update ( " #{ type } _events " = > false )
2019-12-12 12:07:33 +00:00
expect ( cross_reference ( type ) ) . to eq ( s_ ( 'JiraService|Events for %{noteable_model_name} are disabled.' ) % { noteable_model_name : type . pluralize . humanize . downcase } )
2016-11-14 21:30:01 +00:00
end
2018-03-16 19:09:35 +00:00
it " creates cross reference when #{ type . underscore } _events is true " do
2016-11-14 21:30:01 +00:00
jira_tracker . update ( " #{ type } _events " = > true )
2017-05-18 06:07:48 +00:00
expect ( cross_reference ( type ) ) . to eq ( success_message )
end
end
context 'when a new cross reference is created' do
it 'creates a new comment and remote link' do
cross_reference ( type )
2015-12-17 22:08:14 +00:00
2017-05-18 06:07:48 +00:00
expect ( WebMock ) . to have_requested ( :post , jira_api_comment_url ( jira_issue ) )
expect ( WebMock ) . to have_requested ( :post , jira_api_remote_link_url ( jira_issue ) )
end
end
context 'when a link exists' do
it 'updates a link but does not create a new comment' do
expect ( WebMock ) . not_to have_requested ( :post , jira_api_comment_url ( jira_issue ) )
cross_reference ( type , true )
2016-11-14 21:30:01 +00:00
end
end
end
2015-12-17 22:08:14 +00:00
2016-11-17 20:46:31 +00:00
describe " new reference " do
2018-05-22 16:37:35 +00:00
let ( :favicon_path ) { " http://localhost/assets/ #{ find_asset ( 'favicon.png' ) . digest_path } " }
2018-04-13 20:30:08 +00:00
2017-05-18 06:07:48 +00:00
before do
allow ( JIRA :: Resource :: Remotelink ) . to receive ( :all ) . and_return ( [ ] )
end
2016-11-17 20:46:31 +00:00
context 'for commits' do
it " creates comment " do
result = described_class . cross_reference ( jira_issue , commit , author )
2015-12-17 22:08:14 +00:00
2016-11-17 20:46:31 +00:00
expect ( result ) . to eq ( success_message )
end
2016-11-09 21:55:21 +00:00
it " creates remote link " do
2016-11-17 20:46:31 +00:00
described_class . cross_reference ( jira_issue , commit , author )
2016-11-09 21:55:21 +00:00
expect ( WebMock ) . to have_requested ( :post , jira_api_remote_link_url ( jira_issue ) ) . with (
body : hash_including (
GlobalID : " GitLab " ,
2019-02-28 09:46:09 +00:00
relationship : 'mentioned on' ,
2016-11-09 21:55:21 +00:00
object : {
2017-06-29 17:06:35 +00:00
url : project_commit_url ( project , commit ) ,
2019-02-28 09:46:09 +00:00
title : " Commit - #{ commit . title } " ,
2018-04-13 20:30:08 +00:00
icon : { title : " GitLab " , url16x16 : favicon_path } ,
2016-11-09 21:55:21 +00:00
status : { resolved : false }
}
)
) . once
end
2015-12-17 22:08:14 +00:00
end
2016-11-17 20:46:31 +00:00
context 'for issues' do
2019-01-16 12:09:29 +00:00
let ( :issue ) { create ( :issue , project : project ) }
2015-12-17 22:08:14 +00:00
2016-11-17 20:46:31 +00:00
it " creates comment " do
result = described_class . cross_reference ( jira_issue , issue , author )
2015-12-17 22:08:14 +00:00
2016-11-17 20:46:31 +00:00
expect ( result ) . to eq ( success_message )
end
2016-11-09 21:55:21 +00:00
it " creates remote link " do
2016-11-17 20:46:31 +00:00
described_class . cross_reference ( jira_issue , issue , author )
2016-11-09 21:55:21 +00:00
expect ( WebMock ) . to have_requested ( :post , jira_api_remote_link_url ( jira_issue ) ) . with (
body : hash_including (
GlobalID : " GitLab " ,
2019-02-28 09:46:09 +00:00
relationship : 'mentioned on' ,
2016-11-09 21:55:21 +00:00
object : {
2017-06-29 17:06:35 +00:00
url : project_issue_url ( project , issue ) ,
2019-02-28 09:46:09 +00:00
title : " Issue - #{ issue . title } " ,
2018-04-13 20:30:08 +00:00
icon : { title : " GitLab " , url16x16 : favicon_path } ,
2016-11-09 21:55:21 +00:00
status : { resolved : false }
}
)
) . once
end
2016-09-29 21:11:32 +00:00
end
2016-11-17 20:46:31 +00:00
context 'for snippets' do
let ( :snippet ) { create ( :snippet , project : project ) }
it " creates comment " do
result = described_class . cross_reference ( jira_issue , snippet , author )
expect ( result ) . to eq ( success_message )
end
it " creates remote link " do
described_class . cross_reference ( jira_issue , snippet , author )
expect ( WebMock ) . to have_requested ( :post , jira_api_remote_link_url ( jira_issue ) ) . with (
body : hash_including (
GlobalID : " GitLab " ,
2019-02-28 09:46:09 +00:00
relationship : 'mentioned on' ,
2016-11-17 20:46:31 +00:00
object : {
2017-06-29 17:06:35 +00:00
url : project_snippet_url ( project , snippet ) ,
2019-02-28 09:46:09 +00:00
title : " Snippet - #{ snippet . title } " ,
2018-04-13 20:30:08 +00:00
icon : { title : " GitLab " , url16x16 : favicon_path } ,
2016-11-17 20:46:31 +00:00
status : { resolved : false }
}
)
) . once
end
end
2016-09-29 21:11:32 +00:00
end
describe " existing reference " do
before do
2017-05-18 06:07:48 +00:00
allow ( JIRA :: Resource :: Remotelink ) . to receive ( :all ) . and_return ( [ ] )
2017-07-22 00:37:22 +00:00
message = " [ #{ author . name } |http://localhost/ #{ author . username } ] mentioned this issue in [a commit of #{ project . full_path } |http://localhost/ #{ project . full_path } /commit/ #{ commit . id } ]: \n ' #{ commit . title . chomp } ' "
2019-12-16 12:07:43 +00:00
allow_next_instance_of ( JIRA :: Resource :: Issue ) do | instance |
allow ( instance ) . to receive ( :comments ) . and_return ( [ OpenStruct . new ( body : message ) ] )
end
2015-12-17 22:08:14 +00:00
end
2016-09-29 21:11:32 +00:00
2016-11-17 20:46:31 +00:00
it " does not return success message " do
result = described_class . cross_reference ( jira_issue , commit , author )
2016-09-29 21:11:32 +00:00
2016-11-17 20:46:31 +00:00
expect ( result ) . not_to eq ( success_message )
end
2016-11-09 21:55:21 +00:00
it 'does not try to create comment and remote link' do
subject
expect ( WebMock ) . not_to have_requested ( :post , jira_api_comment_url ( jira_issue ) )
expect ( WebMock ) . not_to have_requested ( :post , jira_api_remote_link_url ( jira_issue ) )
end
2015-12-17 22:08:14 +00:00
end
end
2016-10-26 21:21:50 +00:00
2019-04-03 19:10:21 +00:00
describe '.change_time_estimate' do
2020-01-17 18:08:41 +00:00
it 'calls TimeTrackingService' do
expect_next_instance_of ( :: SystemNotes :: TimeTrackingService ) do | service |
expect ( service ) . to receive ( :change_time_estimate )
2019-06-11 10:40:01 +00:00
end
2019-04-03 19:10:21 +00:00
2020-01-17 18:08:41 +00:00
described_class . change_time_estimate ( noteable , project , author )
2019-04-03 19:10:21 +00:00
end
end
2016-10-26 21:21:50 +00:00
describe '.discussion_continued_in_issue' do
2017-08-30 10:54:23 +00:00
let ( :discussion ) { create ( :diff_note_on_merge_request , project : project ) . to_discussion }
2016-10-26 21:21:50 +00:00
let ( :merge_request ) { discussion . noteable }
let ( :issue ) { create ( :issue , project : project ) }
def reloaded_merge_request
MergeRequest . find ( merge_request . id )
end
2017-03-15 13:19:45 +00:00
subject { described_class . discussion_continued_in_issue ( discussion , project , author , issue ) }
it_behaves_like 'a system note' do
let ( :expected_noteable ) { discussion . first_note . noteable }
let ( :action ) { 'discussion' }
2016-10-26 21:21:50 +00:00
end
it 'creates a new note in the discussion' do
# we need to completely rebuild the merge request object, or the `@discussions` on the merge request are not reloaded.
2017-03-15 13:19:45 +00:00
expect { subject } . to change { reloaded_merge_request . discussions . first . notes . size } . by ( 1 )
2016-10-26 21:21:50 +00:00
end
it 'mentions the created issue in the system note' do
2017-03-15 13:19:45 +00:00
expect ( subject . note ) . to include ( issue . to_reference )
2016-10-26 21:21:50 +00:00
end
end
2016-12-23 05:44:02 +00:00
describe '.change_time_spent' do
2020-01-17 18:08:41 +00:00
it 'calls TimeTrackingService' do
expect_next_instance_of ( :: SystemNotes :: TimeTrackingService ) do | service |
expect ( service ) . to receive ( :change_time_spent )
2016-12-23 05:44:02 +00:00
end
2020-01-17 18:08:41 +00:00
described_class . change_time_spent ( noteable , project , author )
2016-12-23 05:44:02 +00:00
end
end
2016-12-15 20:48:26 +00:00
2017-11-21 19:25:37 +00:00
describe '.handle_merge_request_wip' do
2019-10-23 09:06:03 +00:00
it 'calls MergeRequestsService' do
expect_next_instance_of ( :: SystemNotes :: MergeRequestsService ) do | service |
expect ( service ) . to receive ( :handle_merge_request_wip )
2017-11-21 19:25:37 +00:00
end
2017-03-15 13:19:45 +00:00
2019-10-23 09:06:03 +00:00
described_class . handle_merge_request_wip ( noteable , project , author )
2017-03-15 13:19:45 +00:00
end
end
2016-12-15 20:48:26 +00:00
describe '.add_merge_request_wip_from_commit' do
2019-10-23 09:06:03 +00:00
it 'calls MergeRequestsService' do
commit = double
2016-12-15 20:48:26 +00:00
2019-10-23 09:06:03 +00:00
expect_next_instance_of ( :: SystemNotes :: MergeRequestsService ) do | service |
expect ( service ) . to receive ( :add_merge_request_wip_from_commit ) . with ( commit )
end
2016-12-15 20:48:26 +00:00
2019-10-23 09:06:03 +00:00
described_class . add_merge_request_wip_from_commit ( noteable , project , author , commit )
2016-12-15 20:48:26 +00:00
end
end
2017-03-15 13:19:45 +00:00
describe '.change_task_status' do
2019-10-08 15:06:04 +00:00
let ( :new_task ) { double }
2017-03-15 13:19:45 +00:00
2019-10-08 15:06:04 +00:00
it 'calls IssuableService' do
expect_next_instance_of ( :: SystemNotes :: IssuablesService ) do | service |
expect ( service ) . to receive ( :change_task_status ) . with ( new_task )
end
2017-03-15 13:19:45 +00:00
2019-10-08 15:06:04 +00:00
described_class . change_task_status ( noteable , project , author , new_task )
2017-03-15 13:19:45 +00:00
end
end
describe '.resolve_all_discussions' do
2019-10-23 09:06:03 +00:00
it 'calls MergeRequestsService' do
expect_next_instance_of ( :: SystemNotes :: MergeRequestsService ) do | service |
expect ( service ) . to receive ( :resolve_all_discussions )
end
2017-03-15 13:19:45 +00:00
2019-10-23 09:06:03 +00:00
described_class . resolve_all_discussions ( noteable , project , author )
2017-03-15 13:19:45 +00:00
end
end
2017-05-21 20:38:33 +00:00
describe '.diff_discussion_outdated' do
2019-10-23 09:06:03 +00:00
it 'calls MergeRequestsService' do
discussion = double
change_position = double
2017-05-21 20:38:33 +00:00
2019-10-23 09:06:03 +00:00
expect_next_instance_of ( :: SystemNotes :: MergeRequestsService ) do | service |
expect ( service ) . to receive ( :diff_discussion_outdated ) . with ( discussion , change_position )
2019-07-05 11:03:47 +00:00
end
2019-10-23 09:06:03 +00:00
described_class . diff_discussion_outdated ( discussion , project , author , change_position )
2017-05-21 20:38:33 +00:00
end
end
2017-03-30 01:39:06 +00:00
describe '.mark_duplicate_issue' do
2019-10-08 15:06:04 +00:00
let ( :canonical_issue ) { double }
2017-03-30 01:39:06 +00:00
2019-10-08 15:06:04 +00:00
it 'calls IssuableService' do
expect_next_instance_of ( :: SystemNotes :: IssuablesService ) do | service |
expect ( service ) . to receive ( :mark_duplicate_issue ) . with ( canonical_issue )
2017-03-30 01:39:06 +00:00
end
2019-10-08 15:06:04 +00:00
described_class . mark_duplicate_issue ( noteable , project , author , canonical_issue )
2017-07-20 14:42:33 +00:00
end
end
describe '.mark_canonical_issue_of_duplicate' do
2019-10-08 15:06:04 +00:00
let ( :duplicate_issue ) { double }
2017-07-20 14:42:33 +00:00
2019-10-08 15:06:04 +00:00
it 'calls IssuableService' do
expect_next_instance_of ( :: SystemNotes :: IssuablesService ) do | service |
expect ( service ) . to receive ( :mark_canonical_issue_of_duplicate ) . with ( duplicate_issue )
2017-07-20 14:42:33 +00:00
end
2019-10-08 15:06:04 +00:00
described_class . mark_canonical_issue_of_duplicate ( noteable , project , author , duplicate_issue )
2017-03-30 01:39:06 +00:00
end
end
2017-10-10 06:35:31 +00:00
describe '.discussion_lock' do
2019-10-08 15:06:04 +00:00
let ( :issuable ) { double }
2017-10-10 06:35:31 +00:00
2019-10-08 15:06:04 +00:00
before do
allow ( issuable ) . to receive ( :project ) . and_return ( double )
2017-10-10 06:35:31 +00:00
end
2019-10-08 15:06:04 +00:00
it 'calls IssuableService' do
expect_next_instance_of ( :: SystemNotes :: IssuablesService ) do | service |
expect ( service ) . to receive ( :discussion_lock )
2017-10-10 06:35:31 +00:00
end
2019-10-08 15:06:04 +00:00
described_class . discussion_lock ( issuable , double )
2017-10-10 06:35:31 +00:00
end
end
2015-05-01 03:16:19 +00:00
end