diff --git a/spec/helpers/signature_sheets_helper_spec.rb b/spec/helpers/signature_sheets_helper_spec.rb index 8e2e5efcc..e9b6a2953 100644 --- a/spec/helpers/signature_sheets_helper_spec.rb +++ b/spec/helpers/signature_sheets_helper_spec.rb @@ -8,12 +8,11 @@ describe SignatureSheetsHelper do end end - describe "#required_fields_to_verify_text_help with remote_census active" do - before do - Setting["feature.remote_census"] = true - end - + describe "#required_fields_to_verify_text_help with remote_census active", :remote_census 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_2 = "Required fields for each user must be separated by commas and each user must be separated by semicolons." text_example = "Example: 12345678Z; 87654321Y" @@ -24,7 +23,7 @@ describe SignatureSheetsHelper do end 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_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_2) expect(example_text_help).to include(text_example) - - Setting["remote_census.request.date_of_birth"] = nil end 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_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_2) expect(example_text_help).to include(text_example) - - Setting["remote_census.request.postal_code"] = nil end 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_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" @@ -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_2) 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 diff --git a/spec/lib/census_caller_spec.rb b/spec/lib/census_caller_spec.rb index 5f65076f2..2e910204f 100644 --- a/spec/lib/census_caller_spec.rb +++ b/spec/lib/census_caller_spec.rb @@ -34,13 +34,7 @@ describe CensusCaller do end end - describe "RemoteCensusApi" 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 - + describe "RemoteCensusApi", :remote_census 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) allow_any_instance_of(RemoteCensusApi).to receive(:call).and_return(remote_census_api_response) diff --git a/spec/lib/remote_census_api_spec.rb b/spec/lib/remote_census_api_spec.rb index 85adafd7c..3e4a6b2a9 100644 --- a/spec/lib/remote_census_api_spec.rb +++ b/spec/lib/remote_census_api_spec.rb @@ -3,7 +3,7 @@ require "rails_helper" describe RemoteCensusApi do 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(:valid_body) do { @@ -19,14 +19,6 @@ describe RemoteCensusApi do } 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 date = Date.parse("01/01/1983") 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 - describe "RemoteCensusApi::Response" 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 - + describe "RemoteCensusApi::Response", :remote_census do it "return expected response methods with default values" do document_type = "1" document_number = "12345678Z" diff --git a/spec/models/officing/residence_spec.rb b/spec/models/officing/residence_spec.rb index 1925ac6f7..07304b69f 100644 --- a/spec/models/officing/residence_spec.rb +++ b/spec/models/officing/residence_spec.rb @@ -34,7 +34,7 @@ describe Officing::Residence do expect(residence).to be_valid end - describe "custom validations" do + describe "custom validations", :remote_census do let(:custom_residence) do build(:officing_residence, document_number: "12345678Z", @@ -42,17 +42,6 @@ describe Officing::Residence do postal_code: "28001") 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 expect(custom_residence).to be_valid end diff --git a/spec/models/signature_spec.rb b/spec/models/signature_spec.rb index c55136d47..7bfea9419 100644 --- a/spec/models/signature_spec.rb +++ b/spec/models/signature_spec.rb @@ -225,18 +225,7 @@ describe Signature do end describe "document in census throught CustomCensusApi" 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 "calls assign_vote_to_user" do + it "calls assign_vote_to_user", :remote_census do signature = create(:signature, document_number: "12345678Z", date_of_birth: "31/12/1980", postal_code: "28013") diff --git a/spec/models/verification/management/document_spec.rb b/spec/models/verification/management/document_spec.rb index 5e8752108..f01a915d4 100644 --- a/spec/models/verification/management/document_spec.rb +++ b/spec/models/verification/management/document_spec.rb @@ -28,18 +28,7 @@ describe Verification::Management::Document do expect(verification_document).to be_valid end - describe "custom validations with RemoteCensus enabled" 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 - + describe "custom validations with RemoteCensus enabled", :remote_census do it "is valid" do expect(verification_document).to be_valid end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 1996c2bb1..79358cf14 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -105,6 +105,38 @@ RSpec.configure do |config| allow(Time).to receive(:zone).and_return(application_zone) 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 # the `--only-failures` and `--next-failure` CLI options. config.example_status_persistence_file_path = "spec/examples.txt" diff --git a/spec/system/admin/signature_sheets_spec.rb b/spec/system/admin/signature_sheets_spec.rb index 57d57d350..e68dbdd8b 100644 --- a/spec/system/admin/signature_sheets_spec.rb +++ b/spec/system/admin/signature_sheets_spec.rb @@ -76,18 +76,7 @@ describe "Signature sheets" do end end - context "Create throught all required_fields_to_verify of custom census api" 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 - + context "Create throught all required_fields_to_verify of custom census api", :remote_census do scenario "Proposal" do proposal = create(:proposal) visit new_admin_signature_sheet_path diff --git a/spec/system/management/document_verifications_spec.rb b/spec/system/management/document_verifications_spec.rb index c27f5395d..62b364e2f 100644 --- a/spec/system/management/document_verifications_spec.rb +++ b/spec/system/management/document_verifications_spec.rb @@ -53,18 +53,7 @@ describe "DocumentVerifications" do end end - context "Remote Census API" 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 - + context "Remote Census API", :remote_census 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?). and_return(false) diff --git a/spec/system/officing/residence_spec.rb b/spec/system/officing/residence_spec.rb index aa63dcf21..0abbb6124 100644 --- a/spec/system/officing/residence_spec.rb +++ b/spec/system/officing/residence_spec.rb @@ -111,11 +111,8 @@ describe "Residence", :with_frozen_time do expect(page).to have_content "Vote introduced!" end - context "With remote census configuration" do + context "With remote census configuration", :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" create(:poll_officer_assignment, officer: officer) login_through_form_as_officer(officer.user) visit officing_root_path @@ -137,9 +134,6 @@ describe "Residence", :with_frozen_time do end 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 click_link "Validate document" end @@ -153,11 +147,6 @@ describe "Residence", :with_frozen_time do end 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 click_link "Validate document" end diff --git a/spec/system/verification/residence_spec.rb b/spec/system/verification/residence_spec.rb index a08ed5b23..7c60bebef 100644 --- a/spec/system/verification/residence_spec.rb +++ b/spec/system/verification/residence_spec.rb @@ -20,14 +20,7 @@ describe "Residence" do expect(page).to have_content "Residence verified" end - scenario "Verify resident throught RemoteCensusApi" 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 + scenario "Verify resident throught RemoteCensusApi", :remote_census do user = create(:user) login_as(user) @@ -42,7 +35,6 @@ describe "Residence" do click_button "Verify residence" expect(page).to have_content "Residence verified" - Setting["feature.remote_census"] = nil end scenario "Residence form use min age to participate" do