Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FI-3475: Unit test improvements #13

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 0 additions & 26 deletions spec/request_helper.rb

This file was deleted.

4 changes: 3 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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') }
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Loading