Browse Source

CLDC-2222 Update access needs mapping and validations (#1501)

* Set housingneeds to yes if field 59 is 0

* Only display errors on selected housing needs

* Add errors to relevant fields when no housingneeds are selected with housingneeds options

* Add errors to correct fields when housingneeds don't know is selected

* Refactor validations

* Update 2023 housingneeds validations
pull/1504/head
kosiakkatrina 2 years ago committed by GitHub
parent
commit
0fc63711a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 24
      app/services/bulk_upload/lettings/year2022/row_parser.rb
  2. 24
      app/services/bulk_upload/lettings/year2023/row_parser.rb
  3. 98
      spec/services/bulk_upload/lettings/year2022/row_parser_spec.rb
  4. 98
      spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb

24
app/services/bulk_upload/lettings/year2022/row_parser.rb

@ -532,22 +532,26 @@ private
end end
def validate_dont_know_disabled_needs_conjunction def validate_dont_know_disabled_needs_conjunction
if field_60 == 1 && [field_55, field_56, field_57, field_58].compact.count.positive? if field_60 == 1 && [field_55, field_56, field_57, field_58].count(1).positive?
errors.add(:field_60, I18n.t("validations.household.housingneeds.dont_know_disabled_needs_conjunction")) %i[field_60 field_55 field_56 field_57 field_58].each do |field|
errors.add(field, I18n.t("validations.household.housingneeds.dont_know_disabled_needs_conjunction")) if send(field) == 1
end
end end
end end
def validate_no_disabled_needs_conjunction def validate_no_disabled_needs_conjunction
if field_59 == 1 && [field_55, field_56, field_57, field_58].compact.count.positive? if field_59 == 1 && [field_55, field_56, field_57, field_58].count(1).positive?
errors.add(:field_59, I18n.t("validations.household.housingneeds.no_disabled_needs_conjunction")) %i[field_59 field_55 field_56 field_57 field_58].each do |field|
errors.add(field, I18n.t("validations.household.housingneeds.no_disabled_needs_conjunction")) if send(field) == 1
end
end end
end end
def validate_only_one_housing_needs_type def validate_only_one_housing_needs_type
if [field_55, field_56, field_57].compact.count > 1 if [field_55, field_56, field_57].count(1) > 1
errors.add(:field_55, I18n.t("validations.household.housingneeds_type.only_one_option_permitted")) %i[field_55 field_56 field_57].each do |field|
errors.add(:field_56, I18n.t("validations.household.housingneeds_type.only_one_option_permitted")) errors.add(field, I18n.t("validations.household.housingneeds_type.only_one_option_permitted")) if send(field) == 1
errors.add(:field_57, I18n.t("validations.household.housingneeds_type.only_one_option_permitted")) end
end end
end end
@ -1240,8 +1244,8 @@ private
2 2
elsif field_60 == 1 elsif field_60 == 1
3 3
else elsif field_59&.zero?
2 1
end end
end end

24
app/services/bulk_upload/lettings/year2023/row_parser.rb

@ -431,22 +431,26 @@ private
end end
def validate_dont_know_disabled_needs_conjunction def validate_dont_know_disabled_needs_conjunction
if field_88 == 1 && [field_83, field_84, field_85, field_86].compact.count.positive? if field_88 == 1 && [field_83, field_84, field_85, field_86].count(1).positive?
errors.add(:field_88, I18n.t("validations.household.housingneeds.dont_know_disabled_needs_conjunction")) %i[field_88 field_83 field_84 field_85 field_86].each do |field|
errors.add(field, I18n.t("validations.household.housingneeds.dont_know_disabled_needs_conjunction")) if send(field) == 1
end
end end
end end
def validate_no_disabled_needs_conjunction def validate_no_disabled_needs_conjunction
if field_87 == 1 && [field_83, field_84, field_85, field_86].compact.count.positive? if field_87 == 1 && [field_83, field_84, field_85, field_86].count(1).positive?
errors.add(:field_87, I18n.t("validations.household.housingneeds.no_disabled_needs_conjunction")) %i[field_87 field_83 field_84 field_85 field_86].each do |field|
errors.add(field, I18n.t("validations.household.housingneeds.no_disabled_needs_conjunction")) if send(field) == 1
end
end end
end end
def validate_only_one_housing_needs_type def validate_only_one_housing_needs_type
if [field_83, field_84, field_85].compact.count > 1 if [field_83, field_84, field_85].count(1) > 1
errors.add(:field_83, I18n.t("validations.household.housingneeds_type.only_one_option_permitted")) %i[field_83 field_84 field_85].each do |field|
errors.add(:field_84, I18n.t("validations.household.housingneeds_type.only_one_option_permitted")) errors.add(field, I18n.t("validations.household.housingneeds_type.only_one_option_permitted")) if send(field) == 1
errors.add(:field_85, I18n.t("validations.household.housingneeds_type.only_one_option_permitted")) end
end end
end end
@ -1173,8 +1177,8 @@ private
2 2
elsif field_88 == 1 elsif field_88 == 1
3 3
else elsif field_87&.zero?
2 1
end end
end end

98
spec/services/bulk_upload/lettings/year2022/row_parser_spec.rb

@ -97,6 +97,12 @@ RSpec.describe BulkUpload::Lettings::Year2022::RowParser do
field_118: "2", field_118: "2",
field_55: "1",
field_56: "0",
field_57: "0",
field_58: "1",
field_59: "0",
field_66: "5", field_66: "5",
field_67: "2", field_67: "2",
field_52: "31", field_52: "31",
@ -501,7 +507,6 @@ RSpec.describe BulkUpload::Lettings::Year2022::RowParser do
it "is not permitted" do it "is not permitted" do
expect(parser.errors[:field_55]).to be_present expect(parser.errors[:field_55]).to be_present
expect(parser.errors[:field_56]).to be_present expect(parser.errors[:field_56]).to be_present
expect(parser.errors[:field_57]).to be_present
end end
end end
end end
@ -1414,6 +1419,97 @@ RSpec.describe BulkUpload::Lettings::Year2022::RowParser do
expect(parser.log.housingneeds).to eq(3) expect(parser.log.housingneeds).to eq(3)
end end
end end
context "when housingneeds are given" do
let(:attributes) { { bulk_upload:, field_59: "0", field_57: "1", field_58: "1" } }
it "sets correct housingneeds" do
expect(parser.log.housingneeds).to eq(1)
expect(parser.log.housingneeds_type).to eq(2)
expect(parser.log.housingneeds_other).to eq(1)
end
end
context "when housingneeds a and b are selected" do
let(:attributes) { { bulk_upload:, field_55: "1", field_56: "1" } }
it "sets error on housingneeds a and b" do
parser.valid?
expect(parser.errors[:field_55]).to include("Only one disabled access need: fully wheelchair-accessible housing, wheelchair access to essential rooms or level access housing, can be selected")
expect(parser.errors[:field_56]).to include("Only one disabled access need: fully wheelchair-accessible housing, wheelchair access to essential rooms or level access housing, can be selected")
expect(parser.errors[:field_57]).to be_blank
end
end
context "when housingneeds a and c are selected" do
let(:attributes) { { bulk_upload:, field_55: "1", field_57: "1" } }
it "sets error on housingneeds a and c" do
parser.valid?
expect(parser.errors[:field_55]).to include("Only one disabled access need: fully wheelchair-accessible housing, wheelchair access to essential rooms or level access housing, can be selected")
expect(parser.errors[:field_57]).to include("Only one disabled access need: fully wheelchair-accessible housing, wheelchair access to essential rooms or level access housing, can be selected")
expect(parser.errors[:field_56]).to be_blank
end
end
context "when housingneeds b and c are selected" do
let(:attributes) { { bulk_upload:, field_56: "1", field_57: "1" } }
it "sets error on housingneeds b and c" do
parser.valid?
expect(parser.errors[:field_56]).to include("Only one disabled access need: fully wheelchair-accessible housing, wheelchair access to essential rooms or level access housing, can be selected")
expect(parser.errors[:field_57]).to include("Only one disabled access need: fully wheelchair-accessible housing, wheelchair access to essential rooms or level access housing, can be selected")
expect(parser.errors[:field_55]).to be_blank
end
end
context "when housingneeds a and g are selected" do
let(:attributes) { { bulk_upload:, field_55: "1", field_59: "1" } }
it "sets error on housingneeds a and g" do
parser.valid?
expect(parser.errors[:field_59]).to include("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")
expect(parser.errors[:field_55]).to include("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")
expect(parser.errors[:field_56]).to be_blank
expect(parser.errors[:field_57]).to be_blank
end
end
context "when only housingneeds g is selected" do
let(:attributes) { { bulk_upload:, field_55: "0", field_59: "1" } }
it "does not add any housingneeds errors" do
parser.valid?
expect(parser.errors[:field_59]).to be_blank
expect(parser.errors[:field_55]).to be_blank
expect(parser.errors[:field_56]).to be_blank
expect(parser.errors[:field_57]).to be_blank
end
end
context "when housingneeds a and h are selected" do
let(:attributes) { { bulk_upload:, field_55: "1", field_60: "1" } }
it "sets error on housingneeds a and h" do
parser.valid?
expect(parser.errors[:field_60]).to include("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")
expect(parser.errors[:field_55]).to include("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")
expect(parser.errors[:field_56]).to be_blank
expect(parser.errors[:field_57]).to be_blank
end
end
context "when only housingneeds h is selected" do
let(:attributes) { { bulk_upload:, field_55: "0", field_60: "1" } }
it "does not add any housingneeds errors" do
parser.valid?
expect(parser.errors[:field_60]).to be_blank
expect(parser.errors[:field_55]).to be_blank
expect(parser.errors[:field_56]).to be_blank
expect(parser.errors[:field_57]).to be_blank
end
end
end end
describe "#housingneeds_type" do describe "#housingneeds_type" do

98
spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb

@ -165,6 +165,12 @@ RSpec.describe BulkUpload::Lettings::Year2023::RowParser do
field_82: "1", field_82: "1",
field_83: "1",
field_84: "0",
field_85: "0",
field_86: "1",
field_87: "0",
field_89: "2", field_89: "2",
field_100: "5", field_100: "5",
@ -517,7 +523,6 @@ RSpec.describe BulkUpload::Lettings::Year2023::RowParser do
it "is not permitted" do it "is not permitted" do
expect(parser.errors[:field_83]).to be_present expect(parser.errors[:field_83]).to be_present
expect(parser.errors[:field_84]).to be_present expect(parser.errors[:field_84]).to be_present
expect(parser.errors[:field_85]).to be_present
end end
end end
end end
@ -1452,6 +1457,97 @@ RSpec.describe BulkUpload::Lettings::Year2023::RowParser do
expect(parser.log.housingneeds).to eq(3) expect(parser.log.housingneeds).to eq(3)
end end
end end
context "when housingneeds are given" do
let(:attributes) { { bulk_upload:, field_87: "0", field_85: "1", field_86: "1" } }
it "sets correct housingneeds" do
expect(parser.log.housingneeds).to eq(1)
expect(parser.log.housingneeds_type).to eq(2)
expect(parser.log.housingneeds_other).to eq(1)
end
end
context "when housingneeds a and b are selected" do
let(:attributes) { { bulk_upload:, field_83: "1", field_84: "1" } }
it "sets error on housingneeds a and b" do
parser.valid?
expect(parser.errors[:field_83]).to include("Only one disabled access need: fully wheelchair-accessible housing, wheelchair access to essential rooms or level access housing, can be selected")
expect(parser.errors[:field_84]).to include("Only one disabled access need: fully wheelchair-accessible housing, wheelchair access to essential rooms or level access housing, can be selected")
expect(parser.errors[:field_85]).to be_blank
end
end
context "when housingneeds a and c are selected" do
let(:attributes) { { bulk_upload:, field_83: "1", field_85: "1" } }
it "sets error on housingneeds a and c" do
parser.valid?
expect(parser.errors[:field_83]).to include("Only one disabled access need: fully wheelchair-accessible housing, wheelchair access to essential rooms or level access housing, can be selected")
expect(parser.errors[:field_85]).to include("Only one disabled access need: fully wheelchair-accessible housing, wheelchair access to essential rooms or level access housing, can be selected")
expect(parser.errors[:field_84]).to be_blank
end
end
context "when housingneeds b and c are selected" do
let(:attributes) { { bulk_upload:, field_84: "1", field_85: "1" } }
it "sets error on housingneeds b and c" do
parser.valid?
expect(parser.errors[:field_84]).to include("Only one disabled access need: fully wheelchair-accessible housing, wheelchair access to essential rooms or level access housing, can be selected")
expect(parser.errors[:field_85]).to include("Only one disabled access need: fully wheelchair-accessible housing, wheelchair access to essential rooms or level access housing, can be selected")
expect(parser.errors[:field_83]).to be_blank
end
end
context "when housingneeds a and g are selected" do
let(:attributes) { { bulk_upload:, field_83: "1", field_87: "1" } }
it "sets error on housingneeds a and g" do
parser.valid?
expect(parser.errors[:field_87]).to include("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")
expect(parser.errors[:field_83]).to include("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")
expect(parser.errors[:field_84]).to be_blank
expect(parser.errors[:field_85]).to be_blank
end
end
context "when only housingneeds g is selected" do
let(:attributes) { { bulk_upload:, field_83: "0", field_87: "1" } }
it "does not add any housingneeds errors" do
parser.valid?
expect(parser.errors[:field_59]).to be_blank
expect(parser.errors[:field_83]).to be_blank
expect(parser.errors[:field_84]).to be_blank
expect(parser.errors[:field_85]).to be_blank
end
end
context "when housingneeds a and h are selected" do
let(:attributes) { { bulk_upload:, field_83: "1", field_88: "1" } }
it "sets error on housingneeds a and h" do
parser.valid?
expect(parser.errors[:field_88]).to include("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")
expect(parser.errors[:field_83]).to include("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")
expect(parser.errors[:field_84]).to be_blank
expect(parser.errors[:field_85]).to be_blank
end
end
context "when only housingneeds h is selected" do
let(:attributes) { { bulk_upload:, field_83: "0", field_88: "1" } }
it "does not add any housingneeds errors" do
parser.valid?
expect(parser.errors[:field_88]).to be_blank
expect(parser.errors[:field_83]).to be_blank
expect(parser.errors[:field_84]).to be_blank
expect(parser.errors[:field_85]).to be_blank
end
end
end end
describe "#housingneeds_type" do describe "#housingneeds_type" do

Loading…
Cancel
Save