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,17 @@
require_relative 'dtr_light_ehr_supported_payer_endpoint_test'

module DaVinciDTRTestKit
class DTRLightEhrSupportedEndpointsGroup < Inferno::TestGroup
id :dtr_light_ehr_supported_endpoints
title '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.

)
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,43 @@
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 %(
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
6 changes: 6 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, LightEHRSupportedPayerEndpoint

group do
title 'Authorization'

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

group from: :dtr_light_ehr_supported_endpoints
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
require_relative '../../tags'

module DaVinciDTRTestKit
class LightEHRSupportedPayerEndpoint < Inferno::DSL::SuiteEndpoint
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
if request.headers['Accept'] == 'application/json'
results_repo.update_result(result.id, 'pass')
else
results_repo.update_result(result.id, 'fail')
end
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 @@ -14,6 +14,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 @@ -50,6 +51,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,67 @@
require_relative '../request_helper'

RSpec.describe DaVinciDTRTestKit::DTRLightEhrSupportedPayerEndpointTest do
include Rack::Test::Methods
include RequestHelpers

def app
Inferno::Web.app
end

let(:group) { Inferno::Repositories::TestGroups.new.find('dtr_light_ehr_supported_payer_endpoint') }
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(:supported_payer_url) { "/custom/#{suite_id}/supported_payers" }
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_payer_url

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_PAYER_TAG])

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_payer_url

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