Extract block to configure remote census in tests

Co-Authored-By: Javi Martín <javim@elretirao.net>
This commit is contained in:
Senén Rodero Rodríguez
2020-09-29 15:53:55 +02:00
committed by Javi Martín
parent b170949fc1
commit 06dcbd699c
11 changed files with 48 additions and 128 deletions

View File

@@ -8,12 +8,11 @@ describe SignatureSheetsHelper do
end end
end end
describe "#required_fields_to_verify_text_help with remote_census active" do describe "#required_fields_to_verify_text_help with remote_census active", :remote_census do
before do
Setting["feature.remote_census"] = true
end
it "returns text help when date_of_birth and postal_code are not required" do it "returns text help when date_of_birth and postal_code are not required" do
Setting["remote_census.request.date_of_birth"] = nil
Setting["remote_census.request.postal_code"] = nil
text_help_1 = "To verify a user, your application needs: Document number" text_help_1 = "To verify a user, your application needs: Document number"
text_help_2 = "Required fields for each user must be separated by commas and each user must be separated by semicolons." text_help_2 = "Required fields for each user must be separated by commas and each user must be separated by semicolons."
text_example = "Example: 12345678Z; 87654321Y" text_example = "Example: 12345678Z; 87654321Y"
@@ -24,7 +23,7 @@ describe SignatureSheetsHelper do
end end
it "returns text help when date_of_birth is required" do it "returns text help when date_of_birth is required" do
Setting["remote_census.request.date_of_birth"] = "some.value" Setting["remote_census.request.postal_code"] = nil
text_help_1 = "To verify a user, your application needs: Document number, Day of birth (dd/mm/yyyy)" text_help_1 = "To verify a user, your application needs: Document number, Day of birth (dd/mm/yyyy)"
text_help_2 = "Required fields for each user must be separated by commas and each user must be separated by semicolons." text_help_2 = "Required fields for each user must be separated by commas and each user must be separated by semicolons."
@@ -33,12 +32,10 @@ describe SignatureSheetsHelper do
expect(required_fields_to_verify_text_help).to include(text_help_1) expect(required_fields_to_verify_text_help).to include(text_help_1)
expect(required_fields_to_verify_text_help).to include(text_help_2) expect(required_fields_to_verify_text_help).to include(text_help_2)
expect(example_text_help).to include(text_example) expect(example_text_help).to include(text_example)
Setting["remote_census.request.date_of_birth"] = nil
end end
it "returns text help when postal_code is required" do it "returns text help when postal_code is required" do
Setting["remote_census.request.postal_code"] = "some.value" Setting["remote_census.request.date_of_birth"] = nil
text_help_1 = "To verify a user, your application needs: Document number and Postal Code" text_help_1 = "To verify a user, your application needs: Document number and Postal Code"
text_help_2 = "Required fields for each user must be separated by commas and each user must be separated by semicolons." text_help_2 = "Required fields for each user must be separated by commas and each user must be separated by semicolons."
@@ -47,14 +44,9 @@ describe SignatureSheetsHelper do
expect(required_fields_to_verify_text_help).to include(text_help_1) expect(required_fields_to_verify_text_help).to include(text_help_1)
expect(required_fields_to_verify_text_help).to include(text_help_2) expect(required_fields_to_verify_text_help).to include(text_help_2)
expect(example_text_help).to include(text_example) expect(example_text_help).to include(text_example)
Setting["remote_census.request.postal_code"] = nil
end end
it "returns text help when date_of_birth and postal_code are required" do it "returns text help when date_of_birth and postal_code are required" do
Setting["remote_census.request.date_of_birth"] = "some.value"
Setting["remote_census.request.postal_code"] = "some.value"
text_help_1 = "To verify a user, your application needs: Document number, Day of birth (dd/mm/yyyy) and Postal Code" text_help_1 = "To verify a user, your application needs: Document number, Day of birth (dd/mm/yyyy) and Postal Code"
text_help_2 = "Required fields for each user must be separated by commas and each user must be separated by semicolons." text_help_2 = "Required fields for each user must be separated by commas and each user must be separated by semicolons."
text_example = "Example: 12345678Z, 01/01/1980, 28001; 87654321Y, 01/02/1990, 28002" text_example = "Example: 12345678Z, 01/01/1980, 28001; 87654321Y, 01/02/1990, 28002"
@@ -62,9 +54,6 @@ describe SignatureSheetsHelper do
expect(required_fields_to_verify_text_help).to include(text_help_1) expect(required_fields_to_verify_text_help).to include(text_help_1)
expect(required_fields_to_verify_text_help).to include(text_help_2) expect(required_fields_to_verify_text_help).to include(text_help_2)
expect(example_text_help).to include(text_example) expect(example_text_help).to include(text_example)
Setting["remote_census.request.postal_code"] = nil
Setting["remote_census.request.postal_code"] = nil
end end
end end
end end

