From 3f9cd65365b39a75579d1e354bb5dd9f03110605 Mon Sep 17 00:00:00 2001 From: kosiakkatrina <54268893+kosiakkatrina@users.noreply.github.com> Date: Thu, 24 Feb 2022 10:16:41 +0000 Subject: [PATCH] Household situation fixes (#332) * content changes and prevloc validation * add la validation to the property information section * Fix the tests --- app/models/validations/household_validations.rb | 6 ++++++ app/models/validations/property_validations.rb | 4 ++++ config/forms/2021_2022.json | 2 +- config/locales/en.yml | 2 ++ spec/features/form/accessible_autocomplete_spec.rb | 3 ++- spec/features/form/check_answers_page_spec.rb | 9 +++++---- spec/models/validations/household_validations_spec.rb | 11 +++++++++++ spec/models/validations/property_validations_spec.rb | 9 +++++++++ 8 files changed, 40 insertions(+), 6 deletions(-) diff --git a/app/models/validations/household_validations.rb b/app/models/validations/household_validations.rb index 58997fb9d..5fdeb8e40 100644 --- a/app/models/validations/household_validations.rb +++ b/app/models/validations/household_validations.rb @@ -90,6 +90,12 @@ module Validations::HouseholdValidations end end + def validate_prevloc(record) + if record.previous_la_known == "Yes" && record.prevloc.blank? + record.errors.add :prevloc, I18n.t("validations.household.previous_la_known") + end + end + private def women_of_child_bearing_age_in_household(record) diff --git a/app/models/validations/property_validations.rb b/app/models/validations/property_validations.rb index 107460dec..26b569f85 100644 --- a/app/models/validations/property_validations.rb +++ b/app/models/validations/property_validations.rb @@ -27,6 +27,10 @@ module Validations::PropertyValidations if record.la.present? && !LONDON_BOROUGHS.include?(record.la) && (record.rent_type == "London Affordable rent" || record.rent_type == "London living rent") record.errors.add :la, I18n.t("validations.property.la.london_rent") end + + if record.la_known == "Yes" && record.la.blank? + record.errors.add :la, I18n.t("validations.property.la.la_known") + end end FIRST_LET_VACANCY_REASONS = ["First let of new-build property", diff --git a/config/forms/2021_2022.json b/config/forms/2021_2022.json index cd1562545..ede49b9eb 100644 --- a/config/forms/2021_2022.json +++ b/config/forms/2021_2022.json @@ -2687,7 +2687,7 @@ "description": "", "questions": { "previous_postcode_known": { - "header": "Do you know the property’s postcode?", + "header": "Do you know the postcode of the household’s last settled accommodation?", "hint_text": "This is also known as the household’s ’last settled home’.", "type": "radio", "answer_options": { diff --git a/config/locales/en.yml b/config/locales/en.yml index f391010f6..71bebaf85 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -55,6 +55,7 @@ en: relet_number: "Property number of times relet must be between 0 and 20" la: london_rent: "Local authority has to be in London" + la_known: "Enter a local authority" rsnvac: first_let_not_social: "Reason for vacancy cannot be first let if unit has been previously let as social housing" first_let_social: "Reason for vacancy must be first let if unit has been previously let as social housing" @@ -126,6 +127,7 @@ en: internal_transfer: "Answer cannot be other homelessness as you already told us this tenancy was an internal transfer" reasonpref: not_homeless: "Can not be No if household was given reasonable preference" + previous_la_known: "Enter a local authority" tenancy: diff --git a/spec/features/form/accessible_autocomplete_spec.rb b/spec/features/form/accessible_autocomplete_spec.rb index 4f2f15c46..ed3047fbb 100644 --- a/spec/features/form/accessible_autocomplete_spec.rb +++ b/spec/features/form/accessible_autocomplete_spec.rb @@ -9,6 +9,7 @@ RSpec.describe "Accessible Automcomplete" do :case_log, :in_progress, la_known: "Yes", + la: "Westminster", is_la_inferred: false, owning_organisation: user.organisation, managing_organisation: user.organisation, @@ -39,7 +40,7 @@ RSpec.describe "Accessible Automcomplete" do end it "has the correct option selected if one has been saved" do - case_log.update!(postcode_known: "No", la: "Oxford") + case_log.update!(postcode_known: "No", la_known: "Yes", la: "Oxford") visit("/logs/#{case_log.id}/accessible-select") expect(page).to have_select("case-log-la-field", selected: %w[Oxford]) end diff --git a/spec/features/form/check_answers_page_spec.rb b/spec/features/form/check_answers_page_spec.rb index 1e2f3e97a..e185025c3 100644 --- a/spec/features/form/check_answers_page_spec.rb +++ b/spec/features/form/check_answers_page_spec.rb @@ -18,6 +18,7 @@ RSpec.describe "Form Check Answers Page" do FactoryBot.create( :case_log, la_known: "Yes", + la: "Westminster", is_la_inferred: false, owning_organisation: user.organisation, managing_organisation: user.organisation, @@ -86,14 +87,14 @@ RSpec.describe "Form Check Answers Page" do it "updates the change/answer link when answers get updated" do visit("/logs/#{empty_case_log.id}/household-needs/check-answers") - assert_selector "a", text: /Answer (?!the missing questions)/, count: 5 - assert_selector "a", text: "Change", count: 0 + assert_selector "a", text: /Answer (?!the missing questions)/, count: 4 + assert_selector "a", text: "Change", count: 1 visit("/logs/#{empty_case_log.id}/accessibility-requirements") check("case-log-accessibility-requirements-housingneeds-c-field") click_button("Save and continue") visit("/logs/#{empty_case_log.id}/household-needs/check-answers") - assert_selector "a", text: /Answer (?!the missing questions)/, count: 4 - assert_selector "a", text: "Change", count: 1 + assert_selector "a", text: /Answer (?!the missing questions)/, count: 3 + assert_selector "a", text: "Change", count: 2 expect(page).to have_link("Change", href: "/logs/#{empty_case_log.id}/accessibility-requirements") end diff --git a/spec/models/validations/household_validations_spec.rb b/spec/models/validations/household_validations_spec.rb index 423b9c412..50243321f 100644 --- a/spec/models/validations/household_validations_spec.rb +++ b/spec/models/validations/household_validations_spec.rb @@ -536,4 +536,15 @@ RSpec.describe Validations::HouseholdValidations do end end end + + describe "la validations" do + context "when previous la is known" do + it "prevloc has to be provided" do + record.previous_la_known = "Yes" + household_validator.validate_prevloc(record) + expect(record.errors["prevloc"]) + .to include(match I18n.t("validations.household.previous_la_known")) + end + end + end end diff --git a/spec/models/validations/property_validations_spec.rb b/spec/models/validations/property_validations_spec.rb index fb11039c9..bbf650059 100644 --- a/spec/models/validations/property_validations_spec.rb +++ b/spec/models/validations/property_validations_spec.rb @@ -157,6 +157,15 @@ RSpec.describe Validations::PropertyValidations do expect(record.errors["la"]).to be_empty end end + + context "when previous la is known" do + it "la has to be provided" do + record.la_known = "Yes" + property_validator.validate_la(record) + expect(record.errors["la"]) + .to include(match I18n.t("validations.property.la.la_known")) + end + end end describe "#validate_unitletas" do