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-3463: DTR Light EHR: test supported payer endpoint #42

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
require_relative 'dtr_light_ehr_supported_payer_endpoint_test'

module DaVinciDTRTestKit
class DTRLightEhrSupportedEndpointsGroup < Inferno::TestGroup
id :dtr_light_ehr_supported_endpoints
title 'DTR Supported Endpoints'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
title 'DTR Supported Endpoints'
title 'Supported Endpoints'

description %(
Demonstrate the ability to access supported endpoints
)
run_as_group

test from: :dtr_light_ehr_supported_payer_endpoint
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
require_relative '../../urls'

module DaVinciDTRTestKit
class DtrLightEhrSupportedPayerEndpointTest < Inferno::Test
include URLs
id :dtr_light_ehr_supported_payer_endpoint
title 'Client can retrieve payers from supported payer endpoint'
description %(
Inferno, will wait for a request to return the payer details from the supported endpoint.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be a description of what this test checks. something like, 'This test verifies that the app can successfully access the supported payer endpoint via a GET request, including an Accept header set to application/json'.

)
input :access_token,
description: %(
`Bearer` token that the client under test will send in the
`Authorization` header of each HTTP request to Inferno. Inferno
will look for this value to associate requests with this session.
)

run do
wait(
identifier: access_token,
message: %(
### Supported Payer Endpoint

Inferno will wait for the Light EHR to to make a GET request to

`#{supported_payer_url}`

Inferno will return the static payers json details

### Request Identification

In order to identify requests for this session, Inferno will look for
an `Authorization` header with value:

```
Bearer #{access_token}
```
)
)
end
end
end
16 changes: 16 additions & 0 deletions lib/davinci_dtr_test_kit/dtr_light_ehr_suite.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
require_relative 'profiles/service_request_group'
require_relative 'profiles/task_group'
require_relative 'profiles/vision_prescription_group'
require_relative 'endpoints/mock_payer/light_ehr_supported_payer_endpoint'
require_relative 'client_groups/light_ehr/dtr_light_ehr_supported_endpoints_group'
require 'smart_app_launch/smart_stu1_suite'
require 'smart_app_launch/smart_stu2_suite'

Expand Down Expand Up @@ -55,6 +57,8 @@ class DTRLightEHRSuite < Inferno::TestSuite
end
end

suite_endpoint :get, SUPPORTED_PAYER_PATH, MockPayer::LightEHRSupportedPayerEndpoint

group do
title 'Authorization'

Expand Down Expand Up @@ -136,5 +140,17 @@ class DTRLightEHRSuite < Inferno::TestSuite
group from: :task_group
group from: :vision_prescription_group
end

group do
title 'DTR Light EHR Supported Endpoints'
description %(This test group tests system for their conformance to
the supported endpoint capabilities as defined by the DaVinci Documentation
Templates and Rules (DTR) v2.0.1 Implementation Guide Light DTR EHR
Capability Statement.

)

group from: :dtr_light_ehr_supported_endpoints
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don’t need to nest group from: :dtr_light_ehr_supported_endpoints within another group. You can simply use group from: :dtr_light_ehr_supported_endpoints directly. Update the dtr_light_ehr_supported_endpoints_group.rb file with this description.

end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
require_relative '../mock_payer'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be removed, since no functionality from that module is being used here.

require_relative '../../tags'

module DaVinciDTRTestKit
module MockPayer
class LightEHRSupportedPayerEndpoint < Inferno::DSL::SuiteEndpoint
include MockPayer
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this as well


def name
'light_ehr_supported_payer_endpoint'
end

def test_run_identifier
request.headers['authorization']&.delete_prefix('Bearer ')
end

def tags
[SUPPORTED_PAYER_TAG]
end

def make_response
puts "Request method: #{request.request_method}"
if request.headers['Accept'] != 'application/json'
response.status = 406
response.headers['Content-Type'] = 'application/json'
response.body = { error: 'Not Acceptable', message: 'Accept header must be application/json' }.to_json
return
end

