Skip to content

Commit

Permalink
FI-2567: Fix client instance variables (#464)
Browse files Browse the repository at this point in the history
* add specs to for inputs in http/fhir clients

* replace #call with #send

* fix linting errors
  • Loading branch information
Jammjammjamm authored Mar 8, 2024
1 parent e7663b7 commit 1c9c0b0
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/inferno/dsl/fhir_client_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def headers(headers = nil)

# @private
def method_missing(name, *args, &)
return runnable.call(name, *args, &) if runnable.respond_to? name
return runnable.send(name, *args, &) if runnable.respond_to? name

super
end
Expand Down
2 changes: 1 addition & 1 deletion lib/inferno/dsl/http_client_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def headers(headers = nil)

# @private
def method_missing(name, *args, &)
return runnable.call(name, *args, &) if runnable.respond_to? name
return runnable.send(name, *args, &) if runnable.respond_to? name

super
end
Expand Down
24 changes: 24 additions & 0 deletions spec/inferno/dsl/fhir_client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ def test_session_id
let(:default_client) { group.fhir_clients[:default] }
let(:bundle) { FHIR::Bundle.new(type: 'history', entry: [{ resource: }]) }
let(:session_data_repo) { Inferno::Repositories::SessionData.new }
let(:test) do
Class.new(Inferno::Entities::Test) do
input :foo

fhir_client do
url 'http://www.example.com/fhir'
headers 'Authorization' => "Basic #{foo}"
end
end
end
let(:boolean_parameter) do
FHIR::Parameters::Parameter.new.tap do |param|
param.name = 'PARAM_BOOL'
Expand Down Expand Up @@ -133,6 +143,20 @@ def test_session_id
end.to raise_error(SocketError, 'not a TCP error')
end
end

context 'with input references' do
it 'gets the input value from the runnable' do
runnable = test.new(inputs: { foo: 'BLAH' })
request =
stub_request(:get, "#{base_url}/Patient/1")
.with(headers: { 'Authorization' => 'Basic BLAH' })
.to_return(status: 200, body: FHIR::Patient.new(id: 1).to_json)

runnable.fhir_read(:patient, '1')

expect(request).to have_been_made.once
end
end
end

describe '#body_to_path' do
Expand Down
24 changes: 24 additions & 0 deletions spec/inferno/dsl/http_client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ def test_session_id
let(:resource_id) { '123' }
let(:resource) { FHIR::CarePlan.new(id: resource_id) }
let(:response_body) { 'RESPONSE_BODY' }
let(:test) do
Class.new(Inferno::Entities::Test) do
input :foo

http_client do
url 'http://www.example.com'
headers 'Authorization' => "Basic #{foo}"
end
end
end
let(:default_client) do
block = proc { url 'http://www.example.com' }
Inferno::DSL::HTTPClientBuilder.new.build(group, block)
Expand Down Expand Up @@ -92,6 +102,20 @@ def setup_default_client
end.to raise_error(Faraday::ConnectionFailed, 'not a TCP error')
end
end

context 'with input references' do
it 'gets the input value from the runnable' do
runnable = test.new(inputs: { foo: 'BLAH' })
request =
stub_request(:get, base_url)
.with(headers: { 'Authorization' => 'Basic BLAH' })
.to_return(status: 200, body: FHIR::Patient.new(id: 1).to_json)

runnable.get

expect(request).to have_been_made.once
end
end
end

describe '#get' do
Expand Down

0 comments on commit 1c9c0b0

Please sign in to comment.