From c4518311c20e119c4bed8ea3985bb93089df6600 Mon Sep 17 00:00:00 2001 From: Kat Date: Wed, 20 Dec 2023 16:56:46 +0000 Subject: [PATCH] Surface organisation and date errors in summary --- .../lettings/year2023/row_parser.rb | 6 ++++- .../bulk_upload/sales/year2023/row_parser.rb | 6 ++++- .../lettings/year2023/row_parser_spec.rb | 23 +++++++++++++++++++ .../sales/year2023/row_parser_spec.rb | 23 +++++++++++++++++++ 4 files changed, 56 insertions(+), 2 deletions(-) diff --git a/app/services/bulk_upload/lettings/year2023/row_parser.rb b/app/services/bulk_upload/lettings/year2023/row_parser.rb index 25b00302c..1d15abf65 100644 --- a/app/services/bulk_upload/lettings/year2023/row_parser.rb +++ b/app/services/bulk_upload/lettings/year2023/row_parser.rb @@ -436,7 +436,11 @@ class BulkUpload::Lettings::Year2023::RowParser fields.each do |field| unless errors.include?(field) - errors.add(field, error.message) + if error.attribute == :owning_organisation_id || error.attribute == :managing_organisation_id || error.attribute == :startdate + errors.add(field, error.message, category: :setup) + else + errors.add(field, error.message) + end end end end diff --git a/app/services/bulk_upload/sales/year2023/row_parser.rb b/app/services/bulk_upload/sales/year2023/row_parser.rb index 485a412ba..1c4e643f9 100644 --- a/app/services/bulk_upload/sales/year2023/row_parser.rb +++ b/app/services/bulk_upload/sales/year2023/row_parser.rb @@ -510,7 +510,11 @@ class BulkUpload::Sales::Year2023::RowParser fields.each do |field| unless errors.include?(field) - errors.add(field, error.message) + if error.attribute == :owning_organisation_id || error.attribute == :managing_organisation_id || error.attribute == :saledate + errors.add(field, error.message, category: :setup) + else + errors.add(field, error.message) + 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 af713d29b..871e8504e 100644 --- a/spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb +++ b/spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb @@ -1406,6 +1406,29 @@ RSpec.describe BulkUpload::Lettings::Year2023::RowParser do expect(parser.errors.where(:field_3)).not_to be_present end end + + context "when user's org has absorbed owning organisation before the startdate" do + let(:merged_org) { create(:organisation, :with_old_visible_id, holds_own_stock: true) } + + let(:attributes) { setup_section_params.merge({ field_1: merged_org.old_visible_id, field_2: merged_org.old_visible_id, field_3: user.email }) } + + before do + merged_org.update!(absorbing_organisation: user.organisation, merge_date: Time.zone.today - 5.years) + merged_org.reload + user.organisation.reload + end + + it "is not permitted" do + parser = described_class.new(attributes) + + parser.valid? + expect(parser.errors[:field_1]).to include(/The owning organisation must be active on the tenancy start date/) + expect(parser.errors[:field_2]).to include(/The managing organisation must be active on the tenancy start date/) + expect(parser.errors[:field_7]).to include(/Enter a date when the owning and managing organisation was active/) + expect(parser.errors[:field_8]).to include(/Enter a date when the owning and managing organisation was active/) + expect(parser.errors[:field_9]).to include(/Enter a date when the owning and managing organisation was active/) + end + end end describe "#field_2" do # managing org diff --git a/spec/services/bulk_upload/sales/year2023/row_parser_spec.rb b/spec/services/bulk_upload/sales/year2023/row_parser_spec.rb index 4853afb6f..263f0ddaa 100644 --- a/spec/services/bulk_upload/sales/year2023/row_parser_spec.rb +++ b/spec/services/bulk_upload/sales/year2023/row_parser_spec.rb @@ -457,6 +457,29 @@ RSpec.describe BulkUpload::Sales::Year2023::RowParser do expect(parser.errors.where(:field_2)).not_to be_present end end + + context "when user's org has absorbed owning organisation before the startdate" do + let(:merged_org) { create(:organisation, :with_old_visible_id, holds_own_stock: true) } + + let(:attributes) { setup_section_params.merge({ field_1: merged_org.old_visible_id, field_2: user.email }) } + + before do + merged_org.update!(absorbing_organisation: user.organisation, merge_date: Time.zone.today - 3.years) + merged_org.reload + user.organisation.reload + user.reload + end + + it "is not permitted" do + parser = described_class.new(attributes) + + parser.valid? + expect(parser.errors[:field_1]).to include(/The owning organisation must be active on the sale completion date/) + expect(parser.errors[:field_3]).to include(/Enter a date when the owning organisation was active/) + expect(parser.errors[:field_4]).to include(/Enter a date when the owning organisation was active/) + expect(parser.errors[:field_5]).to include(/Enter a date when the owning organisation was active/) + end + end end describe "#field_2" do # username for created_by