View File

@@ -34,13 +34,7 @@ describe CensusCaller do
end end
end end
describe "RemoteCensusApi" do describe "RemoteCensusApi", :remote_census do
before do
Setting["feature.remote_census"] = true
access_user_data = "get_habita_datos_response.get_habita_datos_return.datos_habitante.item"
Setting["remote_census.response.valid"] = access_user_data
end
it "returns remote census api response when it's available and response is valid" do it "returns remote census api response when it's available and response is valid" do
remote_census_api_response = RemoteCensusApi::Response.new(valid_body) remote_census_api_response = RemoteCensusApi::Response.new(valid_body)
allow_any_instance_of(RemoteCensusApi).to receive(:call).and_return(remote_census_api_response) allow_any_instance_of(RemoteCensusApi).to receive(:call).and_return(remote_census_api_response)

View File

@@ -3,7 +3,7 @@ require "rails_helper"
describe RemoteCensusApi do describe RemoteCensusApi do
let(:api) { RemoteCensusApi.new } let(:api) { RemoteCensusApi.new }
describe "#call" do describe "#call", :remote_census do
let(:invalid_body) { { get_habita_datos_response: { get_habita_datos_return: { datos_habitante: {}}}} } let(:invalid_body) { { get_habita_datos_response: { get_habita_datos_return: { datos_habitante: {}}}} }
let(:valid_body) do let(:valid_body) do
{ {
@@ -19,14 +19,6 @@ describe RemoteCensusApi do
} }
end end
before do
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.valid"] = access_user_data
end
it "returns the response for the first valid variant" do it "returns the response for the first valid variant" do
date = Date.parse("01/01/1983") date = Date.parse("01/01/1983")
allow(api).to receive(:get_response_body).with(1, "00123456", date, "28001").and_return(invalid_body) allow(api).to receive(:get_response_body).with(1, "00123456", date, "28001").and_return(invalid_body)
@@ -184,20 +176,7 @@ describe RemoteCensusApi do
end end
end end
describe "RemoteCensusApi::Response" do describe "RemoteCensusApi::Response", :remote_census do
before do
Setting["feature.remote_census"] = true
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
end
it "return expected response methods with default values" do it "return expected response methods with default values" do
document_type = "1" document_type = "1"
document_number = "12345678Z" document_number = "12345678Z"

View File

@@ -34,7 +34,7 @@ describe Officing::Residence do
expect(residence).to be_valid expect(residence).to be_valid
end end
describe "custom validations" do describe "custom validations", :remote_census do
let(:custom_residence) do let(:custom_residence) do
build(:officing_residence, build(:officing_residence,
document_number: "12345678Z", document_number: "12345678Z",
@@ -42,17 +42,6 @@ describe Officing::Residence do
postal_code: "28001") postal_code: "28001")
end end
before do
Setting["feature.remote_census"] = true
Setting["remote_census.request.date_of_birth"] = "some.value"
Setting["remote_census.request.postal_code"] = "some.value"
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.valid"] = access_user_data
end
it "is valid" do it "is valid" do
expect(custom_residence).to be_valid expect(custom_residence).to be_valid
end end

View File

@@ -225,18 +225,7 @@ describe Signature do
end end
describe "document in census throught CustomCensusApi" do describe "document in census throught CustomCensusApi" do
before do it "calls assign_vote_to_user", :remote_census do
Setting["feature.remote_census"] = true
Setting["remote_census.request.date_of_birth"] = "some.value"
Setting["remote_census.request.postal_code"] = "some.value"
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.valid"] = access_user_data
end
it "calls assign_vote_to_user" do
signature = create(:signature, document_number: "12345678Z", signature = create(:signature, document_number: "12345678Z",
date_of_birth: "31/12/1980", date_of_birth: "31/12/1980",
postal_code: "28013") postal_code: "28013")

View File

