2019-10-12 21:52:04 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
Integration.available_services_names.each do |service|
|
2020-03-13 15:44:24 +05:30
|
|
|
RSpec.shared_context service do
|
2020-11-24 15:15:51 +05:30
|
|
|
include JiraServiceHelper if service == 'jira'
|
|
|
|
|
2015-09-25 12:07:36 +05:30
|
|
|
let(:dashed_service) { service.dasherize }
|
|
|
|
let(:service_method) { "#{service}_service".to_sym }
|
2021-06-08 01:23:25 +05:30
|
|
|
let(:service_klass) { Integration.service_name_to_model(service) }
|
2018-03-17 18:26:18 +05:30
|
|
|
let(:service_instance) { service_klass.new }
|
|
|
|
let(:service_fields) { service_instance.fields }
|
2015-10-24 18:46:33 +05:30
|
|
|
let(:service_attrs_list) { service_fields.inject([]) {|arr, hash| arr << hash[:name].to_sym } }
|
2015-09-25 12:07:36 +05:30
|
|
|
let(:service_attrs) do
|
|
|
|
service_attrs_list.inject({}) do |hash, k|
|
|
|
|
if k =~ /^(token*|.*_token|.*_key)/
|
|
|
|
hash.merge!(k => 'secrettoken')
|
2020-07-28 23:09:34 +05:30
|
|
|
elsif service == 'confluence' && k == :confluence_url
|
|
|
|
hash.merge!(k => 'https://example.atlassian.net/wiki')
|
2021-02-22 17:27:13 +05:30
|
|
|
elsif service == 'datadog' && k == :datadog_site
|
|
|
|
hash.merge!(k => 'datadoghq.com')
|
2015-09-25 12:07:36 +05:30
|
|
|
elsif k =~ /^(.*_url|url|webhook)/
|
|
|
|
hash.merge!(k => "http://example.com")
|
2017-08-17 22:00:37 +05:30
|
|
|
elsif service_klass.method_defined?("#{k}?")
|
|
|
|
hash.merge!(k => true)
|
2015-09-25 12:07:36 +05:30
|
|
|
elsif service == 'irker' && k == :recipients
|
|
|
|
hash.merge!(k => 'irc://irc.network.net:666/#channel')
|
2017-08-17 22:00:37 +05:30
|
|
|
elsif service == 'irker' && k == :server_port
|
|
|
|
hash.merge!(k => 1234)
|
|
|
|
elsif service == 'jira' && k == :jira_issue_transition_id
|
2019-07-07 11:18:12 +05:30
|
|
|
hash.merge!(k => '1,2,3')
|
2021-04-29 21:17:54 +05:30
|
|
|
elsif service == 'emails_on_push' && k == :recipients
|
|
|
|
hash.merge!(k => 'foo@bar.com')
|
2021-06-08 01:23:25 +05:30
|
|
|
elsif service == 'slack' || service == 'mattermost' && k == :labels_to_be_notified_behavior
|
|
|
|
hash.merge!(k => "match_any")
|
2015-09-25 12:07:36 +05:30
|
|
|
else
|
|
|
|
hash.merge!(k => "someword")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
let(:licensed_features) do
|
|
|
|
{
|
2021-02-22 17:27:13 +05:30
|
|
|
'github' => :github_project_service_integration
|
2019-12-21 20:55:43 +05:30
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
before do
|
2019-12-21 20:55:43 +05:30
|
|
|
enable_license_for_service(service)
|
2020-11-24 15:15:51 +05:30
|
|
|
stub_jira_service_test if service == 'jira'
|
2019-07-07 11:18:12 +05:30
|
|
|
end
|
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
def initialize_service(service, attrs = {})
|
2018-03-17 18:26:18 +05:30
|
|
|
service_item = project.find_or_initialize_service(service)
|
2021-06-08 01:23:25 +05:30
|
|
|
service_item.attributes = attrs
|
2018-03-17 18:26:18 +05:30
|
|
|
service_item.properties = service_attrs
|
2019-09-04 21:01:54 +05:30
|
|
|
service_item.save!
|
2018-03-17 18:26:18 +05:30
|
|
|
service_item
|
|
|
|
end
|
2019-12-21 20:55:43 +05:30
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def enable_license_for_service(service)
|
|
|
|
return unless respond_to?(:stub_licensed_features)
|
|
|
|
|
|
|
|
licensed_feature = licensed_features[service]
|
|
|
|
return unless licensed_feature
|
|
|
|
|
|
|
|
stub_licensed_features(licensed_feature => true)
|
|
|
|
project.clear_memoization(:disabled_services)
|
|
|
|
end
|
2015-09-25 12:07:36 +05:30
|
|
|
end
|
|
|
|
end
|