diff --git a/lib/remote_census_api.rb b/lib/remote_census_api.rb index 5cea6142e..e91de7e12 100644 --- a/lib/remote_census_api.rb +++ b/lib/remote_census_api.rb @@ -73,7 +73,7 @@ class RemoteCensusApi private def get_response_body(document_type, document_number, date_of_birth, postal_code) - if end_point_available? + if end_point_defined? request = request(document_type, document_number, date_of_birth, postal_code) client.call(Setting["remote_census.request.method_name"].to_sym, message: request).body else @@ -118,8 +118,8 @@ class RemoteCensusApi to_set[final_key] = value end - def end_point_available? - !Rails.env.development? + def end_point_defined? + Setting["remote_census.general.endpoint"].present? end def stubbed_invalid_response diff --git a/spec/lib/remote_census_api_spec.rb b/spec/lib/remote_census_api_spec.rb index 152d1b946..2e25b6e1e 100644 --- a/spec/lib/remote_census_api_spec.rb +++ b/spec/lib/remote_census_api_spec.rb @@ -90,5 +90,13 @@ describe RemoteCensusApi do api.call("1", "12345678Z", Date.parse("31/12/1980"), "28013") end end + + it "returns an invalid response when endpoint is not defined" do + allow_any_instance_of(RemoteCensusApi).to receive(:end_point_defined?).and_return(false) + + response = api.call("1", "12345678Z", Date.parse("01/01/1983"), "28013") + + expect(response).not_to be_valid + end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index df40b8c01..00b5c8c9e 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -106,6 +106,7 @@ RSpec.configure do |config| end config.before(:each, :remote_census) do |example| + allow_any_instance_of(RemoteCensusApi).to receive(:end_point_defined?).and_return(true) Setting["feature.remote_census"] = true Setting["remote_census.request.method_name"] = "verify_residence" Setting["remote_census.request.structure"] = '{ "request":