diff --git a/Gemfile.lock b/Gemfile.lock index a0b4ba9..52ce86f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -133,7 +133,7 @@ GEM domain_name (~> 0.5) i18n (1.14.6) concurrent-ruby (~> 1.0) - inferno_core (0.5.0) + inferno_core (0.5.1) activesupport (~> 6.1.7.5) base62-rb (= 0.3.1) blueprinter (= 0.25.2) @@ -167,17 +167,17 @@ GEM json (2.7.2) jwt (2.9.3) base64 - kramdown (2.4.0) - rexml + kramdown (2.5.1) + rexml (>= 3.3.9) language_server-protocol (3.17.0.3) - logger (1.6.1) + logger (1.6.2) method_source (1.1.0) mime-types (3.6.0) logger mime-types-data (~> 3.2015) - mime-types-data (3.2024.1001) - mini_portile2 (2.8.7) - minitest (5.25.1) + mime-types-data (3.2024.1105) + mini_portile2 (2.8.8) + minitest (5.25.2) multi_json (1.15.0) multi_xml (0.7.1) bigdecimal (~> 3.1) @@ -250,7 +250,7 @@ GEM roo (2.10.1) nokogiri (~> 1) rubyzip (>= 1.3.0, < 3.0.0) - rouge (4.4.0) + rouge (4.5.1) rspec (3.13.0) rspec-core (~> 3.13.0) rspec-expectations (~> 3.13.0) diff --git a/lib/subscriptions_test_kit/suites/subscriptions_r5_backport_r4_client/workflow/interaction_test.rb b/lib/subscriptions_test_kit/suites/subscriptions_r5_backport_r4_client/workflow/interaction_test.rb index ee3ff18..842a7fd 100644 --- a/lib/subscriptions_test_kit/suites/subscriptions_r5_backport_r4_client/workflow/interaction_test.rb +++ b/lib/subscriptions_test_kit/suites/subscriptions_r5_backport_r4_client/workflow/interaction_test.rb @@ -3,6 +3,7 @@ module SubscriptionsTestKit module SubscriptionsR5BackportR4Client class InteractionTest < Inferno::Test + include URLs id :subscriptions_r4_client_interaction description %( During this test, the client under test will interact with Inferno following the Subscription diff --git a/spec/request_helper.rb b/spec/request_helper.rb deleted file mode 100644 index 30e3320..0000000 --- a/spec/request_helper.rb +++ /dev/null @@ -1,26 +0,0 @@ -require 'spec_helper' -require 'rack/test' -require 'inferno/apps/web/application' - -module RequestHelpers - def app - Inferno::Web.app - end - - def post_json(path, data) - post path, data.to_json, 'CONTENT_TYPE' => 'application/json' - end - - def parsed_body - JSON.parse(last_response.body) - end -end - -RSpec.configure do |config| - config.define_derived_metadata(file_path: %r{/routes/}) do |metadata| - metadata[:request] = true - end - - config.include Rack::Test::Methods, request: true - config.include RequestHelpers, request: true -end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index f30b83f..65dac30 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -118,6 +118,8 @@ config.before(:suite) do FactoryBot.find_definitions end + + config.shared_context_metadata_behavior = :apply_to_host_groups end require 'inferno/config/application' @@ -127,7 +129,7 @@ require 'inferno' Inferno::Application.finalize! -require Inferno::SpecSupport::FACTORY_BOT_SUPPORT_PATH +Inferno::SpecSupport.require_helpers FactoryBot.definition_file_paths = [ Inferno::SpecSupport::FACTORY_PATH diff --git a/spec/subscriptions_test_kit/subscription_r4_server/common/interaction/notification_delivery_test_spec.rb b/spec/subscriptions_test_kit/subscription_r4_server/common/interaction/notification_delivery_test_spec.rb index 65717ed..63226e9 100644 --- a/spec/subscriptions_test_kit/subscription_r4_server/common/interaction/notification_delivery_test_spec.rb +++ b/spec/subscriptions_test_kit/subscription_r4_server/common/interaction/notification_delivery_test_spec.rb @@ -1,11 +1,7 @@ require_relative '../../../../../lib/subscriptions_test_kit/suites/subscriptions_r5_backport_r4_server/' \ 'common/interaction/notification_delivery_test' -require_relative '../../../../request_helper' - -RSpec.describe SubscriptionsTestKit::SubscriptionsR5BackportR4Server::NotificationDeliveryTest do - include Rack::Test::Methods - include RequestHelpers +RSpec.describe SubscriptionsTestKit::SubscriptionsR5BackportR4Server::NotificationDeliveryTest, :request do let(:suite) { Inferno::Repositories::TestSuites.new.find('subscriptions_r5_backport_r4_server') } let(:test) { Inferno::Repositories::Tests.new.find('subscriptions_r4_server_notification_delivery') } let(:test_group) { Inferno::Repositories::TestGroups.new.find('subscriptions_r4_server_interaction') } diff --git a/spec/subscriptions_test_kit/suites/subscription_r5_backport_r4_client/workflow/interaction_test_spec.rb b/spec/subscriptions_test_kit/suites/subscription_r5_backport_r4_client/workflow/interaction_test_spec.rb new file mode 100644 index 0000000..a0f2ab9 --- /dev/null +++ b/spec/subscriptions_test_kit/suites/subscription_r5_backport_r4_client/workflow/interaction_test_spec.rb @@ -0,0 +1,86 @@ +RSpec.describe SubscriptionsTestKit::SubscriptionsR5BackportR4Client::InteractionTest, :request do + let(:suite_id) { 'subscriptions_r5_backport_r4_client' } + + describe 'performing interactions with the client under test' do + let(:access_token) { '1234' } + + # Pattern for execution with tester inputs + # 1. get the runnable into the `test` variable using the find_test function, + # e.g., let(:test) { find_test(suite, described_class.id) } + # 2. create input hash, e.g., inputs = { ... } + # 3. pass to the run method (defined in the shared context), e.g., result = run(test, inputs) + # let(:test) { find_test(suite, described_class.id) } + let(:test) { described_class } + + describe 'when the tester-provided notification bundle is valid' do + let(:valid_notification_json) do + File.read(File.join(__dir__, '../../../..', 'fixtures', 'empty_notification_bundle_example.json')) + end + let(:resume_pass_url) { "/custom/#{suite_id}/resume_pass" } + let(:resume_fail_url) { "/custom/#{suite_id}/resume_fail" } + let(:results_repo) { Inferno::Repositories::Results.new } + + # Pattern for wait testing + # 1. execute the test, e.g., result = run(test, ...) + # 2. verify the test is waiting, e.g., expect(result.result).to eq('wait') + # 3. perform an action that cause the wait to end, e.g., get(...) + # 4. find the updated result, e.g., result = results_repo.find(result.id) + # 5. verify it is no longer waiting, e.g., expect(result.result).to eq('pass') + it 'passes when the tester chooses to complete the tests' do + inputs = { access_token:, notification_bundle: valid_notification_json } + result = run(test, inputs) + expect(result.result).to eq('wait') + + get("#{resume_pass_url}?test_run_identifier=#{access_token}") + + result = results_repo.find(result.id) + expect(result.result).to eq('pass') + end + + it 'fails when the tester chooses to fail the tests' do + inputs = { access_token:, notification_bundle: valid_notification_json } + result = run(test, inputs) + expect(result.result).to eq('wait') + + get("#{resume_fail_url}?test_run_identifier=#{access_token}") + + result = results_repo.find(result.id) + expect(result.result).to eq('fail') + end + end + + describe 'when the tester-provided notification bundle is not valid' do + it 'fails when the notification bundle is not json' do + inputs = { access_token:, notification_bundle: 'not json' } + result = run(test, inputs) + expect(result.result).to eq('fail') + end + + it 'fails when the notification bundle is not FHIR' do + inputs = { access_token:, notification_bundle: '{"not":"FHIR"}' } + result = run(test, inputs) + expect(result.result).to eq('fail') + end + + it 'fails when the notification bundle is not a Bundle' do + inputs = { access_token:, notification_bundle: '{"resourceType":"Patient"}' } + result = run(test, inputs) + expect(result.result).to eq('fail') + end + + it 'fails when the notification bundle does not contain a Parameters instance' do + inputs = { access_token:, notification_bundle: '{"resourceType":"Bundle"}' } + result = run(test, inputs) + expect(result.result).to eq('fail') + end + + it 'fails when the notification bundle Parameters instance does not contain a subscription parameter entry' do + inputs = { access_token:, + notification_bundle: + '{"resourceType":"Bundle", "entry":[{"resource":{"resourceType":"Parameters"}}]}' } + result = run(test, inputs) + expect(result.result).to eq('fail') + end + end + end +end