From 6e8acbc9275f0af9e5eeede2335b10c4f36a9f58 Mon Sep 17 00:00:00 2001 From: kosiakkatrina <54268893+kosiakkatrina@users.noreply.github.com> Date: Wed, 2 Aug 2023 08:07:37 +0100 Subject: [PATCH] Set housingneeds other to no if any of the housing needs are given (#1812) --- .../bulk_upload/lettings/year2022/row_parser.rb | 1 + .../bulk_upload/lettings/year2023/row_parser.rb | 1 + .../bulk_upload/lettings/year2022/row_parser_spec.rb | 10 ++++++++++ .../bulk_upload/lettings/year2023/row_parser_spec.rb | 10 ++++++++++ 4 files changed, 22 insertions(+) diff --git a/app/services/bulk_upload/lettings/year2022/row_parser.rb b/app/services/bulk_upload/lettings/year2022/row_parser.rb index 642c8efe8..9bef9312f 100644 --- a/app/services/bulk_upload/lettings/year2022/row_parser.rb +++ b/app/services/bulk_upload/lettings/year2022/row_parser.rb @@ -1466,6 +1466,7 @@ private def housingneeds_other return 1 if field_58 == 1 + return 0 if [field_55, field_56, field_57].include?(1) end def ethnic_group_from_ethnic diff --git a/app/services/bulk_upload/lettings/year2023/row_parser.rb b/app/services/bulk_upload/lettings/year2023/row_parser.rb index 4a12e9083..8d023792c 100644 --- a/app/services/bulk_upload/lettings/year2023/row_parser.rb +++ b/app/services/bulk_upload/lettings/year2023/row_parser.rb @@ -1410,6 +1410,7 @@ private def housingneeds_other return 1 if field_86 == 1 + return 0 if [field_83, field_84, field_85].include?(1) end def prevloc diff --git a/spec/services/bulk_upload/lettings/year2022/row_parser_spec.rb b/spec/services/bulk_upload/lettings/year2022/row_parser_spec.rb index b91caa969..6b5eaa2ae 100644 --- a/spec/services/bulk_upload/lettings/year2022/row_parser_spec.rb +++ b/spec/services/bulk_upload/lettings/year2022/row_parser_spec.rb @@ -1914,6 +1914,16 @@ RSpec.describe BulkUpload::Lettings::Year2022::RowParser do expect(parser.log.housingneeds_other).to eq(1) end end + + context "when field_58 is nil and one housingneeds option is selected" do + let(:attributes) { { bulk_upload:, field_58: nil, field_55: "1" } } + + it "sets to 0" do + expect(parser.errors[:field_58]).to be_blank + expect(parser.errors[:field_55]).to be_blank + expect(parser.log.housingneeds_other).to eq(0) + end + end end end diff --git a/spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb b/spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb index e12785738..cac166f46 100644 --- a/spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb +++ b/spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb @@ -754,6 +754,16 @@ RSpec.describe BulkUpload::Lettings::Year2023::RowParser do expect(parser.errors[:field_87]).to be_present end end + + context "when one item selected and field_86 is blank" do + let(:attributes) { setup_section_params.merge({ field_83: "1", field_86: nil }) } + + it "sets other disabled access needs as no" do + expect(parser.errors[:field_83]).to be_blank + expect(parser.errors[:field_86]).to be_blank + expect(parser.log.housingneeds_other).to eq(0) + end + end end describe "#field_89, field_98 - 99" do