2018-11-18 11:00:15 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
module TestHooks
|
|
|
|
class BaseService
|
2020-06-23 00:09:42 +05:30
|
|
|
include BaseServiceUtility
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
attr_accessor :hook, :current_user, :trigger
|
|
|
|
|
|
|
|
def initialize(hook, current_user, trigger)
|
|
|
|
@hook = hook
|
|
|
|
@current_user = current_user
|
|
|
|
@trigger = trigger
|
|
|
|
end
|
|
|
|
|
|
|
|
def execute
|
2018-03-17 18:26:18 +05:30
|
|
|
trigger_key = hook.class.triggers.key(trigger.to_sym)
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
return error('Testing not available for this hook') if trigger_key.nil? || data.blank?
|
2023-03-17 16:20:25 +05:30
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
return error(data[:error]) if data[:error].present?
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
hook.execute(data, trigger_key, force: true)
|
2023-03-17 16:20:25 +05:30
|
|
|
rescue ArgumentError => e
|
|
|
|
error(e.message)
|
|
|
|
end
|
|
|
|
|
|
|
|
def error(message)
|
|
|
|
ServiceResponse.error(message: message)
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|