diff --git a/app/services/bulk_upload/lettings/row_parser.rb b/app/services/bulk_upload/lettings/row_parser.rb index 9d5604587..bf1f62eba 100644 --- a/app/services/bulk_upload/lettings/row_parser.rb +++ b/app/services/bulk_upload/lettings/row_parser.rb @@ -150,6 +150,10 @@ class BulkUpload::Lettings::RowParser validate :validate_cannot_be_la_referral_if_general_needs validate :validate_leaving_reason_for_renewal validate :validate_lettings_type_matches_bulk_upload + validate :validate_only_one_housing_needs_type + validate :validate_no_disabled_needs_conjunction + validate :validate_dont_know_disabled_needs_conjunction + validate :validate_no_and_dont_know_disabled_needs_conjunction def valid? errors.clear @@ -178,6 +182,33 @@ class BulkUpload::Lettings::RowParser private + def validate_no_and_dont_know_disabled_needs_conjunction + if field_59 == 1 && field_60 == 1 + errors.add(:field_59, I18n.t("validations.household.housingneeds.no_and_dont_know_disabled_needs_conjunction")) + errors.add(:field_60, I18n.t("validations.household.housingneeds.no_and_dont_know_disabled_needs_conjunction")) + end + end + + def validate_dont_know_disabled_needs_conjunction + if field_60 == 1 && [field_55, field_56, field_57, field_58].compact.count.positive? + errors.add(:field_60, I18n.t("validations.household.housingneeds.dont_know_disabled_needs_conjunction")) + end + end + + def validate_no_disabled_needs_conjunction + if field_59 == 1 && [field_55, field_56, field_57, field_58].compact.count.positive? + errors.add(:field_59, I18n.t("validations.household.housingneeds.no_disabled_needs_conjunction")) + end + end + + def validate_only_one_housing_needs_type + if [field_55, field_56, field_57].compact.count.positive? + errors.add(:field_55, I18n.t("validations.household.housingneeds_type.only_one_option_permitted")) + errors.add(:field_56, I18n.t("validations.household.housingneeds_type.only_one_option_permitted")) + errors.add(:field_57, I18n.t("validations.household.housingneeds_type.only_one_option_permitted")) + end + end + def validate_lettings_type_matches_bulk_upload if [1, 3, 5, 7, 9, 11].include?(field_1) && !bulk_upload.general_needs? errors.add(:field_1, I18n.t("validations.setup.lettype.supported_housing_mismatch")) @@ -552,6 +583,8 @@ private attributes["preg_occ"] = field_47 attributes["housingneeds"] = housingneeds + attributes["housingneeds_type"] = housingneeds_type + attributes["housingneeds_other"] = housingneeds_other attributes["illness"] = field_118 @@ -808,7 +841,7 @@ private def housingneeds if field_59 == 1 - 1 + 2 elsif field_60 == 1 3 else @@ -816,6 +849,20 @@ private end end + def housingneeds_type + if field_55 == 1 + 0 + elsif field_56 == 1 + 1 + elsif field_57 == 1 + 2 + end + end + + def housingneeds_other + return 1 if field_58 == 1 + end + def ethnic_group_from_ethnic return nil if field_43.blank? diff --git a/config/locales/en.yml b/config/locales/en.yml index 98e40dfb3..23d39bbe8 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -347,6 +347,12 @@ en: must_be_child: "Answer must be ‘child’ if the person is aged 16-19 and a student" housingneeds_a: one_or_two_choices: "You can only select one option or ‘other disabled access needs’ plus ‘wheelchair-accessible housing’, ‘wheelchair access to essential rooms’ or ‘level access housing’" + housingneeds_type: + only_one_option_permitted: "Only one disabled access need: fully wheelchair-accessible housing, wheelchair access to essential rooms or level access housing, can be selected" + housingneeds: + no_disabled_needs_conjunction: "No disabled access needs can’t be selected if you have selected fully wheelchair-accessible housing, wheelchair access to essential rooms, level access housing or other disabled access needs" + dont_know_disabled_needs_conjunction: "Don’t know disabled access needs can’t be selected if you have selected fully wheelchair-accessible housing, wheelchair access to essential rooms, level access housing or other disabled access needs" + no_and_dont_know_disabled_needs_conjunction: "No disabled access needs and don’t know disabled access needs cannot be selected together" prevten: non_temp_accommodation: "Answer cannot be non-temporary accommodation as this is a re-let to a tenant who occupied the same property as temporary accommodation" over_20_foster_care: "Answer cannot be a children’s home or foster care as the lead tenant is 20 or older" diff --git a/spec/services/bulk_upload/lettings/row_parser_spec.rb b/spec/services/bulk_upload/lettings/row_parser_spec.rb index 8f609838c..1bebd6444 100644 --- a/spec/services/bulk_upload/lettings/row_parser_spec.rb +++ b/spec/services/bulk_upload/lettings/row_parser_spec.rb @@ -344,6 +344,49 @@ RSpec.describe BulkUpload::Lettings::RowParser do end end + describe "#field_55, #field_56, #field_57" do + context "when more than one item selected" do + let(:attributes) { { bulk_upload:, field_55: "1", field_56: "1" } } + + it "is not permitted" do + expect(parser.errors[:field_55]).to be_present + expect(parser.errors[:field_56]).to be_present + expect(parser.errors[:field_57]).to be_present + end + end + end + + describe "#field_59" do + context "when 1 and another disability field selected" do + let(:attributes) { { bulk_upload:, field_59: "1", field_58: "1" } } + + it "is not permitted" do + expect(parser.errors[:field_59]).to be_present + end + end + end + + describe "#field_60" do + context "when 1 and another disability field selected" do + let(:attributes) { { bulk_upload:, field_60: "1", field_58: "1" } } + + it "is not permitted" do + expect(parser.errors[:field_60]).to be_present + end + end + end + + describe "#field_59, #field_60" do + context "when both 1" do + let(:attributes) { { bulk_upload:, field_59: "1", field_60: "1" } } + + it "is not permitted" do + expect(parser.errors[:field_59]).to be_present + expect(parser.errors[:field_60]).to be_present + end + end + end + describe "#field_78" do # referral context "when 3 ie PRP nominated by LA and owning org is LA" do let(:attributes) { { bulk_upload:, field_78: "3", field_111: owning_org.old_visible_id } } @@ -894,6 +937,60 @@ RSpec.describe BulkUpload::Lettings::RowParser do end end end + + describe "#housingneeds" do + context "when no disabled needs" do + let(:attributes) { { bulk_upload:, field_59: "1" } } + + it "sets to 2" do + expect(parser.log.housingneeds).to eq(2) + end + end + + context "when dont know about disabled needs" do + let(:attributes) { { bulk_upload:, field_60: "1" } } + + it "sets to 3" do + expect(parser.log.housingneeds).to eq(3) + end + end + end + + describe "#housingneeds_type" do + context "when field_55 is 1" do + let(:attributes) { { bulk_upload:, field_55: "1" } } + + it "set to 0" do + expect(parser.log.housingneeds_type).to eq(0) + end + end + + context "when field_56 is 1" do + let(:attributes) { { bulk_upload:, field_56: "1" } } + + it "set to 1" do + expect(parser.log.housingneeds_type).to eq(1) + end + end + + context "when field_57 is 1" do + let(:attributes) { { bulk_upload:, field_57: "1" } } + + it "set to 2" do + expect(parser.log.housingneeds_type).to eq(2) + end + end + end + + describe "#housingneeds_other" do + context "when field_58 is 1" do + let(:attributes) { { bulk_upload:, field_58: "1" } } + + it "sets to 1" do + expect(parser.log.housingneeds_other).to eq(1) + end + end + end end describe "#start_date" do