@@ -28,18 +28,7 @@ describe Verification::Management::Document do
expect(verification_document).to be_valid expect(verification_document).to be_valid
end end
describe "custom validations with RemoteCensus enabled" do describe "custom validations with RemoteCensus enabled", :remote_census do
before do
Setting["feature.remote_census"] = true
Setting["remote_census.request.date_of_birth"] = "some.value"
Setting["remote_census.request.postal_code"] = "some.value"
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.valid"] = access_user_data
end
it "is valid" do it "is valid" do
expect(verification_document).to be_valid expect(verification_document).to be_valid
end end

View File

@@ -105,6 +105,38 @@ RSpec.configure do |config|
allow(Time).to receive(:zone).and_return(application_zone) allow(Time).to receive(:zone).and_return(application_zone)
end 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["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
}
}'
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
end
# Allows RSpec to persist some state between runs in order to support # Allows RSpec to persist some state between runs in order to support
# the `--only-failures` and `--next-failure` CLI options. # the `--only-failures` and `--next-failure` CLI options.
config.example_status_persistence_file_path = "spec/examples.txt" config.example_status_persistence_file_path = "spec/examples.txt"

View File

@@ -76,18 +76,7 @@ describe "Signature sheets" do
end end
end end
context "Create throught all required_fields_to_verify of custom census api" do context "Create throught all required_fields_to_verify of custom census api", :remote_census do
before do
Setting["feature.remote_census"] = true
Setting["remote_census.request.date_of_birth"] = "some.value"
Setting["remote_census.request.postal_code"] = "some.value"
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.valid"] = access_user_data
end
scenario "Proposal" do scenario "Proposal" do
proposal = create(:proposal) proposal = create(:proposal)
visit new_admin_signature_sheet_path visit new_admin_signature_sheet_path

View File

@@ -53,18 +53,7 @@ describe "DocumentVerifications" do
end end
end end
context "Remote Census API" do context "Remote Census API", :remote_census do
before do
Setting["feature.remote_census"] = true
Setting["remote_census.request.date_of_birth"] = "some.value"
Setting["remote_census.request.postal_code"] = "some.value"
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.valid"] = access_user_data
end
scenario "Verifying a user which does not exist and is not in the census shows an error" do scenario "Verifying a user which does not exist and is not in the census shows an error" do
expect_any_instance_of(Verification::Management::Document).to receive(:in_census?). expect_any_instance_of(Verification::Management::Document).to receive(:in_census?).
and_return(false) and_return(false)

View File

@@ -111,11 +111,8 @@ describe "Residence", :with_frozen_time do
expect(page).to have_content "Vote introduced!" expect(page).to have_content "Vote introduced!"
end end
context "With remote census configuration" do context "With remote census configuration", :remote_census do
before do before do
Setting["feature.remote_census"] = true
Setting["remote_census.request.date_of_birth"] = "some.value"
Setting["remote_census.request.postal_code"] = "some.value"
create(:poll_officer_assignment, officer: officer) create(:poll_officer_assignment, officer: officer)
login_through_form_as_officer(officer.user) login_through_form_as_officer(officer.user)
visit officing_root_path visit officing_root_path
@@ -137,9 +134,6 @@ describe "Residence", :with_frozen_time do
end end
scenario "with all custom census not display year_of_birth" do scenario "with all custom census not display year_of_birth" do
Setting["remote_census.request.date_of_birth"] = "some.value"
Setting["remote_census.request.postal_code"] = "some.value"
within("#side_menu") do within("#side_menu") do
click_link "Validate document" click_link "Validate document"
end end
@@ -153,11 +147,6 @@ describe "Residence", :with_frozen_time do
end end
scenario "can verify voter with date_of_birth and postal_code fields" do scenario "can verify voter with date_of_birth and postal_code fields" do
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.valid"] = access_user_data
within("#side_menu") do within("#side_menu") do
click_link "Validate document" click_link "Validate document"
end end

View File

@@ -20,14 +20,7 @@ describe "Residence" do
expect(page).to have_content "Residence verified" expect(page).to have_content "Residence verified"
end end
scenario "Verify resident throught RemoteCensusApi" do scenario "Verify resident throught RemoteCensusApi", :remote_census do
Setting["feature.remote_census"] = true
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.valid"] = access_user_data
user = create(:user) user = create(:user)
login_as(user) login_as(user)
@@ -42,7 +35,6 @@ describe "Residence" do
click_button "Verify residence" click_button "Verify residence"
expect(page).to have_content "Residence verified" expect(page).to have_content "Residence verified"
Setting["feature.remote_census"] = nil
end end
scenario "Residence form use min age to participate" do scenario "Residence form use min age to participate" do