diff --git a/app/models/case_log.rb b/app/models/case_log.rb index a98296bb2..52be17984 100644 --- a/app/models/case_log.rb +++ b/app/models/case_log.rb @@ -25,6 +25,7 @@ class CaseLog < ApplicationRecord before_validation :reset_scheme_location!, if: :scheme_changed?, unless: :location_changed? before_validation :process_postcode_changes!, if: :postcode_full_changed? before_validation :process_previous_postcode_changes!, if: :ppostcode_full_changed? + before_validation :set_housingneeds_fields, if: :housingneeds_present? before_validation :reset_invalidated_dependent_fields! before_validation :reset_location_fields!, unless: :postcode_known? before_validation :reset_previous_location_fields!, unless: :previous_postcode_known? @@ -693,29 +694,29 @@ private end end - def get_housingneeds - return 1 if has_housingneeds? - return 2 if no_housingneeds? - return 3 if unknown_housingneeds? - end + # def get_housingneeds + # return 1 if has_housingneeds? + # return 2 if no_housingneeds? + # return 3 if unknown_housingneeds? + # end - def has_housingneeds? - if [housingneeds_a, housingneeds_b, housingneeds_c, housingneeds_f].any?(1) - 1 - end - end + # def has_housingneeds? + # if [housingneeds_a, housingneeds_b, housingneeds_c, housingneeds_f].any?(1) + # 1 + # end + # end - def no_housingneeds? - if housingneeds_g == 1 - 1 - end - end + # def no_housingneeds? + # if housingneeds_g == 1 + # 1 + # end + # end - def unknown_housingneeds? - if housingneeds_h == 1 - 1 - end - end + # def unknown_housingneeds? + # if housingneeds_h == 1 + # 1 + # end + # end def all_fields_completed? subsection_statuses = form.subsections.map { |subsection| subsection.status(self) }.uniq @@ -754,4 +755,57 @@ private def upcase_and_remove_whitespace(string) string.present? ? string.upcase.gsub(/\s+/, "") : string end + + def housingneeds_present? + housingneeds.present? + end + + def fully_wheelchair_accessible? + housingneeds_type.present? && housingneeds_type.zero? + end + + def essential_wheelchair_access? + housingneeds_type == 1 + end + + def level_access_housing? + housingneeds_type == 2 + end + + def other_housingneeds? + housingneeds_other == 1 + end + + def has_housingneeds? + housingneeds == 1 + end + + def no_housingneeds? + housingneeds == 2 + end + + def unknown_housingneeds? + housingneeds == 3 + end + + def set_housingneeds_fields + set_housingneeds_values_to_nil + + self.housingneeds_a = 1 if fully_wheelchair_accessible? + self.housingneeds_b = 1 if essential_wheelchair_access? + self.housingneeds_c = 1 if level_access_housing? + self.housingneeds_f = 1 if other_housingneeds? + set_housingneeds_values_to_nil unless has_housingneeds? + self.housingneeds_g = 1 if no_housingneeds? + self.housingneeds_h = 1 if unknown_housingneeds? + end + + def set_housingneeds_values_to_nil + self.housingneeds_a = 0 + self.housingneeds_b = 0 + self.housingneeds_c = 0 + self.housingneeds_f = 0 + self.housingneeds_g = 0 + self.housingneeds_h = 0 + end end diff --git a/app/models/derived_variables/case_log_variables.rb b/app/models/derived_variables/case_log_variables.rb index 3bf227b6f..b98f62f2c 100644 --- a/app/models/derived_variables/case_log_variables.rb +++ b/app/models/derived_variables/case_log_variables.rb @@ -43,7 +43,7 @@ module DerivedVariables::CaseLogVariables self.has_benefits = get_has_benefits self.tshortfall_known = 0 if tshortfall self.nocharge = household_charge&.zero? ? 1 : 0 - self.housingneeds = get_housingneeds + # self.housingneeds = get_housingneeds if is_renewal? self.underoccupation_benefitcap = 2 if collection_start_year == 2021 self.homeless = 1 diff --git a/app/models/validations/household_validations.rb b/app/models/validations/household_validations.rb index 48b862ab3..7053d3571 100644 --- a/app/models/validations/household_validations.rb +++ b/app/models/validations/household_validations.rb @@ -54,16 +54,6 @@ module Validations::HouseholdValidations validate_person_age_matches_economic_status(record, 1) end - def validate_accessibility_requirements(record) - all_options = [record.housingneeds_a, record.housingneeds_b, record.housingneeds_c, record.housingneeds_f, record.housingneeds_g, record.housingneeds_h] - if all_options.count(1) > 1 - mobility_accessibility_options = [record.housingneeds_a, record.housingneeds_b, record.housingneeds_c] - unless all_options.count(1) == 2 && record.housingneeds_f == 1 && mobility_accessibility_options.any? { |x| x == 1 } - record.errors.add :accessibility_requirements, I18n.t("validations.household.housingneeds_a.one_or_two_choices") - end - end - end - def validate_condition_effects(record) all_options = [record.illness_type_1, record.illness_type_2, record.illness_type_3, record.illness_type_4, record.illness_type_5, record.illness_type_6, record.illness_type_7, record.illness_type_8, record.illness_type_9, record.illness_type_10] if all_options.count(1) >= 1 && household_no_illness?(record) diff --git a/app/services/imports/case_logs_import_service.rb b/app/services/imports/case_logs_import_service.rb index a0d75c0bb..ed387e945 100644 --- a/app/services/imports/case_logs_import_service.rb +++ b/app/services/imports/case_logs_import_service.rb @@ -107,6 +107,13 @@ module Imports %w[a b c f g h].each do |letter| attributes["housingneeds_#{letter}"] = housing_needs(xml_doc, letter) end + attributes["housingneeds"] = 1 if [attributes["housingneeds_a"], attributes["housingneeds_b"], attributes["housingneeds_c"], attributes["housingneeds_f"]].any? { |housingneed| housingneed == 1 } + attributes["housingneeds"] = 2 if attributes["housingneeds_g"] == 1 + attributes["housingneeds"] = 3 if attributes["housingneeds_h"] == 1 + attributes["housingneeds_type"] = 0 if attributes["housingneeds_a"] == 1 + attributes["housingneeds_type"] = 1 if attributes["housingneeds_b"] == 1 + attributes["housingneeds_type"] = 2 if attributes["housingneeds_c"] == 1 + attributes["housingneeds_other"] = attributes["housingneeds_f"] == 1 ? 1 : 0 attributes["illness"] = unsafe_string_as_integer(xml_doc, "Q10ia") (1..10).each do |index| @@ -275,7 +282,7 @@ module Imports end def fields_not_present_in_softwire_data - %w[majorrepairs illness_type_0 tshortfall_known pregnancy_value_check retirement_value_check rent_value_check net_income_value_check major_repairs_date_value_check void_date_value_check] + %w[majorrepairs illness_type_0 tshortfall_known pregnancy_value_check retirement_value_check rent_value_check net_income_value_check major_repairs_date_value_check void_date_value_check housingneeds_type housingneeds_other] end def check_status_completed(case_log, previous_status) diff --git a/config/forms/2021_2022.json b/config/forms/2021_2022.json index 433bcca61..82ed7bb95 100644 --- a/config/forms/2021_2022.json +++ b/config/forms/2021_2022.json @@ -5667,40 +5667,79 @@ } } }, - "access_needs": { + "access_needs_exist": { "header": "", "description": "", "questions": { - "accessibility_requirements": { + "housingneeds": { "header": "Does anybody in the household have any disabled access needs?", "hint_text": "", - "type": "checkbox", - "check_answer_label": "Anybody in household with disabled access needs", + "type": "radio", + "check_answer_label": "Anybody with disabled access needs", + "answer_options": { + "1": { + "value": "Yes" + }, + "2": { + "value": "No" + }, + "divider": { + "value": true + }, + "3": { + "value": "Don’t know" + } + } + } + } + }, + "type_of_access_needs": { + "header": "Disabled access needs", + "description": "", + "questions": { + "housingneeds_type": { + "header": "What type of access need do they have?", + "hint_text": "", + "type": "radio", + "check_answer_label": "Disabled access needs", "answer_options": { - "housingneeds_a": { + "0": { "value": "Fully wheelchair accessible housing" }, - "housingneeds_b": { + "1": { "value": "Wheelchair access to essential rooms" }, - "housingneeds_c": { + "2": { "value": "Level access housing" }, - "housingneeds_f": { - "value": "Other disabled access needs" - }, "divider": { "value": true }, - "housingneeds_g": { - "value": "No disabled access needs" + "3": { + "value": "None of the above" + } + } + }, + "housingneeds_type_other": { + "header": "Do they have any other access needs?", + "hint_text": "", + "type": "radio", + "check_answer_label": "Other disabled access needs", + "answer_options": { + "1": { + "value": "Yes" }, - "housingneeds_h": { - "value": "Don’t know" + "0": { + "value": "No" } } } - } + }, + "depends_on": [ + { + "housingneeds": 1 + } + ] }, "health_conditions": { "header": "", diff --git a/config/forms/2022_2023.json b/config/forms/2022_2023.json index 3a2c03c11..1bf41c984 100644 --- a/config/forms/2022_2023.json +++ b/config/forms/2022_2023.json @@ -5669,40 +5669,79 @@ } } }, - "access_needs": { + "access_needs_exist": { "header": "", "description": "", "questions": { - "accessibility_requirements": { + "housingneeds": { "header": "Does anybody in the household have any disabled access needs?", "hint_text": "", - "type": "checkbox", - "check_answer_label": "Anybody in household with disabled access needs", + "type": "radio", + "check_answer_label": "Anybody with disabled access needs", + "answer_options": { + "1": { + "value": "Yes" + }, + "2": { + "value": "No" + }, + "divider": { + "value": true + }, + "3": { + "value": "Don’t know" + } + } + } + } + }, + "type_of_access_needs": { + "header": "Disabled access needs", + "description": "", + "questions": { + "housingneeds_type": { + "header": "What type of access need do they have?", + "hint_text": "", + "type": "radio", + "check_answer_label": "Disabled access needs", "answer_options": { - "housingneeds_a": { + "0": { "value": "Fully wheelchair accessible housing" }, - "housingneeds_b": { + "1": { "value": "Wheelchair access to essential rooms" }, - "housingneeds_c": { + "2": { "value": "Level access housing" }, - "housingneeds_f": { - "value": "Other disabled access needs" - }, "divider": { "value": true }, - "housingneeds_g": { - "value": "No disabled access needs" + "3": { + "value": "None of the above" + } + } + }, + "housingneeds_other": { + "header": "Do they have any other access needs?", + "hint_text": "", + "type": "radio", + "check_answer_label": "Other disabled access needs", + "answer_options": { + "1": { + "value": "Yes" }, - "housingneeds_h": { - "value": "Don’t know" + "0": { + "value": "No" } } } - } + }, + "depends_on": [ + { + "housingneeds": 1 + } + ] }, "health_conditions": { "header": "", diff --git a/db/migrate/20220809100723_add_accessibility_requirements_fields.rb b/db/migrate/20220809100723_add_accessibility_requirements_fields.rb new file mode 100644 index 000000000..636a7e0ec --- /dev/null +++ b/db/migrate/20220809100723_add_accessibility_requirements_fields.rb @@ -0,0 +1,8 @@ +class AddAccessibilityRequirementsFields < ActiveRecord::Migration[7.0] + def change + change_table :case_logs, bulk: true do |t| + t.column :housingneeds_type, :integer + t.column :housingneeds_other, :integer + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 206fc69b0..ebb6822aa 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -202,6 +202,8 @@ ActiveRecord::Schema[7.0].define(version: 2022_08_10_152340) do t.bigint "location_id" t.integer "major_repairs_date_value_check" t.integer "void_date_value_check" + t.integer "housingneeds_type" + t.integer "housingneeds_other" t.index ["created_by_id"], name: "index_case_logs_on_created_by_id" t.index ["location_id"], name: "index_case_logs_on_location_id" t.index ["managing_organisation_id"], name: "index_case_logs_on_managing_organisation_id" diff --git a/spec/factories/case_log.rb b/spec/factories/case_log.rb index 46c151fd2..d557c4061 100644 --- a/spec/factories/case_log.rb +++ b/spec/factories/case_log.rb @@ -87,12 +87,9 @@ FactoryBot.define do chr { 1 } cap { 0 } reasonother { nil } - housingneeds_a { 1 } - housingneeds_b { 0 } - housingneeds_c { 0 } - housingneeds_f { 0 } - housingneeds_g { 0 } - housingneeds_h { 0 } + housingneeds { 1 } + housingneeds_type { 0 } + housingneeds_other { 0 } illness_type_1 { 0 } illness_type_2 { 1 } illness_type_3 { 0 } diff --git a/spec/features/form/checkboxes_spec.rb b/spec/features/form/checkboxes_spec.rb index cbf5e51c1..a62725b3b 100644 --- a/spec/features/form/checkboxes_spec.rb +++ b/spec/features/form/checkboxes_spec.rb @@ -41,24 +41,24 @@ RSpec.describe "Checkboxes" do context "when a checkbox question is submitted with invalid answers" do before do + case_log.update(illness: 100) allow(case_log).to receive(:update).and_return(false) end it "shows an error summary" do - visit("/logs/#{id}/accessibility-requirements") - page.check("case-log-accessibility-requirements-housingneeds-a-field") - page.check("case-log-accessibility-requirements-housingneeds-c-field") + visit("/logs/#{id}/condition-effects") + page.check("case-log-condition-effects-illness-type-1-field") + page.check("case-log-condition-effects-illness-type-2-field") click_button("Save and continue") expect(page).to have_title("Error") end it "persists the original selections" do - visit("/logs/#{id}/accessibility-requirements") - page.check("case-log-accessibility-requirements-housingneeds-a-field") - page.check("case-log-accessibility-requirements-housingneeds-c-field") + visit("/logs/#{id}/condition-effects") + page.check("case-log-condition-effects-illness-type-1-field") + page.check("case-log-condition-effects-illness-type-2-field") click_button("Save and continue") - expect(page).to have_checked_field("case-log-accessibility-requirements-housingneeds-a-field") - expect(page).to have_checked_field("case-log-accessibility-requirements-housingneeds-c-field") + expect(page).to have_checked_field("case-log-condition-effects-illness-type-2-field") end end end diff --git a/spec/fixtures/complete_case_log.json b/spec/fixtures/complete_case_log.json index 227da864b..826b0838f 100644 --- a/spec/fixtures/complete_case_log.json +++ b/spec/fixtures/complete_case_log.json @@ -56,12 +56,9 @@ "chr":0, "cap":0, "reasonother":"", - "housingneeds_a":0, - "housingneeds_b":0, - "housingneeds_c":1, - "housingneeds_f":0, - "housingneeds_g":0, - "housingneeds_h":0, + "housingneeds": 1, + "housingneeds_type": 2, + "housingneeds_other": 0, "illness_type_1":null, "illness_type_2":null, "illness_type_3":null, @@ -155,7 +152,6 @@ "wtcharge":"93.0", "wtshortfall":null, "refused":1, - "housingneeds":2, "wchchrg":null, "newprop":2, "relat2":"P", diff --git a/spec/fixtures/files/case_logs_download.csv b/spec/fixtures/files/case_logs_download.csv index 42aa605a2..483641117 100644 --- a/spec/fixtures/files/case_logs_download.csv +++ b/spec/fixtures/files/case_logs_download.csv @@ -1,2 +1,2 @@ -id,status,created_at,updated_at,created_by_name,is_dpo,owning_organisation_name,managing_organisation_name,needstype,renewal,startdate,rent_type,irproduct_other,tenancycode,propcode,age1,sex1,ecstat1,hhmemb,relat2,age2,sex2,retirement_value_check,ecstat2,armedforces,leftreg,illness,housingneeds_a,housingneeds_b,housingneeds_c,housingneeds_h,is_previous_la_inferred,prevloc,illness_type_1,illness_type_2,is_la_inferred,la,postcode_known,postcode_full,previous_la_known,wchair,preg_occ,cbl,earnings,incfreq,net_income_value_check,benefits,hb,period,brent,scharge,pscharge,supcharg,tcharge,offered,layear,ppostcode_full,mrcdate,declaration,ethnic,national,prevten,age3,sex3,ecstat3,age4,sex4,ecstat4,age5,sex5,ecstat5,age6,sex6,ecstat6,age7,sex7,ecstat7,age8,sex8,ecstat8,homeless,underoccupation_benefitcap,reservist,startertenancy,tenancylength,tenancy,rsnvac,unittype_gn,beds,waityear,reasonpref,chr,cap,reasonother,housingneeds_f,housingneeds_g,illness_type_3,illness_type_4,illness_type_8,illness_type_5,illness_type_6,illness_type_7,illness_type_9,illness_type_10,rp_homeless,rp_insan_unsat,rp_medwel,rp_hardship,rp_dontknow,tenancyother,property_owner_organisation,property_manager_organisation,sale_or_letting,purchaser_code,reason,majorrepairs,hbrentshortfall,property_relet,incref,sale_completion_date,first_time_property_let_as_social_housing,unitletas,builtype,voiddate,renttype,lettype,totchild,totelder,totadult,net_income_known,nocharge,is_carehome,household_charge,referral,tshortfall,chcharge,ppcodenk,age1_known,age2_known,age3_known,age4_known,age5_known,age6_known,age7_known,age8_known,ethnic_group,ethnic_other,letting_allocation_unknown,details_known_2,details_known_3,details_known_4,details_known_5,details_known_6,details_known_7,details_known_8,has_benefits,wrent,wscharge,wpschrge,wsupchrg,wtcharge,wtshortfall,refused,housingneeds,wchchrg,newprop,relat3,relat4,relat5,relat6,relat7,relat8,rent_value_check,old_form_id,lar,irproduct,old_id,joint,illness_type_0,tshortfall_known,sheltered,pregnancy_value_check,hhtype,new_old,vacdays,major_repairs_date_value_check,void_date_value_check,unittype_sh,scheme_id,location_id,scheme_code,scheme_service_name,scheme_sensitive,scheme_type,scheme_registered_under_care_act,scheme_owning_organisation_name,scheme_managing_organisation_name,scheme_primary_client_group,scheme_has_other_client_group,scheme_secondary_client_group,scheme_support_type,scheme_intended_stay,scheme_created_at,location_code,location_postcode,location_name,location_units,location_type_of_unit,location_mobility_type,location_admin_district,location_startdate -{id},in_progress,2022-02-08 16:52:15 +0000,2022-02-08 16:52:15 +0000,Danny Rojas,No,DLUHC,DLUHC,Supported housing,,,,,,,,,,,,,,,,,,,,,,,No,,,,No,Westminster,,SE1 1TE,,2,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,0,0,0,,0,,,,,,,,,,,,,,,,,,,,,,,,,0,,,,,,,0,,,,,,,,,,,,,,,,,,,,9,,,,,6,{scheme_id},SE1 1TE,{scheme_code},{scheme_service_name},{scheme_sensitive},Missing,No,DLUHC,DLUHC,{scheme_primary_client_group},,{scheme_secondary_client_group},{scheme_support_type},{scheme_intended_stay},2022-06-05 01:00:00 +0100,{location_code},SE1 1TE,Downing Street,20,Bungalow,Fitted with equipment and adaptations,Westminster,{location_startdate} +id,status,created_at,updated_at,created_by_name,is_dpo,owning_organisation_name,managing_organisation_name,needstype,renewal,startdate,rent_type,irproduct_other,tenancycode,propcode,age1,sex1,ecstat1,hhmemb,relat2,age2,sex2,retirement_value_check,ecstat2,armedforces,leftreg,illness,housingneeds_a,housingneeds_b,housingneeds_c,housingneeds_h,is_previous_la_inferred,prevloc,illness_type_1,illness_type_2,is_la_inferred,la,postcode_known,postcode_full,previous_la_known,wchair,preg_occ,cbl,earnings,incfreq,net_income_value_check,benefits,hb,period,brent,scharge,pscharge,supcharg,tcharge,offered,layear,ppostcode_full,mrcdate,declaration,ethnic,national,prevten,age3,sex3,ecstat3,age4,sex4,ecstat4,age5,sex5,ecstat5,age6,sex6,ecstat6,age7,sex7,ecstat7,age8,sex8,ecstat8,homeless,underoccupation_benefitcap,reservist,startertenancy,tenancylength,tenancy,rsnvac,unittype_gn,beds,waityear,reasonpref,chr,cap,reasonother,housingneeds_f,housingneeds_g,illness_type_3,illness_type_4,illness_type_8,illness_type_5,illness_type_6,illness_type_7,illness_type_9,illness_type_10,rp_homeless,rp_insan_unsat,rp_medwel,rp_hardship,rp_dontknow,tenancyother,property_owner_organisation,property_manager_organisation,sale_or_letting,purchaser_code,reason,majorrepairs,hbrentshortfall,property_relet,incref,sale_completion_date,first_time_property_let_as_social_housing,unitletas,builtype,voiddate,renttype,lettype,totchild,totelder,totadult,net_income_known,nocharge,is_carehome,household_charge,referral,tshortfall,chcharge,ppcodenk,age1_known,age2_known,age3_known,age4_known,age5_known,age6_known,age7_known,age8_known,ethnic_group,ethnic_other,letting_allocation_unknown,details_known_2,details_known_3,details_known_4,details_known_5,details_known_6,details_known_7,details_known_8,has_benefits,wrent,wscharge,wpschrge,wsupchrg,wtcharge,wtshortfall,refused,housingneeds,wchchrg,newprop,relat3,relat4,relat5,relat6,relat7,relat8,rent_value_check,old_form_id,lar,irproduct,old_id,joint,illness_type_0,tshortfall_known,sheltered,pregnancy_value_check,hhtype,new_old,vacdays,major_repairs_date_value_check,void_date_value_check,housingneeds_type,housingneeds_other,unittype_sh,scheme_id,location_id,scheme_code,scheme_service_name,scheme_sensitive,scheme_type,scheme_registered_under_care_act,scheme_owning_organisation_name,scheme_managing_organisation_name,scheme_primary_client_group,scheme_has_other_client_group,scheme_secondary_client_group,scheme_support_type,scheme_intended_stay,scheme_created_at,location_code,location_postcode,location_name,location_units,location_type_of_unit,location_mobility_type,location_admin_district,location_startdate +{id},in_progress,2022-02-08 16:52:15 +0000,2022-02-08 16:52:15 +0000,Danny Rojas,No,DLUHC,DLUHC,Supported housing,,,,,,,,,,,,,,,,,,,,,,,No,,,,No,Westminster,,SE1 1TE,,2,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,0,0,0,,0,,,,,,,,,,,,,,,,,,,,,,,,,0,,,,,,,0,,,,,,,,,,,,,,,,,,,,9,,,,,,,6,{scheme_id},SE1 1TE,{scheme_code},{scheme_service_name},{scheme_sensitive},Missing,No,DLUHC,DLUHC,{scheme_primary_client_group},,{scheme_secondary_client_group},{scheme_support_type},{scheme_intended_stay},2022-06-05 01:00:00 +0100,{location_code},SE1 1TE,Downing Street,20,Bungalow,Fitted with equipment and adaptations,Westminster,{location_startdate} diff --git a/spec/fixtures/files/case_logs_download_non_support.csv b/spec/fixtures/files/case_logs_download_non_support.csv index 209df7ecb..12aca6dcf 100644 --- a/spec/fixtures/files/case_logs_download_non_support.csv +++ b/spec/fixtures/files/case_logs_download_non_support.csv @@ -1,2 +1,2 @@ -id,status,created_at,updated_at,created_by_name,is_dpo,owning_organisation_name,managing_organisation_name,renewal,startdate,irproduct_other,tenancycode,propcode,age1,sex1,ecstat1,relat2,age2,sex2,ecstat2,armedforces,leftreg,illness,housingneeds_a,housingneeds_b,housingneeds_c,housingneeds_h,prevloc,illness_type_1,illness_type_2,la,postcode_full,wchair,preg_occ,cbl,earnings,incfreq,benefits,hb,period,brent,scharge,pscharge,supcharg,tcharge,offered,layear,ppostcode_full,mrcdate,declaration,ethnic,national,prevten,age3,sex3,ecstat3,age4,sex4,ecstat4,age5,sex5,ecstat5,age6,sex6,ecstat6,age7,sex7,ecstat7,age8,sex8,ecstat8,homeless,underoccupation_benefitcap,reservist,startertenancy,tenancylength,tenancy,rsnvac,unittype_gn,beds,waityear,reasonpref,chr,cap,reasonother,housingneeds_f,housingneeds_g,illness_type_3,illness_type_4,illness_type_8,illness_type_5,illness_type_6,illness_type_7,illness_type_9,illness_type_10,rp_homeless,rp_insan_unsat,rp_medwel,rp_hardship,rp_dontknow,tenancyother,property_owner_organisation,property_manager_organisation,purchaser_code,reason,majorrepairs,hbrentshortfall,property_relet,incref,sale_completion_date,unitletas,builtype,voiddate,lettype,nocharge,household_charge,referral,tshortfall,chcharge,ppcodenk,ethnic_group,ethnic_other,has_benefits,refused,housingneeds,wchchrg,newprop,relat3,relat4,relat5,relat6,relat7,relat8,lar,irproduct,joint,illness_type_0,sheltered,major_repairs_date_value_check,void_date_value_check,unittype_sh,scheme_code,scheme_service_name,scheme_sensitive,scheme_type,scheme_registered_under_care_act,scheme_owning_organisation_name,scheme_managing_organisation_name,scheme_primary_client_group,scheme_has_other_client_group,scheme_secondary_client_group,scheme_support_type,scheme_intended_stay,scheme_created_at,location_code,location_postcode,location_name,location_units,location_type_of_unit,location_mobility_type,location_admin_district,location_startdate -{id},in_progress,2022-02-08 16:52:15 +0000,2022-02-08 16:52:15 +0000,Danny Rojas,No,DLUHC,DLUHC,,,,,,,,,,,,,,,,,,,,,,,Westminster,SE1 1TE,2,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,0,,,,,,,,0,0,,,,,,,,,,,,,,,,,6,{scheme_code},{scheme_service_name},{scheme_sensitive},Missing,No,DLUHC,DLUHC,{scheme_primary_client_group},,{scheme_secondary_client_group},{scheme_support_type},{scheme_intended_stay},2022-06-05 01:00:00 +0100,{location_code},SE1 1TE,Downing Street,20,Bungalow,Fitted with equipment and adaptations,Westminster,{location_startdate} +id,status,created_at,updated_at,created_by_name,is_dpo,owning_organisation_name,managing_organisation_name,renewal,startdate,irproduct_other,tenancycode,propcode,age1,sex1,ecstat1,relat2,age2,sex2,ecstat2,armedforces,leftreg,illness,housingneeds_a,housingneeds_b,housingneeds_c,housingneeds_h,prevloc,illness_type_1,illness_type_2,la,postcode_full,wchair,preg_occ,cbl,earnings,incfreq,benefits,hb,period,brent,scharge,pscharge,supcharg,tcharge,offered,layear,ppostcode_full,mrcdate,declaration,ethnic,national,prevten,age3,sex3,ecstat3,age4,sex4,ecstat4,age5,sex5,ecstat5,age6,sex6,ecstat6,age7,sex7,ecstat7,age8,sex8,ecstat8,homeless,underoccupation_benefitcap,reservist,startertenancy,tenancylength,tenancy,rsnvac,unittype_gn,beds,waityear,reasonpref,chr,cap,reasonother,housingneeds_f,housingneeds_g,illness_type_3,illness_type_4,illness_type_8,illness_type_5,illness_type_6,illness_type_7,illness_type_9,illness_type_10,rp_homeless,rp_insan_unsat,rp_medwel,rp_hardship,rp_dontknow,tenancyother,property_owner_organisation,property_manager_organisation,purchaser_code,reason,majorrepairs,hbrentshortfall,property_relet,incref,sale_completion_date,unitletas,builtype,voiddate,lettype,nocharge,household_charge,referral,tshortfall,chcharge,ppcodenk,ethnic_group,ethnic_other,has_benefits,refused,housingneeds,wchchrg,newprop,relat3,relat4,relat5,relat6,relat7,relat8,lar,irproduct,joint,illness_type_0,sheltered,major_repairs_date_value_check,void_date_value_check,housingneeds_type,housingneeds_other,unittype_sh,scheme_code,scheme_service_name,scheme_sensitive,scheme_type,scheme_registered_under_care_act,scheme_owning_organisation_name,scheme_managing_organisation_name,scheme_primary_client_group,scheme_has_other_client_group,scheme_secondary_client_group,scheme_support_type,scheme_intended_stay,scheme_created_at,location_code,location_postcode,location_name,location_units,location_type_of_unit,location_mobility_type,location_admin_district,location_startdate +{id},in_progress,2022-02-08 16:52:15 +0000,2022-02-08 16:52:15 +0000,Danny Rojas,No,DLUHC,DLUHC,,,,,,,,,,,,,,,,,,,,,,,Westminster,SE1 1TE,2,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,0,,,,,,,,0,0,,,,,,,,,,,,,,,,,,,6,{scheme_code},{scheme_service_name},{scheme_sensitive},Missing,No,DLUHC,DLUHC,{scheme_primary_client_group},,{scheme_secondary_client_group},{scheme_support_type},{scheme_intended_stay},2022-06-05 01:00:00 +0100,{location_code},SE1 1TE,Downing Street,20,Bungalow,Fitted with equipment and adaptations,Westminster,{location_startdate} diff --git a/spec/fixtures/forms/2021_2022.json b/spec/fixtures/forms/2021_2022.json index ea8b3ce40..8d3508989 100644 --- a/spec/fixtures/forms/2021_2022.json +++ b/spec/fixtures/forms/2021_2022.json @@ -159,7 +159,6 @@ } }, "age2": { - "check_answers_card_number": 2, "check_answer_label": "Person 2’s age", "header": "Do you know person 2’s age?", "type": "numeric", @@ -169,7 +168,6 @@ "width": 2 }, "sex2": { - "check_answers_card_number": 2, "check_answer_label": "Person 2’s gender identity", "header": "Which of these best describes person 2’s gender identity?", "type": "radio", @@ -634,386 +632,366 @@ "label": true, "i18n_template": "ecstat1" }, - {"key": "earnings", + { + "key": "earnings", "label": true, "i18n_template": "earnings" - }] - }, - "questions": { - "net_income_value_check": { - "check_answer_label": "Net income soft validation", - "hidden_in_check_answers": true, - "header": "Are you sure this is correct?", - "type": "interruption_screen", - "answer_options": { - "0": { - "value": "Yes" - }, - "1": { - "value": "No" - } + } + ] + }, + "questions": { + "net_income_value_check": { + "check_answer_label": "Net income soft validation", + "hidden_in_check_answers": true, + "header": "Are you sure this is correct?", + "type": "interruption_screen", + "answer_options": { + "0": { + "value": "Yes" + }, + "1": { + "value": "No" } } } - }, - "net_income_uc_proportion": { - "questions": { - "benefits": { - "check_answer_label": "Benefits as a proportion of income", - "header": "How much of the tenant’s income is from Universal Credit, state pensions or benefits?", - "type": "radio", - "answer_options": { - "0": { - "value":"All" - }, - "1": { - "value":"Some" - } + } + }, + "net_income_uc_proportion": { + "questions": { + "benefits": { + "check_answer_label": "Benefits as a proportion of income", + "header": "How much of the tenant’s income is from Universal Credit, state pensions or benefits?", + "type": "radio", + "answer_options": { + "0": { + "value": "All" + }, + "1": { + "value": "Some" } } } - }, - "housing_benefit": { - "questions": { - "hb": { - "check_answer_label": "Housing-related benefits received", - "header": "Is the tenant likely to be in receipt of any of these housing-related benefits?", - "type": "radio", - "answer_options": { - "0": { - "value": "Housing benefit" - }, - "1": { - "value": "Tenant prefers not to say" - } + } + }, + "housing_benefit": { + "questions": { + "hb": { + "check_answer_label": "Housing-related benefits received", + "header": "Is the tenant likely to be in receipt of any of these housing-related benefits?", + "type": "radio", + "answer_options": { + "0": { + "value": "Housing benefit" }, - "conditional_for": { - "conditional_question": [0] + "1": { + "value": "Tenant prefers not to say" } }, - "conditional_question": { - "check_answer_label": "Conditional Question", - "header": "Question to test page conditions", - "type": "radio", - "answer_options": { - "0": { - "value": "Option A" - }, - "1": { - "value": "Option B" - } + "conditional_for": { + "conditional_question": [0] + } + }, + "conditional_question": { + "check_answer_label": "Conditional Question", + "header": "Question to test page conditions", + "type": "radio", + "answer_options": { + "0": { + "value": "Option A" + }, + "1": { + "value": "Option B" } } } - }, - "dependent_page": { - "depends_on": [{ "incfreq": 1 }], - "questions": { - "dependent_question": { - "check_answer_label": "Dependent Question", - "header": "Question to test page routing", - "type": "radio", - "answer_options": { - "0": { - "value": "Option A" - }, - "1": { - "value": "Option B" - } + } + }, + "dependent_page": { + "depends_on": [{ "incfreq": 1 }], + "questions": { + "dependent_question": { + "check_answer_label": "Dependent Question", + "header": "Question to test page routing", + "type": "radio", + "answer_options": { + "0": { + "value": "Option A" + }, + "1": { + "value": "Option B" } } } } } - }, - "rent_and_charges": { - "label": "Rent", - "pages": { - "rent": { - "questions": { - "period": { - "check_answer_label": "Rent Period", - "header": "Which period are rent and other charges due?", - "type": "radio", - "answer_options": { - "1": { - "value": "Weekly for 52 weeks" - }, - "3": { - "value": "Every 4 weeks" - } + } + }, + "rent_and_charges": { + "label": "Rent", + "pages": { + "rent": { + "questions": { + "period": { + "check_answer_label": "Rent Period", + "header": "Which period are rent and other charges due?", + "type": "radio", + "answer_options": { + "1": { + "value": "Weekly for 52 weeks" + }, + "3": { + "value": "Every 4 weeks" } - }, - "brent": { - "check_answer_label": "Basic Rent", - "header": "What is the basic rent?", - "hint_text": "Eligible for housing benefit or Universal Credit", - "type": "numeric", - "min": 0, - "step": 1, - "width": 4, - "fields-to-add": [ - "brent", - "scharge", - "pscharge", - "supcharg" - ], - "result-field": "tcharge" - }, - "scharge": { - "check_answer_label": "Service Charge", - "header": "What is the service charge?", - "hint_text": "Eligible for housing benefit or Universal Credit", - "type": "numeric", - "min": 0, - "step": 1, - "width": 4, - "fields-to-add": [ - "brent", - "scharge", - "pscharge", - "supcharg" - ], - "result-field": "tcharge" - }, - "pscharge": { - "check_answer_label": "Personal Service Charge", - "header": "What is the personal service charge?", - "hint_text": "Not eligible for housing benefit or Universal Credit. For example, hot water excluding water rates.", - "type": "numeric", - "min": 0, - "step": 1, - "width": 4, - "fields-to-add": [ - "brent", - "scharge", - "pscharge", - "supcharg" - ], - "result-field": "tcharge" - }, - "supcharg": { - "check_answer_label": "Support Charge", - "header": "What is the support charge?", - "hint_text": "This is to fund housing-related support services included in the tenancy agreement", - "type": "numeric", - "min": 0, - "max": 300, - "step": 1, - "width": 4, - "fields-to-add": [ - "brent", - "scharge", - "pscharge", - "supcharg" - ], - "result-field": "tcharge" - }, - "tcharge": { - "check_answer_label": "Total Charge", - "header": "Total charge?", - "hint_text": "This is the total of rent and all charges", - "type": "numeric_output", - "min": 0, - "step": 1, - "width": 4, - "readonly": true, - "requires_js": true } + }, + "brent": { + "check_answer_label": "Basic Rent", + "header": "What is the basic rent?", + "hint_text": "Eligible for housing benefit or Universal Credit", + "type": "numeric", + "min": 0, + "step": 1, + "width": 4, + "fields-to-add": ["brent", "scharge", "pscharge", "supcharg"], + "result-field": "tcharge" + }, + "scharge": { + "check_answer_label": "Service Charge", + "header": "What is the service charge?", + "hint_text": "Eligible for housing benefit or Universal Credit", + "type": "numeric", + "min": 0, + "step": 1, + "width": 4, + "fields-to-add": ["brent", "scharge", "pscharge", "supcharg"], + "result-field": "tcharge" + }, + "pscharge": { + "check_answer_label": "Personal Service Charge", + "header": "What is the personal service charge?", + "hint_text": "Not eligible for housing benefit or Universal Credit. For example, hot water excluding water rates.", + "type": "numeric", + "min": 0, + "step": 1, + "width": 4, + "fields-to-add": ["brent", "scharge", "pscharge", "supcharg"], + "result-field": "tcharge" + }, + "supcharg": { + "check_answer_label": "Support Charge", + "header": "What is the support charge?", + "hint_text": "This is to fund housing-related support services included in the tenancy agreement", + "type": "numeric", + "min": 0, + "max": 300, + "step": 1, + "width": 4, + "fields-to-add": ["brent", "scharge", "pscharge", "supcharg"], + "result-field": "tcharge" + }, + "tcharge": { + "check_answer_label": "Total Charge", + "header": "Total charge?", + "hint_text": "This is the total of rent and all charges", + "type": "numeric_output", + "min": 0, + "step": 1, + "width": 4, + "readonly": true, + "requires_js": true } - }, - "weekly_net_income": { - "header": "", - "description": "", - "questions": { - "earnings": { - "check_answer_label": "Total household income", - "header": "How much income does the household have in total every week?", - "hint_text": "", - "type": "numeric", - "min": 0, - "step": "1", - "width": 5, - "prefix": "£", - "suffix": " every week" - } + } + }, + "weekly_net_income": { + "header": "", + "description": "", + "questions": { + "earnings": { + "check_answer_label": "Total household income", + "header": "How much income does the household have in total every week?", + "hint_text": "", + "type": "numeric", + "min": 0, + "step": "1", + "width": 5, + "prefix": "£", + "suffix": " every week" + } + } + }, + "care_home_charge": { + "questions": { + "offered": { + "check_answer_label": "Basic Rent", + "header": "What is the basic rent?", + "hint_text": "Eligible for housing benefit or Universal Credit", + "type": "numeric", + "min": 0, + "step": 1, + "width": 4 } }, - "care_home_charge": { - "questions": { - "offered": { - "check_answer_label": "Basic Rent", - "header": "What is the basic rent?", - "hint_text": "Eligible for housing benefit or Universal Credit", - "type": "numeric", - "min": 0, - "step": 1, - "width": 4 - } - }, - "depends_on": [{"period": 3}] + "depends_on": [{ "period": 3 }] + }, + "care_home_charge_bi_weekly": { + "questions": { + "offered": { + "check_answer_label": "Basic Rent", + "header": "What is the basic rent?", + "hint_text": "Eligible for housing benefit or Universal Credit", + "type": "numeric", + "min": 0, + "step": 1, + "width": 4 + } }, - "care_home_charge_bi_weekly": { - "questions": { - "offered": { - "check_answer_label": "Basic Rent", - "header": "What is the basic rent?", - "hint_text": "Eligible for housing benefit or Universal Credit", - "type": "numeric", - "min": 0, - "step": 1, - "width": 4 - } - }, - "depends_on": [{"period": 2}] - } + "depends_on": [{ "period": 2 }] } } } - }, - "local_authority": { - "label": "Local authority", - "subsections": { - "local_authority": { - "label": "Local authority", - "pages": { - "time_lived_in_la": { - "questions": { - "layear": { - "check_answer_label": "How long has the household continuously lived in the local authority area where the new letting is located?", - "header": "How long has the household continuously lived in the local authority area where the new letting is located?", - "type": "radio", - "answer_options": { - "0": { - "value": "Just moved to local authority area" - }, - "1": { - "value": "Less than 1 year" - }, - "2": { - "value": "1 year but under 2 years" - }, - "3": { - "value": "2 years but under 3 years" - }, - "4": { - "value": "3 years but under 4 years" - }, - "5": { - "value": "4 years but under 5 years" - }, - "6": { - "value": "5 years or more" - }, - "divider": { - "value": true - }, - "7": { - "value": "Don’t know" - } + } + }, + "local_authority": { + "label": "Local authority", + "subsections": { + "local_authority": { + "label": "Local authority", + "pages": { + "time_lived_in_la": { + "questions": { + "layear": { + "check_answer_label": "How long has the household continuously lived in the local authority area where the new letting is located?", + "header": "How long has the household continuously lived in the local authority area where the new letting is located?", + "type": "radio", + "answer_options": { + "0": { + "value": "Just moved to local authority area" }, - "hidden_in_check_answers": { - "depends_on": [ - { "layear": 0 }, - { "layear": 1 } - ] + "1": { + "value": "Less than 1 year" + }, + "2": { + "value": "1 year but under 2 years" + }, + "3": { + "value": "2 years but under 3 years" + }, + "4": { + "value": "3 years but under 4 years" + }, + "5": { + "value": "4 years but under 5 years" + }, + "6": { + "value": "5 years or more" + }, + "divider": { + "value": true + }, + "7": { + "value": "Don’t know" } + }, + "hidden_in_check_answers": { + "depends_on": [{ "layear": 0 }, { "layear": 1 }] } - }, - "depends_on": [{ "renewal": 0 }] + } }, - "time_on_la_waiting_list": { - "questions": { - "lawaitlist": { - "check_answer_label": "How long has the household been on the local authority waiting list where the new letting is located?", - "header": "How long has the household been on the local authority waiting list where the new letting is located?", - "type": "radio", - "answer_options": { - "0": { - "value": "Just moved to local authority area" - }, - "1": { - "value": "Less than 1 year" - }, - "2": { - "value": "1 year but under 2 years" - }, - "3": { - "value": "2 years but under 3 years" - }, - "4": { - "value": "3 years but under 4 years" - }, - "5": { - "value": "4 years but under 5 years" - }, - "6": { - "value": "5 years or more" - }, - "divider": { - "value": true - }, - "7": { - "value": "Don’t know" - } + "depends_on": [{ "renewal": 0 }] + }, + "time_on_la_waiting_list": { + "questions": { + "lawaitlist": { + "check_answer_label": "How long has the household been on the local authority waiting list where the new letting is located?", + "header": "How long has the household been on the local authority waiting list where the new letting is located?", + "type": "radio", + "answer_options": { + "0": { + "value": "Just moved to local authority area" + }, + "1": { + "value": "Less than 1 year" + }, + "2": { + "value": "1 year but under 2 years" + }, + "3": { + "value": "2 years but under 3 years" + }, + "4": { + "value": "3 years but under 4 years" + }, + "5": { + "value": "4 years but under 5 years" + }, + "6": { + "value": "5 years or more" + }, + "divider": { + "value": true + }, + "7": { + "value": "Don’t know" } } } - }, - "other_postcode": { - "questions": { - "other_postcode": { - "check_answer_label": "Postcode of previous accommodation if the household has moved from settled accommodation", - "header": "Postcode for the previous accommodation", - "hint_text": "If the household has moved from settled accommodation immediately prior to being re-housed", - "type": "text", - "width": 5, - "conditional_for": { "fake_key": "fake_condition" } - }, - "ppostcode_full": { - "check_answer_label": "Postcode of previous accommodation if the household has moved from settled accommodation", - "header": "Postcode for the previous accommodation", - "hint_text": "If the household has moved from settled accommodation immediately prior to being re-housed", - "type": "text", - "width": 5 - } + } + }, + "other_postcode": { + "questions": { + "other_postcode": { + "check_answer_label": "Postcode of previous accommodation if the household has moved from settled accommodation", + "header": "Postcode for the previous accommodation", + "hint_text": "If the household has moved from settled accommodation immediately prior to being re-housed", + "type": "text", + "width": 5, + "conditional_for": { "fake_key": "fake_condition" } + }, + "ppostcode_full": { + "check_answer_label": "Postcode of previous accommodation if the household has moved from settled accommodation", + "header": "Postcode for the previous accommodation", + "hint_text": "If the household has moved from settled accommodation immediately prior to being re-housed", + "type": "text", + "width": 5 } - }, - "property_major_repairs": { - "questions": { - "mrcdate": { - "check_answer_label": "What was the major repairs completion date?", - "header": "What was the major repairs completion date?", - "hint_text": "For example, 27 3 2021", - "type": "date" - } + } + }, + "property_major_repairs": { + "questions": { + "mrcdate": { + "check_answer_label": "What was the major repairs completion date?", + "header": "What was the major repairs completion date?", + "hint_text": "For example, 27 3 2021", + "type": "date" } } } } } - }, - "submission": { - "label": "Submission", - "subsections": { - "declaration": { - "label": "Declaration", - "depends_on": [{ + } + }, + "submission": { + "label": "Submission", + "subsections": { + "declaration": { + "label": "Declaration", + "depends_on": [ + { "household_characteristics": "completed", "household_needs": "completed", "property_information": "completed" - }], - "pages": { - "declaration": { - "questions": { - "declaration": { - "check_answer_label": "", - "header": "Submit this lettings log ", - "type": "checkbox", - "answer_options": { - "declaration": { - "value": "The tenant has seen the Department for Levelling Up, Housing & Communities (DLUHC) privacy notice" - } + } + ], + "pages": { + "declaration": { + "questions": { + "declaration": { + "check_answer_label": "", + "header": "Submit this lettings log ", + "type": "checkbox", + "answer_options": { + "declaration": { + "value": "The tenant has seen the Department for Levelling Up, Housing & Communities (DLUHC) privacy notice" } } } @@ -1024,3 +1002,4 @@ } } } +} diff --git a/spec/models/case_log_spec.rb b/spec/models/case_log_spec.rb index eadf2d6b0..40525219e 100644 --- a/spec/models/case_log_spec.rb +++ b/spec/models/case_log_spec.rb @@ -139,10 +139,6 @@ RSpec.describe CaseLog do expect(validator).to receive(:validate_rsnvac) end - it "validates accessibility requirements" do - expect(validator).to receive(:validate_accessibility_requirements) - end - it "validates referral" do expect(validator).to receive(:validate_referral) end @@ -1440,34 +1436,6 @@ RSpec.describe CaseLog do end end - context "when the data provider is filling in household needs" do - let!(:case_log) do - described_class.create({ - managing_organisation: owning_organisation, - owning_organisation:, - created_by: created_by_user, - }) - end - - it "correctly derives and saves housing neeeds as 1" do - case_log.update!(housingneeds_a: 1) - record_from_db = ActiveRecord::Base.connection.execute("select housingneeds from case_logs where id=#{case_log.id}").to_a[0] - expect(record_from_db["housingneeds"]).to eq(1) - end - - it "correctly derives and saves housing neeeds as 2" do - case_log.update!(housingneeds_g: 1) - record_from_db = ActiveRecord::Base.connection.execute("select housingneeds from case_logs where id=#{case_log.id}").to_a[0] - expect(record_from_db["housingneeds"]).to eq(2) - end - - it "correctly derives and saves housing neeeds as 3" do - case_log.update!(housingneeds_h: 1) - record_from_db = ActiveRecord::Base.connection.execute("select housingneeds from case_logs where id=#{case_log.id}").to_a[0] - expect(record_from_db["housingneeds"]).to eq(3) - end - end - context "when it is supported housing and a care home charge has been supplied" do let!(:case_log) do described_class.create({ @@ -1753,6 +1721,99 @@ RSpec.describe CaseLog do end end end + + context "when saving accessibility needs" do + it "derives housingneeds_h as true if 'Don't know' is selected for housingneeds" do + case_log.update!({ housingneeds: 3 }) + record_from_db = ActiveRecord::Base.connection.execute("select housingneeds_a, housingneeds_b, housingneeds_c, housingneeds_f, housingneeds_g, housingneeds_h from case_logs where id=#{case_log.id}").to_a[0] + not_selected_housingneeds = %w[housingneeds_a housingneeds_b housingneeds_c housingneeds_f housingneeds_g] + not_selected_housingneeds.each do |housingneed| + expect(record_from_db[housingneed]).to eq(0) + expect(case_log[housingneed]).to eq(0) + end + expect(record_from_db["housingneeds_h"]).to eq(1) + expect(case_log["housingneeds_h"]).to eq(1) + end + + it "derives housingneeds_g as true if 'No' is selected for housingneeds" do + case_log.update!({ housingneeds: 2 }) + record_from_db = ActiveRecord::Base.connection.execute("select housingneeds_a, housingneeds_b, housingneeds_c, housingneeds_f, housingneeds_g, housingneeds_h from case_logs where id=#{case_log.id}").to_a[0] + not_selected_housingneeds = %w[housingneeds_a housingneeds_b housingneeds_c housingneeds_f housingneeds_h] + not_selected_housingneeds.each do |housingneed| + expect(record_from_db[housingneed]).to eq(0) + expect(case_log[housingneed]).to eq(0) + end + expect(record_from_db["housingneeds_g"]).to eq(1) + expect(case_log["housingneeds_g"]).to eq(1) + end + + it "derives housingneeds_a as true if 'Fully wheelchair accessible' is selected for housingneeds_type" do + case_log.update!({ housingneeds: 1, housingneeds_type: 0 }) + record_from_db = ActiveRecord::Base.connection.execute("select housingneeds_a, housingneeds_b, housingneeds_c, housingneeds_f, housingneeds_g, housingneeds_h from case_logs where id=#{case_log.id}").to_a[0] + not_selected_housingneeds = %w[housingneeds_b housingneeds_c housingneeds_f housingneeds_g housingneeds_h] + not_selected_housingneeds.each do |housingneed| + expect(record_from_db[housingneed]).to eq(0) + expect(case_log[housingneed]).to eq(0) + end + expect(record_from_db["housingneeds_a"]).to eq(1) + expect(case_log["housingneeds_a"]).to eq(1) + end + + it "derives housingneeds_b as true if 'Wheelchair access to essential rooms' is selected for housingneeds_type" do + case_log.update!({ housingneeds: 1, housingneeds_type: 1 }) + record_from_db = ActiveRecord::Base.connection.execute("select housingneeds_a, housingneeds_b, housingneeds_c, housingneeds_f, housingneeds_g, housingneeds_h from case_logs where id=#{case_log.id}").to_a[0] + not_selected_housingneeds = %w[housingneeds_a housingneeds_c housingneeds_f housingneeds_g housingneeds_h] + not_selected_housingneeds.each do |housingneed| + expect(record_from_db[housingneed]).to eq(0) + expect(case_log[housingneed]).to eq(0) + end + expect(record_from_db["housingneeds_b"]).to eq(1) + expect(case_log["housingneeds_b"]).to eq(1) + end + + it "derives housingneeds_c if 'Level access housing' is selected for housingneeds_type" do + case_log.update!({ housingneeds: 1, housingneeds_type: 2 }) + record_from_db = ActiveRecord::Base.connection.execute("select housingneeds_a, housingneeds_b, housingneeds_c, housingneeds_f, housingneeds_g, housingneeds_h from case_logs where id=#{case_log.id}").to_a[0] + not_selected_housingneeds = %w[housingneeds_a housingneeds_b housingneeds_f housingneeds_g housingneeds_h] + not_selected_housingneeds.each do |housingneed| + expect(record_from_db[housingneed]).to eq(0) + expect(case_log[housingneed]).to eq(0) + end + expect(record_from_db["housingneeds_c"]).to eq(1) + expect(case_log["housingneeds_c"]).to eq(1) + end + + it "derives housingneeds_f if 'Yes' is selected for housingneeds_other" do + case_log.update!({ housingneeds: 1, housingneeds_other: 1 }) + record_from_db = ActiveRecord::Base.connection.execute("select housingneeds_a, housingneeds_b, housingneeds_c, housingneeds_f, housingneeds_g, housingneeds_h from case_logs where id=#{case_log.id}").to_a[0] + not_selected_housingneeds = %w[housingneeds_a housingneeds_b housingneeds_c housingneeds_g housingneeds_h] + not_selected_housingneeds.each do |housingneed| + expect(record_from_db[housingneed]).to eq(0) + expect(case_log[housingneed]).to eq(0) + end + expect(record_from_db["housingneeds_f"]).to eq(1) + expect(case_log["housingneeds_f"]).to eq(1) + end + + it "clears previously set housingneeds if 'No' is selected for housingneeds" do + case_log.update!({ housingneeds: 1, housingneeds_type: 2, housingneeds_other: 1 }) + record_from_db = ActiveRecord::Base.connection.execute("select housingneeds_a, housingneeds_b, housingneeds_c, housingneeds_f, housingneeds_g, housingneeds_h from case_logs where id=#{case_log.id}").to_a[0] + expect(record_from_db["housingneeds_c"]).to eq(1) + expect(case_log["housingneeds_c"]).to eq(1) + expect(record_from_db["housingneeds_f"]).to eq(1) + expect(case_log["housingneeds_f"]).to eq(1) + + case_log.update!({ housingneeds: 2 }) + record_from_db = ActiveRecord::Base.connection.execute("select housingneeds_a, housingneeds_b, housingneeds_c, housingneeds_f, housingneeds_g, housingneeds_h from case_logs where id=#{case_log.id}").to_a[0] + not_selected_housingneeds = %w[housingneeds_a housingneeds_b housingneeds_c housingneeds_f housingneeds_h] + not_selected_housingneeds.each do |housingneed| + expect(record_from_db[housingneed]).to eq(0) + expect(case_log[housingneed]).to eq(0) + end + expect(record_from_db["housingneeds_g"]).to eq(1) + expect(case_log["housingneeds_g"]).to eq(1) + end + end end describe "optional fields" do diff --git a/spec/models/validations/household_validations_spec.rb b/spec/models/validations/household_validations_spec.rb index 5201adb6e..a844a612a 100644 --- a/spec/models/validations/household_validations_spec.rb +++ b/spec/models/validations/household_validations_spec.rb @@ -575,46 +575,6 @@ RSpec.describe Validations::HouseholdValidations do end end - describe "accessibility requirement validations" do - it "validates that mutually exclusive options can't be selected together" do - record.housingneeds_a = 1 - record.housingneeds_b = 1 - household_validator.validate_accessibility_requirements(record) - expect(record.errors["accessibility_requirements"]) - .to include(match I18n.t("validations.household.housingneeds_a.one_or_two_choices")) - record.housingneeds_a = 0 - record.housingneeds_b = 0 - record.housingneeds_g = 1 - record.housingneeds_f = 1 - household_validator.validate_accessibility_requirements(record) - expect(record.errors["accessibility_requirements"]) - .to include(match I18n.t("validations.household.housingneeds_a.one_or_two_choices")) - record.housingneeds_a = 1 - record.housingneeds_g = 1 - record.housingneeds_f = 1 - household_validator.validate_accessibility_requirements(record) - expect(record.errors["accessibility_requirements"]) - .to include(match I18n.t("validations.household.housingneeds_a.one_or_two_choices")) - end - - it "validates that non-mutually exclusive options can be selected together" do - record.housingneeds_a = 1 - record.housingneeds_f = 1 - household_validator.validate_accessibility_requirements(record) - expect(record.errors["accessibility_requirements"]).to be_empty - record.housingneeds_a = 0 - record.housingneeds_b = 1 - record.housingneeds_f = 1 - household_validator.validate_accessibility_requirements(record) - expect(record.errors["accessibility_requirements"]).to be_empty - record.housingneeds_b = 0 - record.housingneeds_c = 1 - record.housingneeds_f = 1 - household_validator.validate_accessibility_requirements(record) - expect(record.errors["accessibility_requirements"]).to be_empty - end - end - describe "referral validations" do context "when homelessness is assessed" do it "can be internal transfer" do