Class: SubscriptionsTestKit::Jobs::SendSubscriptionNotifications
Constant Summary
SubscriptionsR5BackportR4Client::SubscriptionSimulationUtils::ALLOWED_MIME_TYPES, SubscriptionsR5BackportR4Client::SubscriptionSimulationUtils::DEFAULT_MIME_TYPE
Instance Method Summary
collapse
-
#authorization_header ⇒ Object
-
#await_subcription_creation ⇒ Object
-
#content_type_header ⇒ Object
-
#headers ⇒ Object
-
#perform(test_run_id, test_session_id, result_id, subscription_id, subscription_url, client_endpoint, bearer_token, notification_json, test_run_identifier, test_suite_base_url) ⇒ Object
-
#persist_notification_request(response, tags) ⇒ Object
-
#requests_repo ⇒ Object
-
#rest_hook_connection ⇒ Object
-
#results_repo ⇒ Object
-
#resume_inferno_test ⇒ Object
-
#send_event_notification ⇒ Object
-
#send_handshake_notification ⇒ Object
-
#send_notification(request_body) ⇒ Object
-
#subscription ⇒ Object
-
#subscription_headers ⇒ Object
-
#test_still_waiting? ⇒ Boolean
-
#test_suite_connection ⇒ Object
#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
73
74
75
|
# File 'lib/subscriptions_test_kit/jobs/send_subscription_notifications.rb', line 73
def
@authorization_header ||= @bearer_token.present? ? { 'Authorization' => "Bearer #{@bearer_token}" } : {}
end
|
#await_subcription_creation ⇒ Object
81
82
83
|
# File 'lib/subscriptions_test_kit/jobs/send_subscription_notifications.rb', line 81
def await_subcription_creation
sleep 0.5 until subscription.present?
end
|
62
63
64
|
# File 'lib/subscriptions_test_kit/jobs/send_subscription_notifications.rb', line 62
def
@content_type_header ||= { 'Content-Type' => actual_mime_type(subscription) }
end
|
50
51
52
|
# File 'lib/subscriptions_test_kit/jobs/send_subscription_notifications.rb', line 50
def
@headers ||= .merge().merge()
end
|
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/subscriptions_test_kit/jobs/send_subscription_notifications.rb', line 14
def perform(test_run_id, test_session_id, result_id, subscription_id, subscription_url, client_endpoint,
bearer_token, notification_json, test_run_identifier, test_suite_base_url)
@test_run_id = test_run_id
@test_session_id = test_session_id
@result_id = result_id
@subscription_id = subscription_id
@subscription_url = subscription_url
@client_endpoint = client_endpoint
@bearer_token = bearer_token
@notification_json = notification_json
@test_run_identifier = test_run_identifier
@test_suite_base_url = test_suite_base_url
await_subcription_creation
sleep 1
return unless test_still_waiting?
send_handshake_notification
sleep rand(5..10)
return unless test_still_waiting?
send_event_notification
end
|
#persist_notification_request(response, tags) ⇒ Object
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
# File 'lib/subscriptions_test_kit/jobs/send_subscription_notifications.rb', line 111
def persist_notification_request(response, tags)
= .map { |name, value| { name:, value: } }
= response.&.map { |name, value| { name:, value: } }
requests_repo.create(
verb: 'POST',
url: response.env.url.to_s,
direction: 'outgoing',
status: response.status,
request_body: response.env.request_body,
response_body: response.env.response_body,
test_session_id: @test_session_id,
result_id: @result_id,
request_headers: ,
response_headers: ,
tags:
)
end
|
#requests_repo ⇒ Object
38
39
40
|
# File 'lib/subscriptions_test_kit/jobs/send_subscription_notifications.rb', line 38
def requests_repo
@requests_repo ||= Inferno::Repositories::Requests.new
end
|
#rest_hook_connection ⇒ Object
54
55
56
|
# File 'lib/subscriptions_test_kit/jobs/send_subscription_notifications.rb', line 54
def rest_hook_connection
@rest_hook_connection ||= Faraday.new(url: @client_endpoint, request: { open_timeout: 30 }, headers:)
end
|
#results_repo ⇒ Object
42
43
44
|
# File 'lib/subscriptions_test_kit/jobs/send_subscription_notifications.rb', line 42
def results_repo
@results_repo ||= Inferno::Repositories::Results.new
end
|
#resume_inferno_test ⇒ Object
98
99
100
|
# File 'lib/subscriptions_test_kit/jobs/send_subscription_notifications.rb', line 98
def resume_inferno_test
test_suite_connection.get(RESUME_PASS_PATH.delete_prefix('/'), { test_run_identifier: @test_run_identifier })
end
|
#send_event_notification ⇒ Object
92
93
94
95
96
|
# File 'lib/subscriptions_test_kit/jobs/send_subscription_notifications.rb', line 92
def send_event_notification
event_json = derive_event_notification(@notification_json, @subscription_url, 1).to_json
response = send_notification(event_json)
persist_notification_request(response, [REST_HOOK_EVENT_NOTIFICATION_TAG])
end
|
#send_handshake_notification ⇒ Object
85
86
87
88
89
90
|
# File 'lib/subscriptions_test_kit/jobs/send_subscription_notifications.rb', line 85
def send_handshake_notification
handshake_json = derive_handshake_notification(@notification_json, @subscription_url).to_json
response = send_notification(handshake_json)
persist_notification_request(response, [REST_HOOK_HANDSHAKE_NOTIFICATION_TAG])
resume_inferno_test unless response.status == 200
end
|
#send_notification(request_body) ⇒ Object
102
103
104
105
106
107
108
109
|
# File 'lib/subscriptions_test_kit/jobs/send_subscription_notifications.rb', line 102
def send_notification(request_body)
rest_hook_connection.post('', request_body)
rescue Faraday::Error => e
Faraday::Response.new(response_body: e.message, url: rest_hook_connection.url_prefix.to_s)
end
|
#subscription ⇒ Object
46
47
48
|
# File 'lib/subscriptions_test_kit/jobs/send_subscription_notifications.rb', line 46
def subscription
@subscription ||= find_subscription(@test_session_id)
end
|
66
67
68
69
70
71
|
# File 'lib/subscriptions_test_kit/jobs/send_subscription_notifications.rb', line 66
def
@subscription_headers ||= subscription&.channel&.&.each_with_object({}) do |, hash|
, = .split(': ', 2)
hash[] =
end || {}
end
|
#test_still_waiting? ⇒ Boolean
77
78
79
|
# File 'lib/subscriptions_test_kit/jobs/send_subscription_notifications.rb', line 77
def test_still_waiting?
results_repo.find_waiting_result(test_run_id: @test_run_id)
end
|
#test_suite_connection ⇒ Object
58
59
60
|
# File 'lib/subscriptions_test_kit/jobs/send_subscription_notifications.rb', line 58
def test_suite_connection
@test_suite_connection ||= Faraday.new(@test_suite_base_url)
end
|