Use shorter responses and configuration for specs
By simplyfing the responses the configuration for specs can be simpler too. We're also using more generic terms instead of the ones used in Madrid's Census API. Co-Authored-By: Javi Martín <javim@elretirao.net>
This commit is contained in:
committed by
Javi Martín
parent
3ed4bdaff8
commit
dd0f56f85f
@@ -51,9 +51,9 @@ class RemoteCensusApi
|
||||
path_value = Setting["remote_census.response.gender"]
|
||||
|
||||
case extract_value(path_value)
|
||||
when "Varón"
|
||||
when "Male", "Varón"
|
||||
"male"
|
||||
when "Mujer"
|
||||
when "Female", "Mujer"
|
||||
"female"
|
||||
end
|
||||
end
|
||||
@@ -132,29 +132,21 @@ class RemoteCensusApi
|
||||
|
||||
def stubbed_valid_response
|
||||
{
|
||||
get_habita_datos_response: {
|
||||
get_habita_datos_return: {
|
||||
datos_habitante: {
|
||||
item: {
|
||||
fecha_nacimiento_string: "31-12-1980",
|
||||
identificador_documento: "12345678Z",
|
||||
descripcion_sexo: "Varón",
|
||||
nombre: "José",
|
||||
apellido1: "García"
|
||||
}
|
||||
},
|
||||
datos_vivienda: {
|
||||
item: {
|
||||
codigo_postal: "28013",
|
||||
codigo_distrito: "01"
|
||||
}
|
||||
}
|
||||
response: {
|
||||
data: {
|
||||
date_of_birth: "31-12-1980",
|
||||
document_number: "12345678Z",
|
||||
gender: "Male",
|
||||
name: "William",
|
||||
surname: "Widmore",
|
||||
postal_code: "28013",
|
||||
district_code: "01"
|
||||
}
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
def stubbed_invalid_response
|
||||
{ get_habita_datos_response: { get_habita_datos_return: { datos_habitante: {}, datos_vivienda: {}}}}
|
||||
{ response: { data: {}}}
|
||||
end
|
||||
end
|
||||
|
||||
@@ -45,6 +45,9 @@ describe CensusCaller do
|
||||
end
|
||||
|
||||
describe "RemoteCensusApi", :remote_census do
|
||||
let(:valid_body) { { response: { data: { document_number: "12345678" }}} }
|
||||
let(:invalid_body) { { response: { data: {}}} }
|
||||
|
||||
it "returns remote census api response when it's available and response is valid" do
|
||||
remote_census_api_response = RemoteCensusApi::Response.new(valid_body)
|
||||
allow_any_instance_of(RemoteCensusApi).to receive(:call).and_return(remote_census_api_response)
|
||||
|
||||
@@ -4,21 +4,13 @@ describe RemoteCensusApi do
|
||||
let(:api) { RemoteCensusApi.new }
|
||||
|
||||
describe "#call", :remote_census do
|
||||
let(:invalid_body) { { get_habita_datos_response: { get_habita_datos_return: { datos_habitante: {}}}} }
|
||||
let(:valid_body) do
|
||||
{
|
||||
get_habita_datos_response: {
|
||||
get_habita_datos_return: {
|
||||
datos_habitante: {
|
||||
item: {
|
||||
fecha_nacimiento_string: "1-1-1980"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
before do
|
||||
Setting["remote_census.response.valid"] = "response.data.date_of_birth"
|
||||
end
|
||||
|
||||
let(:invalid_body) { { response: { data: {}}} }
|
||||
let(:valid_body) { { response: { data: { date_of_birth: "1-1-1980" }}} }
|
||||
|
||||
it "returns the response for the first valid variant" do
|
||||
date = Date.parse("01/01/1983")
|
||||
allow(api).to receive(:get_response_body).with(1, "00123456", date, "28001").and_return(invalid_body)
|
||||
@@ -153,23 +145,15 @@ describe RemoteCensusApi do
|
||||
|
||||
response = RemoteCensusApi.new.send(:get_response_body, document_type, document_number, nil, nil)
|
||||
|
||||
expect(response).to eq({ get_habita_datos_response: {
|
||||
get_habita_datos_return: {
|
||||
datos_habitante: {
|
||||
item: {
|
||||
fecha_nacimiento_string: "31-12-1980",
|
||||
identificador_documento: "12345678Z",
|
||||
descripcion_sexo: "Varón",
|
||||
nombre: "José",
|
||||
apellido1: "García"
|
||||
}
|
||||
},
|
||||
datos_vivienda: {
|
||||
item: {
|
||||
codigo_postal: "28013",
|
||||
codigo_distrito: "01"
|
||||
}
|
||||
}
|
||||
expect(response).to eq({ response: {
|
||||
data: {
|
||||
date_of_birth: "31-12-1980",
|
||||
document_number: "12345678Z",
|
||||
gender: "Male",
|
||||
name: "William",
|
||||
surname: "Widmore",
|
||||
postal_code: "28013",
|
||||
district_code: "01"
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -187,9 +171,8 @@ describe RemoteCensusApi do
|
||||
expect(response.valid?).to eq true
|
||||
expect(response.date_of_birth).to eq Time.zone.local(1980, 12, 31).to_date
|
||||
expect(response.postal_code).to eq "28013"
|
||||
expect(response.district_code).to eq "01"
|
||||
expect(response.gender).to eq "male"
|
||||
expect(response.name).to eq "José García"
|
||||
expect(response.name).to eq "William Widmore"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -106,35 +106,28 @@ RSpec.configure do |config|
|
||||
end
|
||||
|
||||
config.before(:each, :remote_census) do |example|
|
||||
Setting["remote_census.request.method_name"] = "get_habita_datos"
|
||||
Setting["remote_census.request.document_type"] = "request.tipo_documento"
|
||||
Setting["remote_census.request.document_number"] = "request.documento"
|
||||
Setting["remote_census.request.date_of_birth"] = "request.fecha_nacimiento"
|
||||
Setting["remote_census.request.postal_code"] = "request.codigo_postal"
|
||||
Setting["feature.remote_census"] = true
|
||||
Setting["remote_census.request.method_name"] = "verify_residence"
|
||||
Setting["remote_census.request.structure"] = '{ "request":
|
||||
{
|
||||
"codigo_institucion": 1,
|
||||
"codigo_portal": 1,
|
||||
"codigo_usuario": 1,
|
||||
"documento": "nil",
|
||||
"tipo_documento": "null",
|
||||
"fecha_nacimiento": "null",
|
||||
"codigo_postal": "nil",
|
||||
"codigo_idioma": 102,
|
||||
"nivel": 3
|
||||
"document_type": "null",
|
||||
"document_number": "nil",
|
||||
"date_of_birth": "null",
|
||||
"postal_code": "nil"
|
||||
}
|
||||
}'
|
||||
|
||||
access_user_data = "get_habita_datos_response.get_habita_datos_return.datos_habitante.item"
|
||||
access_residence_data = "get_habita_datos_response.get_habita_datos_return.datos_vivienda.item"
|
||||
Setting["remote_census.response.date_of_birth"] = "#{access_user_data}.fecha_nacimiento_string"
|
||||
Setting["remote_census.response.postal_code"] = "#{access_residence_data}.codigo_postal"
|
||||
Setting["remote_census.response.district"] = "#{access_residence_data}.codigo_distrito"
|
||||
Setting["remote_census.response.gender"] = "#{access_user_data}.descripcion_sexo"
|
||||
Setting["remote_census.response.name"] = "#{access_user_data}.nombre"
|
||||
Setting["remote_census.response.surname"] = "#{access_user_data}.apellido1"
|
||||
Setting["remote_census.response.valid"] = access_user_data
|
||||
Setting["feature.remote_census"] = true
|
||||
Setting["remote_census.request.document_type"] = "request.document_type"
|
||||
Setting["remote_census.request.document_number"] = "request.document_number"
|
||||
Setting["remote_census.request.date_of_birth"] = "request.date_of_birth"
|
||||
Setting["remote_census.request.postal_code"] = "request.postal_code"
|
||||
Setting["remote_census.response.date_of_birth"] = "response.data.date_of_birth"
|
||||
Setting["remote_census.response.postal_code"] = "response.data.postal_code"
|
||||
Setting["remote_census.response.district"] = "response.data.district_code"
|
||||
Setting["remote_census.response.gender"] = "response.data.gender"
|
||||
Setting["remote_census.response.name"] = "response.data.name"
|
||||
Setting["remote_census.response.surname"] = "response.data.surname"
|
||||
Setting["remote_census.response.valid"] = "response.data.document_number"
|
||||
end
|
||||
|
||||
# Allows RSpec to persist some state between runs in order to support
|
||||
|
||||
Reference in New Issue
Block a user