diff --git a/app/controllers/management/document_verifications_controller.rb b/app/controllers/management/document_verifications_controller.rb index cb7ff1d7e..5280e6d29 100644 --- a/app/controllers/management/document_verifications_controller.rb +++ b/app/controllers/management/document_verifications_controller.rb @@ -34,7 +34,8 @@ class Management::DocumentVerificationsController < Management::BaseController private def document_verification_params - params.require(:document_verification).permit(:document_type, :document_number) + params.require(:document_verification).permit(:document_type, :document_number, + :date_of_birth, :postal_code) end def set_document diff --git a/app/views/management/document_verifications/index.html.erb b/app/views/management/document_verifications/index.html.erb index 414b80667..c8946af22 100644 --- a/app/views/management/document_verifications/index.html.erb +++ b/app/views/management/document_verifications/index.html.erb @@ -18,6 +18,21 @@ label: t("management.document_number") %> + + <% if Setting.force_presence_date_of_birth? %> +
+ <%= f.date_select :date_of_birth, + prompt: true, + start_year: 1900, end_year: minimum_required_age.years.ago.year %> +
+ <% end %> + + <% if Setting.force_presence_postal_code? %> +
+ <%= f.text_field :postal_code, aria: {describedby: "postal-code-help-text"} %> +
+ <% end %> + <%= f.submit t("management.check"), class: "button" %> <% end %> diff --git a/spec/features/management/document_verifications_spec.rb b/spec/features/management/document_verifications_spec.rb index 3e1dcc67c..b845f819a 100644 --- a/spec/features/management/document_verifications_spec.rb +++ b/spec/features/management/document_verifications_spec.rb @@ -33,24 +33,79 @@ describe "DocumentVerifications" do expect(user.reload).to be_level_three_verified end - scenario "Verifying a user which does not exist and is not in the census shows an error" do + describe "Verifying througth Census" do - expect_any_instance_of(Verification::Management::Document).to receive(:in_census?).and_return(false) + context "Census API" do - visit management_document_verifications_path - fill_in "document_verification_document_number", with: "inexisting" - click_button "Check document" + scenario "Verifying a user which does not exist and is not in the census shows an error" do - expect(page).to have_content "This document is not registered" - end + expect_any_instance_of(Verification::Management::Document).to receive(:in_census?). + and_return(false) - scenario "Verifying a user which does exists in the census but not in the db redirects allows sending an email" do + visit management_document_verifications_path + fill_in "document_verification_document_number", with: "inexisting" + click_button "Check document" - visit management_document_verifications_path - fill_in "document_verification_document_number", with: "12345678Z" - click_button "Check document" + expect(page).to have_content "This document is not registered" + end + + scenario "Verifying a user which does exists in the census but not in the db redirects allows sending an email" do + + visit management_document_verifications_path + fill_in "document_verification_document_number", with: "12345678Z" + click_button "Check document" + + expect(page).to have_content "Please introduce the email used on the account" + 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 + + after do + Setting["feature.remote_census"] = nil + Setting["remote_census.request.date_of_birth"] = nil + Setting["remote_census.request.postal_code"] = nil + end + + 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) + + visit management_document_verifications_path + fill_in "document_verification_document_number", with: "12345678Z" + select_date "31-December-1980", from: "document_verification_date_of_birth" + fill_in "document_verification_postal_code", with: "inexisting" + click_button "Check document" + + expect(page).to have_content "This document is not registered" + end + + scenario "Verifying a user which does exists in the census but not in the db redirects allows sending an email" do + + visit management_document_verifications_path + fill_in "document_verification_document_number", with: "12345678Z" + select_date "31-December-1980", from: "document_verification_date_of_birth" + fill_in "document_verification_postal_code", with: "28013" + click_button "Check document" + + expect(page).to have_content "Please introduce the email used on the account" + end + + end - expect(page).to have_content "Please introduce the email used on the account" end scenario "Document number is format-standarized" do