Add new fields to form

- Add :date_of_birth and :postal_code
- Only display new fields when aplication has configured the Remote
  Census API and contains values for fields. Check with Setting Class
  methods:
  - force_presence_date_of_birth?
  - force_presence_postal_code?
This commit is contained in:
taitus
2019-05-14 12:34:25 +02:00
committed by Javi Martín
parent bc36c5a987
commit ceaf118188
3 changed files with 84 additions and 13 deletions

View File

@@ -34,7 +34,8 @@ class Management::DocumentVerificationsController < Management::BaseController
private private
def document_verification_params 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 end
def set_document def set_document

View File

@@ -18,6 +18,21 @@
label: t("management.document_number") label: t("management.document_number")
%> %>
</div> </div>
<% if Setting.force_presence_date_of_birth? %>
<div class="date-of-birth small-12 medium-5">
<%= f.date_select :date_of_birth,
prompt: true,
start_year: 1900, end_year: minimum_required_age.years.ago.year %>
</div>
<% end %>
<% if Setting.force_presence_postal_code? %>
<div class="small-12 medium-5">
<%= f.text_field :postal_code, aria: {describedby: "postal-code-help-text"} %>
</div>
<% end %>
<%= f.submit t("management.check"), class: "button" %> <%= f.submit t("management.check"), class: "button" %>
<% end %> <% end %>
</div> </div>

View File

@@ -33,24 +33,79 @@ describe "DocumentVerifications" do
expect(user.reload).to be_level_three_verified expect(user.reload).to be_level_three_verified
end 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 scenario "Verifying a user which does not exist and is not in the census shows an error" do
fill_in "document_verification_document_number", with: "inexisting"
click_button "Check document"
expect(page).to have_content "This document is not registered" expect_any_instance_of(Verification::Management::Document).to receive(:in_census?).
end 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 expect(page).to have_content "This document is not registered"
fill_in "document_verification_document_number", with: "12345678Z" end
click_button "Check document"
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 end
scenario "Document number is format-standarized" do scenario "Document number is format-standarized" do