Module: SubscriptionsTestKit::SubscriptionsR5BackportR4Server::SubscriptionCreation

Included in:
NotificationDeliveryTest, RejectSubscriptionsTest
Defined in:
lib/subscriptions_test_kit/suites/subscriptions_r5_backport_r4_server/common/subscription_creation.rb

Instance Method Summary collapse

Instance Method Details

#get_new_subscription_value(subscription, field_path) ⇒ Object



15
16
17
# File 'lib/subscriptions_test_kit/suites/subscriptions_r5_backport_r4_server/common/subscription_creation.rb', line 15

def get_new_subscription_value(subscription, field_path)
  field_path.reduce(subscription) { |obj, path| obj[path] }
end

#json_parse(json) ⇒ Object



8
9
10
11
12
13
# File 'lib/subscriptions_test_kit/suites/subscriptions_r5_backport_r4_server/common/subscription_creation.rb', line 8

def json_parse(json)
  JSON.parse(json)
rescue JSON::ParserError
  add_message('error', "#{request_number}Invalid JSON.")
  false
end

#no_error_verification(message) ⇒ Object



4
5
6
# File 'lib/subscriptions_test_kit/suites/subscriptions_r5_backport_r4_server/common/subscription_creation.rb', line 4

def no_error_verification(message)
  assert messages.none? { |msg| msg[:type] == 'error' }, message
end

#send_subscription(subscription) ⇒ Object



52
53
54
55
56
57
58
59
60
# File 'lib/subscriptions_test_kit/suites/subscriptions_r5_backport_r4_server/common/subscription_creation.rb', line 52

def send_subscription(subscription)
  tags = ['subscription_creation']
  payload_type = subscription_payload_type(subscription)
  tags.append(payload_type) if payload_type.present?

  fhir_operation('/Subscription', body: subscription, tags:)
  assert_response_status(201)
  payload_type
end

#send_unsupported_subscription(subscription, unsupported_type, field_paths, subscription_field_old_values) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/subscriptions_test_kit/suites/subscriptions_r5_backport_r4_server/common/subscription_creation.rb', line 19

def send_unsupported_subscription(subscription, unsupported_type, field_paths, subscription_field_old_values)
  fhir_operation('/Subscription', body: subscription)

  return if request.status != 201

  new_subscription = json_parse(request.response_body)
  return unless new_subscription

  altered_field = false
  field_paths.each_with_index do |field_path, index|
    subscription_field_new_value = get_new_subscription_value(new_subscription, field_path)
    if subscription_field_new_value != subscription_field_old_values[index]
      altered_field = true
      break
    end
  end

  return if altered_field

  add_message('error', %(
      Sending a Subscription with #{unsupported_type} should be rejected, or the Subscription should be
      altered to fix the unsupported value.))
end

#subscription_payload_type(subscription) ⇒ Object



43
44
45
46
47
48
49
50
# File 'lib/subscriptions_test_kit/suites/subscriptions_r5_backport_r4_server/common/subscription_creation.rb', line 43

def subscription_payload_type(subscription)
  return unless subscription['channel']['_payload']

  payload_extension = subscription['channel']['_payload']['extension'].find do |ext|
    ext['url'].ends_with?('/backport-payload-content')
  end
  payload_extension['valueCode']
end