diff --git a/lib/inferno/dsl/fhir_client_builder.rb b/lib/inferno/dsl/fhir_client_builder.rb index 67e040841..bb8454cc5 100644 --- a/lib/inferno/dsl/fhir_client_builder.rb +++ b/lib/inferno/dsl/fhir_client_builder.rb @@ -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 diff --git a/lib/inferno/dsl/http_client_builder.rb b/lib/inferno/dsl/http_client_builder.rb index 341f50b3f..90dc02b8b 100644 --- a/lib/inferno/dsl/http_client_builder.rb +++ b/lib/inferno/dsl/http_client_builder.rb @@ -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 diff --git a/spec/inferno/dsl/fhir_client_spec.rb b/spec/inferno/dsl/fhir_client_spec.rb index 6c860aba2..0a5b09509 100644 --- a/spec/inferno/dsl/fhir_client_spec.rb +++ b/spec/inferno/dsl/fhir_client_spec.rb @@ -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' @@ -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 diff --git a/spec/inferno/dsl/http_client_spec.rb b/spec/inferno/dsl/http_client_spec.rb index 6729b6c06..7d5843f57 100644 --- a/spec/inferno/dsl/http_client_spec.rb +++ b/spec/inferno/dsl/http_client_spec.rb @@ -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) @@ -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