response.status = 200
response.headers['Content-Type'] = 'application/json'
response.body = {
payers: [
{ id: 'payer1', name: 'Payer One' },
{ id: 'payer2', name: 'Payer Two' }
]
}.to_json
end

def update_result
results_repo.update_result(result.id, 'pass') unless test.config.options[:accepts_multiple_requests]
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Modify this logic so that it fails if the Accept header is not application/json and passes otherwise.

end
end
end
1 change: 1 addition & 0 deletions lib/davinci_dtr_test_kit/tags.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ module DaVinciDTRTestKit
QUESTIONNAIRE_PACKAGE_TAG = 'dtr_questionnaire_package'.freeze
CLIENT_NEXT_TAG = 'dtr_questionnaire_next_question'.freeze
EHR_AUTHORIZE_TAG = 'dtr_smart_app_ehr_authorize'.freeze
SUPPORTED_PAYER_TAG = 'light_ehr_supported_payer_endpoint'.freeze
end
5 changes: 5 additions & 0 deletions lib/davinci_dtr_test_kit/urls.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module DaVinciDTRTestKit
QUESTIONNAIRE_RESPONSE_PATH = "#{FHIR_BASE_PATH}/QuestionnaireResponse".freeze
FHIR_RESOURCE_PATH = "#{FHIR_BASE_PATH}/:resource/:id".freeze
FHIR_SEARCH_PATH = "#{FHIR_BASE_PATH}/:resource".freeze
SUPPORTED_PAYER_PATH = '/supported-payers'
RESUME_PASS_PATH = '/resume_pass'
RESUME_FAIL_PATH = '/resume_fail'

Expand Down Expand Up @@ -49,6 +50,10 @@ def fhir_base_url
@fhir_base_url ||= base_url + FHIR_BASE_PATH
end

def supported_payer_url
@supported_payer_url ||= base_url + SUPPORTED_PAYER_PATH
end

def resume_pass_url
@resume_pass_url ||= base_url + RESUME_PASS_PATH
end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
require_relative '../request_helper'

RSpec.describe DaVinciDTRTestKit::DTRLightEhrSupportedEndpointsGroup do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

write spec for the Test directly instead of the group.

include Rack::Test::Methods
include RequestHelpers

def app
Inferno::Web.app
end

let(:suite_id) { :dtr_light_ehr }
let(:resume_pass_url) { "/custom/#{suite_id}/resume_pass" }
let(:resume_fail_url) { "/custom/#{suite_id}/resume_fail" }
let(:session_data_repo) { Inferno::Repositories::SessionData.new }
let(:test_session) { repo_create(:test_session, test_suite_id: suite_id) }
let(:test_runs_repo) { Inferno::Repositories::TestRuns.new }
let(:results_repo) { Inferno::Repositories::Results.new }

def run(runnable, test_session, 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) || :text
)
end
Inferno::TestRunner.new(test_session:, test_run:).run(runnable)
end

describe 'Supported Payers Endpoint' do
let(:runnable) { Inferno::Repositories::TestGroups.new.find('light_ehr_supported_payer_endpoint') }

it 'passes when a request is made to the supported payers endpoint' do
header 'Accept', 'application/json'
get '/supported-payers'

expect(last_response.status).to eq(200)
expect(last_response.content_type).to eq('application/json')
expect(JSON.parse(last_response.body)['payers']).to be_an(Array)

result = repo_create(:result, test_session_id: test_session.id)
repo_create(:request, result_id: result.id, name: 'supported_payers', request_body: nil,
test_session_id: test_session.id, tags: ['supported_payers'])

result = run(runnable, test_session)
expect(result.result).to eq('wait')

token = test_runs_repo.last_test_run(test_session.id).identifier
get("#{resume_pass_url}?token=#{token}")

result = results_repo.find(result.id)
expect(result.result).to eq('pass')
end

it 'returns 406 when Accept header is missing or incorrect' do
get '/supported-payers'

expect(last_response.status).to eq(406)
expect(JSON.parse(last_response.body)['error']).to eq('Not Acceptable')
end
end
end
Loading