Connect to the service only when remote census endpoint is defined

Also return an invalid response when the endpoint is not defined.

This will allow to test remote web services on development environments.
This commit is contained in:
Senén Rodero Rodríguez
2020-10-30 12:25:30 +01:00
committed by Javi Martín
parent ac6260a2ef
commit 265f8dbf01
3 changed files with 12 additions and 3 deletions

View File

@@ -73,7 +73,7 @@ class RemoteCensusApi
private private
def get_response_body(document_type, document_number, date_of_birth, postal_code) 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) request = request(document_type, document_number, date_of_birth, postal_code)
client.call(Setting["remote_census.request.method_name"].to_sym, message: request).body client.call(Setting["remote_census.request.method_name"].to_sym, message: request).body
else else
@@ -118,8 +118,8 @@ class RemoteCensusApi
to_set[final_key] = value to_set[final_key] = value
end end
def end_point_available? def end_point_defined?
!Rails.env.development? Setting["remote_census.general.endpoint"].present?
end end
def stubbed_invalid_response def stubbed_invalid_response

View File

@@ -90,5 +90,13 @@ describe RemoteCensusApi do
api.call("1", "12345678Z", Date.parse("31/12/1980"), "28013") api.call("1", "12345678Z", Date.parse("31/12/1980"), "28013")
end end
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
end end

View File

@@ -106,6 +106,7 @@ RSpec.configure do |config|
end end
config.before(:each, :remote_census) do |example| 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["feature.remote_census"] = true
Setting["remote_census.request.method_name"] = "verify_residence" Setting["remote_census.request.method_name"] = "verify_residence"
Setting["remote_census.request.structure"] = '{ "request": Setting["remote_census.request.structure"] = '{ "request":