Class: SubscriptionsTestKit::SubscriptionRestHookEndpoint

Inherits:
Inferno::DSL::SuiteEndpoint
  • Object
show all
Defined in:
lib/subscriptions_test_kit/endpoints/subscription_rest_hook_endpoint.rb

Instance Method Summary collapse

Instance Method Details

#extract_bearer_token(request) ⇒ Object

Header expected to be a bearer token of the form “Bearer <token>”



10
11
12
# File 'lib/subscriptions_test_kit/endpoints/subscription_rest_hook_endpoint.rb', line 10

def extract_bearer_token(request)
  request.headers['authorization']&.delete_prefix('Bearer ')
end

#extract_notification_type(request) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/subscriptions_test_kit/endpoints/subscription_rest_hook_endpoint.rb', line 25

def extract_notification_type(request)
  subscription_status = notification_extract_subscription_status(request)
  return unless subscription_status.present?

  notification_type = subscription_status[:parameter].find { |param| param[:name] == 'type' }
  notification_type[:valueCode]
end

#make_responseObject



52
53
54
# File 'lib/subscriptions_test_kit/endpoints/subscription_rest_hook_endpoint.rb', line 52

def make_response
  response.status = 200
end

#notification_extract_subscription_id(request) ⇒ Object



41
42
43
44
45
46
47
48
49
50
# File 'lib/subscriptions_test_kit/endpoints/subscription_rest_hook_endpoint.rb', line 41

def notification_extract_subscription_id(request)
  subscription_status = notification_extract_subscription_status(request)
  return unless subscription_status.present?

  subscription_param = subscription_status_extract_parameter(subscription_status[:parameter], 'subscription')
  return unless subscription_param.present?

  subscription_reference = subscription_param[:valueReference][:reference]
  subscription_reference.split('/').last
end

#notification_extract_subscription_status(request) ⇒ Object



14
15
16
17
18
19
20
21
22
23
# File 'lib/subscriptions_test_kit/endpoints/subscription_rest_hook_endpoint.rb', line 14

def notification_extract_subscription_status(request)
  notification_bundle_entries = request.params[:entry]
  return if notification_bundle_entries.blank?

  subscription_status_entry = notification_bundle_entries.find do |entry|
    entry[:resource][:resourceType] == 'Parameters'
  end

  subscription_status_entry[:resource]
end

#subscription_status_extract_parameter(parameters, param_name) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/subscriptions_test_kit/endpoints/subscription_rest_hook_endpoint.rb', line 33

def subscription_status_extract_parameter(parameters, param_name)
  return unless parameters.present?

  parameters.find do |entry|
    entry[:name] == param_name
  end
end

#tagsObject



56
57
58
59
60
# File 'lib/subscriptions_test_kit/endpoints/subscription_rest_hook_endpoint.rb', line 56

def tags
  notification_type = extract_notification_type(request)
  subscription_id = notification_extract_subscription_id(request)
  [notification_type, subscription_id]
end

#test_run_identifierObject



4
5
6
7
# File 'lib/subscriptions_test_kit/endpoints/subscription_rest_hook_endpoint.rb', line 4

def test_run_identifier
  bearer_token = extract_bearer_token(request)
  "notification #{bearer_token}"
end

#update_resultObject



62
63
64
# File 'lib/subscriptions_test_kit/endpoints/subscription_rest_hook_endpoint.rb', line 62

def update_result
  results_repo.update(result.id, result: 'pass') unless test.config.options[:accepts_multiple_requests]
end