Return invalid response when document_type or document_number are empty

Probably this case is not real for production environments where those
arguments will always be fullfilled but seems to be interesting for
testing environment where this method is being called when those
paremeters where empty.
This commit is contained in:
Senén Rodero Rodríguez
2020-10-23 15:24:34 +02:00
committed by Javi Martín
parent 06dcbd699c
commit 93e458d46e
2 changed files with 18 additions and 0 deletions

View File

@@ -1,5 +1,7 @@
class CensusCaller class CensusCaller
def call(document_type, document_number, date_of_birth, postal_code) def call(document_type, document_number, date_of_birth, postal_code)
return Response.new if document_number.blank? || document_type.blank?
if Setting["feature.remote_census"].present? if Setting["feature.remote_census"].present?
response = RemoteCensusApi.new.call(document_type, document_number, date_of_birth, postal_code) response = RemoteCensusApi.new.call(document_type, document_number, date_of_birth, postal_code)
else else
@@ -9,4 +11,10 @@ class CensusCaller
response response
end end
class Response
def valid?
false
end
end
end end

View File

@@ -13,6 +13,16 @@ describe CensusCaller do
{ get_habita_datos_response: { get_habita_datos_return: { datos_habitante: {}}}} { get_habita_datos_response: { get_habita_datos_return: { datos_habitante: {}}}}
end end
it "returns invalid response when document_number or document_type are empty" do
response = api.call(1, "", nil, nil)
expect(response).not_to be_valid
response = api.call("", "12345678A", nil, nil)
expect(response).not_to be_valid
end
it "returns local census response when census api response is invalid" do it "returns local census response when census api response is invalid" do
census_api_response = CensusApi::Response.new(invalid_body) census_api_response = CensusApi::Response.new(invalid_body)
allow_any_instance_of(CensusApi).to receive(:call).and_return(census_api_response) allow_any_instance_of(CensusApi).to receive(:call).and_return(census_api_response)