Module: DaVinciCRDTestKit::ServerHookHelper

Instance Method Summary collapse

Instance Method Details

#discovered_service_id_for_hook(hook_name) ⇒ Object

load discovery response to get the target service id



35
36
37
38
39
40
41
# File 'lib/davinci_crd_test_kit/server_hook_helper.rb', line 35

def discovered_service_id_for_hook(hook_name)
  discovery_requests = load_tagged_requests(DaVinciCRDTestKit::DISCOVERY_TAG)
  services = discovery_requests&.first&.response_body
  return unless services.present?

  JSON.parse(services)['services']&.find { |service| service['hook'] == hook_name }&.dig('id')
end

#identify_hook(payloads) ⇒ Object

identify the hook to invoke



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/davinci_crd_test_kit/server_hook_helper.rb', line 13

def identify_hook(payloads)
  if tested_hook_name == ANY_HOOK_TAG
    hook_list_from_payloads = payloads.map { |body| body['hook'] }.uniq

    assert hook_list_from_payloads.length == 1,
           'Could not identify the tested hook for the *Demonstrated Any Hook tests* from the request bodies.'

    hook_list_from_payloads.first
  else
    tested_hook_name
  end
end

#target_service_id(service_ids, hook_name) ⇒ Object

target service id for invocation if a list isn’t provided, use the discovery response and the target hook to find one



28
29
30
31
32
# File 'lib/davinci_crd_test_kit/server_hook_helper.rb', line 28

def target_service_id(service_ids, hook_name)
  return service_ids.split(', ').first.strip if service_ids.present?

  discovered_service_id_for_hook(hook_name)
end

#tested_hook_nameObject

configured hook used for tagging the request “any” is an option



8
9
10
# File 'lib/davinci_crd_test_kit/server_hook_helper.rb', line 8

def tested_hook_name
  config.options[:hook_name]
end