Skip to content
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
require_relative '../../../lib/subscriptions_test_kit/common/notification_conformance_verification'

RSpec.describe SubscriptionsTestKit::NotificationConformanceVerification do
let(:suite) { Inferno::Repositories::TestSuites.new.find('subscriptions_r5_backport_r4_server') }
let(:session_data_repo) { Inferno::Repositories::SessionData.new }
let(:test_session) { repo_create(:test_session, test_suite_id: suite.id) }
RSpec.describe SubscriptionsTestKit::NotificationConformanceVerification, :runnable do
let(:suite_id) { 'subscriptions_r5_backport_r4_server' }
let(:results_repo) { Inferno::Repositories::Results.new }

let(:full_resource_notification_bundle) do
Expand All @@ -29,7 +27,7 @@
outcomes: [{
issues: []
}],
sessionId: 'b8cf5547-1dc7-4714-a797-dc2347b93fe2'
sessionId: test_session.id
}
end

Expand All @@ -41,12 +39,11 @@
message: 'Resource does not conform to profile'
}]
}],
sessionId: 'b8cf5547-1dc7-4714-a797-dc2347b93fe2'
sessionId: test_session.id
}
end

let(:subscription_id) { '123' }
let(:validator_url) { ENV.fetch('FHIR_RESOURCE_VALIDATOR_URL') }

def entity_result_message(runnable)
results_repo.current_results_for_test_session_and_runnables(test_session.id, [runnable])
Expand All @@ -64,20 +61,6 @@ def entity_result_message_type(runnable)
.first
end

def run(runnable, inputs = {})
test_run_params = { test_session_id: test_session.id }.merge(runnable.reference_hash)
test_run = Inferno::Repositories::TestRuns.new.create(test_run_params)
inputs.each do |name, value|
session_data_repo.save(
test_session_id: test_session.id,
name:,
value:,
type: runnable.config.input_type(name)
)
end
Inferno::TestRunner.new(test_session:, test_run:).run(runnable)
end

describe 'Notification Verification' do
let(:test) do
Class.new(Inferno::Test) do
Expand Down Expand Up @@ -110,7 +93,7 @@ def run(runnable, inputs = {})
end

it 'passes if conformant notification bundle passed in' do
verification_request = stub_request(:post, "#{validator_url}/validate")
verification_request = stub_request(:post, validation_url)
.to_return(status: 200, body: operation_outcome_success.to_json)

