Class: SubscriptionsTestKit::SubscriptionStatusEndpoint

Inherits:
Inferno::DSL::SuiteEndpoint
  • Object
show all
Includes:
SubscriptionsTestKit::SubscriptionsR5BackportR4Client::SubscriptionSimulationUtils
Defined in:
lib/subscriptions_test_kit/endpoints/subscription_status_endpoint.rb

Constant Summary

Constants included from SubscriptionsTestKit::SubscriptionsR5BackportR4Client::SubscriptionSimulationUtils

SubscriptionsTestKit::SubscriptionsR5BackportR4Client::SubscriptionSimulationUtils::ALLOWED_MIME_TYPES, SubscriptionsTestKit::SubscriptionsR5BackportR4Client::SubscriptionSimulationUtils::DEFAULT_MIME_TYPE

Instance Method Summary collapse

Methods included from SubscriptionsTestKit::SubscriptionsR5BackportR4Client::SubscriptionSimulationUtils

#actual_mime_type, #client_access_token_input, #derive_event_notification, #derive_handshake_notification, #derive_status_bundle, #determine_event_count, #determine_subscription_status_code, #find_subscription, #notification_bundle_input, #operation_outcome

Instance Method Details

#base_subscription_urlObject



71
72
73
# File 'lib/subscriptions_test_kit/endpoints/subscription_status_endpoint.rb', line 71

def base_subscription_url
  request.url.sub(/(#{Regexp.escape(FHIR_SUBSCRIPTION_PATH)}).*/, '\1')
end

#find_params(params, name) ⇒ Object



67
68
69
# File 'lib/subscriptions_test_kit/endpoints/subscription_status_endpoint.rb', line 67

def find_params(params, name)
  params&.parameter&.filter { |p| p.name == name }
end

#make_responseObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/subscriptions_test_kit/endpoints/subscription_status_endpoint.rb', line 12

def make_response
  response.format = :json
  subscription = find_subscription(test_run.test_session_id)

  unless subscription.present?
    not_found
    return
  end

  subscription_id = request.params[:id]

  # Handle resource-level status params
  unless subscription_id.present?
    begin
      params = FHIR.from_contents(request.body.string)
    rescue StandardError
      response.status = 400
      response.body = operation_outcome('error', 'invalid', 'Invalid Parameters in request body').to_json
      return
    end

    unless subscription_params_match?(params)
      not_found
      return
    end
  end

  notification_json = notification_bundle_input(result)
  subscription_url = "#{base_subscription_url}/#{subscription.id}"
  status_code = determine_subscription_status_code(subscription_id)
  event_count = determine_event_count(test_run.test_session_id)
  response.status = 200
  response.body = derive_status_bundle(notification_json, subscription_url, status_code, event_count,
                                       request.url).to_json
end

#not_foundObject



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

def not_found
  response.status = 404
  response.body = operation_outcome('error', 'not-found').to_json
end

#subscription_params_match?(params) ⇒ Boolean

Returns:

  • (Boolean)


48
49
50
51
52
53
54
55
56
# File 'lib/subscriptions_test_kit/endpoints/subscription_status_endpoint.rb', line 48

def subscription_params_match?(params)
  id_params = find_params(params, 'id')

  return false if id_params&.any? && id_params&.none? { |p| p.valueString == subscription.id }

  status_params = find_params(params, 'status')
  subscription_status = determine_subscription_status_code(subscription.id)
  status_params.nil? || status_params.none? || status_params.any { p.valueString == subscription_status }
end

#tagsObject



58
59
60
# File 'lib/subscriptions_test_kit/endpoints/subscription_status_endpoint.rb', line 58

def tags
  [SUBSCRIPTION_STATUS_TAG]
end

#test_run_identifierObject



8
9
10
# File 'lib/subscriptions_test_kit/endpoints/subscription_status_endpoint.rb', line 8

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