2019-07-25 01:27:42 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-08-26 19:58:49 -04:00
|
|
|
Service.available_services_names.each do |service|
|
2020-01-20 22:08:37 -05:00
|
|
|
RSpec.shared_context service do
|
2020-08-28 05:10:32 -04:00
|
|
|
include JiraServiceHelper if service == 'jira'
|
|
|
|
|
2015-08-26 19:58:49 -04:00
|
|
|
let(:dashed_service) { service.dasherize }
|
|
|
|
let(:service_method) { "#{service}_service".to_sym }
|
|
|
|
let(:service_klass) { "#{service}_service".classify.constantize }
|
2018-01-06 01:18:13 -05:00
|
|
|
let(:service_instance) { service_klass.new }
|
|
|
|
let(:service_fields) { service_instance.fields }
|
2015-10-12 09:24:00 -04:00
|
|
|
let(:service_attrs_list) { service_fields.inject([]) {|arr, hash| arr << hash[:name].to_sym } }
|
2015-08-26 19:58:49 -04:00
|
|
|
let(:service_attrs) do
|
|
|
|
service_attrs_list.inject({}) do |hash, k|
|
|
|
|
if k =~ /^(token*|.*_token|.*_key)/
|
|
|
|
hash.merge!(k => 'secrettoken')
|
2020-07-14 08:09:14 -04:00
|
|
|
elsif service == 'confluence' && k == :confluence_url
|
|
|
|
hash.merge!(k => 'https://example.atlassian.net/wiki')
|
2020-11-26 16:09:22 -05:00
|
|
|
elsif service == 'datadog' && k == :datadog_site
|
|
|
|
hash.merge!(k => 'datadoghq.com')
|
2015-08-26 19:58:49 -04:00
|
|
|
elsif k =~ /^(.*_url|url|webhook)/
|
|
|
|
hash.merge!(k => "http://example.com")
|
2016-12-05 09:40:53 -05:00
|
|
|
elsif service_klass.method_defined?("#{k}?")
|
|
|
|
hash.merge!(k => true)
|
2015-08-26 19:58:49 -04:00
|
|
|
elsif service == 'irker' && k == :recipients
|
|
|
|
hash.merge!(k => 'irc://irc.network.net:666/#channel')
|
2016-12-05 09:40:53 -05:00
|
|
|
elsif service == 'irker' && k == :server_port
|
|
|
|
hash.merge!(k => 1234)
|
|
|
|
elsif service == 'jira' && k == :jira_issue_transition_id
|
2019-01-31 05:29:27 -05:00
|
|
|
hash.merge!(k => '1,2,3')
|
2015-08-26 19:58:49 -04:00
|
|
|
else
|
|
|
|
hash.merge!(k => "someword")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2018-01-04 04:33:51 -05:00
|
|
|
|
2019-09-25 08:06:15 -04:00
|
|
|
let(:licensed_features) do
|
|
|
|
{
|
2020-11-26 10:09:30 -05:00
|
|
|
'github' => :github_project_service_integration
|
2019-09-25 08:06:15 -04:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2019-02-27 12:00:13 -05:00
|
|
|
before do
|
2019-09-25 08:06:15 -04:00
|
|
|
enable_license_for_service(service)
|
2020-08-28 05:10:32 -04:00
|
|
|
stub_jira_service_test if service == 'jira'
|
2019-02-27 12:00:13 -05:00
|
|
|
end
|
|
|
|
|
2018-01-04 04:33:51 -05:00
|
|
|
def initialize_service(service)
|
|
|
|
service_item = project.find_or_initialize_service(service)
|
|
|
|
service_item.properties = service_attrs
|
2019-06-17 20:01:56 -04:00
|
|
|
service_item.save!
|
2018-01-04 04:33:51 -05:00
|
|
|
service_item
|
|
|
|
end
|
2019-09-25 08:06:15 -04:00
|
|
|
|
|
|
|
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)
|
|
|
|
project.clear_memoization(:licensed_feature_available)
|
|
|
|
end
|
2015-08-26 19:58:49 -04:00
|
|
|
end
|
|
|
|
end
|