result = run(test, notification_bundle: full_resource_notification_bundle.to_json,
Expand All @@ -120,7 +103,7 @@ def run(runnable, inputs = {})
end

it 'passes if conformant notification bundle passed in with correct status argument' do
verification_request = stub_request(:post, "#{validator_url}/validate")
verification_request = stub_request(:post, validation_url)
.to_return(status: 200, body: operation_outcome_success.to_json)

result = run(test, notification_bundle: full_resource_notification_bundle.to_json,
Expand Down Expand Up @@ -152,7 +135,7 @@ def run(runnable, inputs = {})
end

it 'fails if passed in bundle not a history type Bundle' do
verification_request = stub_request(:post, "#{validator_url}/validate")
verification_request = stub_request(:post, validation_url)
.to_return(status: 200, body: operation_outcome_success.to_json)

full_resource_notification_bundle['type'] = 'collection'
Expand All @@ -174,7 +157,7 @@ def run(runnable, inputs = {})
end

it 'fails if SubscriptionStatus does not have the `request` field populated' do
verification_request = stub_request(:post, "#{validator_url}/validate")
verification_request = stub_request(:post, validation_url)
.to_return(status: 200, body: operation_outcome_success.to_json)

full_resource_notification_bundle['entry'].first.delete('request')
Expand All @@ -189,7 +172,7 @@ def run(runnable, inputs = {})
end

it 'fails if SubscriptionStatus does not have the `response` field populated' do
verification_request = stub_request(:post, "#{validator_url}/validate")
verification_request = stub_request(:post, validation_url)
.to_return(status: 200, body: operation_outcome_success.to_json)

full_resource_notification_bundle['entry'].first.delete('response')
Expand All @@ -204,7 +187,7 @@ def run(runnable, inputs = {})
end

it 'fails if SubscriptionStatus does not have the $status operation url in the `request` field' do
verification_request = stub_request(:post, "#{validator_url}/validate")
verification_request = stub_request(:post, validation_url)
.to_return(status: 200, body: operation_outcome_success.to_json)

full_resource_notification_bundle['entry'].first['request']['url'] = 'https://fhirserver.org/fhir/Subscription/123/$wrongoperation'
Expand All @@ -219,7 +202,7 @@ def run(runnable, inputs = {})
end

it 'fails if entry in Bundle does not have the `request` field populated' do
verification_request = stub_request(:post, "#{validator_url}/validate")
verification_request = stub_request(:post, validation_url)
.to_return(status: 200, body: operation_outcome_success.to_json)

full_resource_notification_bundle['entry'].last.delete('request')
Expand All @@ -234,7 +217,7 @@ def run(runnable, inputs = {})
end

it 'fails if entry in Bundle does not have the `response` field populated' do
verification_request = stub_request(:post, "#{validator_url}/validate")
verification_request = stub_request(:post, validation_url)
.to_return(status: 200, body: operation_outcome_success.to_json)

full_resource_notification_bundle['entry'].last.delete('response')
Expand All @@ -260,7 +243,7 @@ def run(runnable, inputs = {})
end

it 'fails if SubscriptionStatus Parameters resource is not conformant' do
verification_request = stub_request(:post, "#{validator_url}/validate")
verification_request = stub_request(:post, validation_url)
.to_return(status: 200, body: operation_outcome_failure.to_json).then
.to_return(status: 200, body: operation_outcome_success.to_json)

Expand All @@ -275,7 +258,7 @@ def run(runnable, inputs = {})
end

it 'fails if SubscriptionStatus type is not set to the notification type passed in' do
verification_request = stub_request(:post, "#{validator_url}/validate")
verification_request = stub_request(:post, validation_url)
.to_return(status: 200, body: operation_outcome_success.to_json)

result = run(test, notification_bundle: full_resource_notification_bundle.to_json,
Expand All @@ -289,7 +272,7 @@ def run(runnable, inputs = {})
end

it 'fails if status argument is passed in but does not equal the status of the SubscriptionStatus' do
verification_request = stub_request(:post, "#{validator_url}/validate")
verification_request = stub_request(:post, validation_url)
.to_return(status: 200, body: operation_outcome_success.to_json)

result = run(test, notification_bundle: full_resource_notification_bundle.to_json,
Expand Down Expand Up @@ -561,7 +544,7 @@ def run(runnable, inputs = {})
end

it 'passes if conformant full-resource notification bundle passed in' do
verification_request = stub_request(:post, "#{validator_url}/validate")
verification_request = stub_request(:post, validation_url)
.to_return(status: 200, body: operation_outcome_success.to_json)

result = run(test, notification_bundle: full_resource_notification_bundle.to_json)
Expand All @@ -582,7 +565,7 @@ def run(runnable, inputs = {})
end

it 'produces warning if full-resource notification bundle does not contain parameter.topic field' do
verification_request = stub_request(:post, "#{validator_url}/validate")
verification_request = stub_request(:post, validation_url)
.to_return(status: 200, body: operation_outcome_success.to_json)

full_resource_notification_bundle['entry'].first['resource']['parameter'].delete_at(1)
Expand All @@ -596,7 +579,7 @@ def run(runnable, inputs = {})
end

it 'fails if SubscriptionStatus does not contain any event-notifications' do
verification_request = stub_request(:post, "#{validator_url}/validate")
verification_request = stub_request(:post, validation_url)
.to_return(status: 200, body: operation_outcome_success.to_json)

full_resource_notification_bundle['entry'].first['resource']['parameter'].pop
Expand All @@ -610,7 +593,7 @@ def run(runnable, inputs = {})
end

it 'fails if any entries in full-resource notification bundle are not conformant' do
verification_request = stub_request(:post, "#{validator_url}/validate")
verification_request = stub_request(:post, validation_url)
.to_return(status: 200, body: operation_outcome_failure.to_json)

result = run(test, notification_bundle: full_resource_notification_bundle.to_json)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
require_relative '../../../lib/subscriptions_test_kit/common/subscription_conformance_verification'

RSpec.describe SubscriptionsTestKit::SubscriptionConformanceVerification do
let(:suite) { Inferno::Repositories::TestSuites.new.find('subscriptions_r5_backport_r4_server') }
let(:session_data_repo) { Inferno::Repositories::SessionData.new }
let(:test_session) { repo_create(:test_session, test_suite_id: suite.id) }
RSpec.describe SubscriptionsTestKit::SubscriptionConformanceVerification, :runnable do
let(:suite_id) { 'subscriptions_r5_backport_r4_server' }
let(:results_repo) { Inferno::Repositories::Results.new }

let(:access_token) { 'SAMPLE_TOKEN' }
let(:subscription_resource) do
JSON.parse(File.read(File.join(
__dir__, '../..', 'fixtures', 'subscription_resource_example.json'
Expand All @@ -17,7 +15,7 @@
outcomes: [{
issues: []
}],
sessionId: 'b8cf5547-1dc7-4714-a797-dc2347b93fe2'
sessionId: test_session.id
}
end

Expand All @@ -29,13 +27,10 @@
message: 'Resource does not conform to profile'
}]
}],
sessionId: 'b8cf5547-1dc7-4714-a797-dc2347b93fe2'
sessionId: test_session.id
}
end

let(:access_token) { 'SAMPLE_TOKEN' }
let(:validator_url) { ENV.fetch('FHIR_RESOURCE_VALIDATOR_URL') }

def entity_result_message(runnable)
results_repo.current_results_for_test_session_and_runnables(test_session.id, [runnable])
.first
Expand All @@ -44,20 +39,6 @@ def entity_result_message(runnable)
.join(' ')
end

def run(runnable, inputs = {})
test_run_params = { test_session_id: test_session.id }.merge(runnable.reference_hash)
test_run = Inferno::Repositories::TestRuns.new.create(test_run_params)
inputs.each do |name, value|
session_data_repo.save(
test_session_id: test_session.id,
name:,
value:,
type: runnable.config.input_type(name)
)
end
Inferno::TestRunner.new(test_session:, test_run:).run(runnable)
end

describe 'Subscription Verification' do
let(:test) do
Class.new(Inferno::Test) do
Expand Down Expand Up @@ -88,7 +69,7 @@ def run(runnable, inputs = {})
end

it 'passes if conformant subscription passed in' do
verification_request = stub_request(:post, "#{validator_url}/validate")
verification_request = stub_request(:post, validation_url)
.to_return(status: 200, body: operation_outcome_success.to_json)

result = run(test, subscription_resource: subscription_resource.to_json)
Expand Down Expand Up @@ -124,7 +105,7 @@ def run(runnable, inputs = {})
end

it 'fails if subscription is not a conformant resource' do
verification_request = stub_request(:post, "#{validator_url}/validate")
verification_request = stub_request(:post, validation_url)
.to_return(status: 200, body: operation_outcome_failure.to_json)

result = run(test, subscription_resource: subscription_resource.to_json)
Expand All @@ -137,7 +118,7 @@ def run(runnable, inputs = {})
end

it 'warns if subscription contains a cross-version extension' do
verification_request = stub_request(:post, "#{validator_url}/validate")
verification_request = stub_request(:post, validation_url)
.to_return(status: 200, body: operation_outcome_success.to_json)

subscription_resource['channel']['_type']['extension'].append(
Expand All @@ -157,7 +138,7 @@ def run(runnable, inputs = {})
it 'fails if subscription does not contain criteria field' do
allow(test).to receive(:suite).and_return(suite)

verification_request = stub_request(:post, "#{validator_url}/validate")
verification_request = stub_request(:post, validation_url)
.to_return(status: 200, body: operation_outcome_success.to_json)

subscription_resource.delete('criteria')
Expand All @@ -171,7 +152,7 @@ def run(runnable, inputs = {})
it 'fails if subscription criteria does not contain valid URL' do
allow(test).to receive(:suite).and_return(suite)

verification_request = stub_request(:post, "#{validator_url}/validate")
verification_request = stub_request(:post, validation_url)
.to_return(status: 200, body: operation_outcome_success.to_json)

subscription_resource['criteria'] = ['Invalid Value']
Expand Down
Loading