From 6a42978fabc51d9cfcc98c5a5757f6a94bd9df22 Mon Sep 17 00:00:00 2001 From: Rachael Booth Date: Fri, 2 Aug 2024 17:31:28 +0100 Subject: [PATCH] CLDC-3546: Add error to managing org when it does not have relevant rent period (#2538) * CLDC-3546: Add error to managing org when it does not have relevant rent period * Add test for :skip_bu_error * Fix managing org question id --- app/models/validations/financial_validations.rb | 7 ++++++- .../bulk_upload/lettings/year2024/row_parser.rb | 1 + config/locales/en.yml | 4 +++- .../models/validations/financial_validations_spec.rb | 8 +++++++- .../bulk_upload/lettings/year2024/row_parser_spec.rb | 12 ++++++++++++ 5 files changed, 29 insertions(+), 3 deletions(-) diff --git a/app/models/validations/financial_validations.rb b/app/models/validations/financial_validations.rb index 5e7d92d2c..53e50a92f 100644 --- a/app/models/validations/financial_validations.rb +++ b/app/models/validations/financial_validations.rb @@ -149,7 +149,12 @@ module Validations::FinancialValidations unless record.managing_organisation.rent_periods.include? record.period record.errors.add :period, :wrong_rent_period, message: I18n.t( - "validations.financial.rent_period.invalid_for_org", + "validations.financial.rent_period.invalid_for_org.period", + org_name: record.managing_organisation.name, + rent_period: record.form.get_question("period", record).label_from_value(record.period).downcase, + ) + record.errors.add :managing_organisation_id, :skip_bu_error, message: I18n.t( + "validations.financial.rent_period.invalid_for_org.managing_org", org_name: record.managing_organisation.name, rent_period: record.form.get_question("period", record).label_from_value(record.period).downcase, ) diff --git a/app/services/bulk_upload/lettings/year2024/row_parser.rb b/app/services/bulk_upload/lettings/year2024/row_parser.rb index b912c167b..2e54f5c3f 100644 --- a/app/services/bulk_upload/lettings/year2024/row_parser.rb +++ b/app/services/bulk_upload/lettings/year2024/row_parser.rb @@ -467,6 +467,7 @@ class BulkUpload::Lettings::Year2024::RowParser fields.each do |field| next if errors.include?(field) + next if error.type == :skip_bu_error question = log.form.get_question(error.attribute, log) diff --git a/config/locales/en.yml b/config/locales/en.yml index a70e7082b..b6ba761f2 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -436,7 +436,9 @@ en: under_10: "Enter a total charge that is at least £10.00 per week" less_than_shortfall: "The total charge must be more than the outstanding amount" rent_period: - invalid_for_org: "%{org_name} does not use %{rent_period} as a rent period. Choose another rent period, or a data coordinator can add rent periods to your organisation" + invalid_for_org: + period: "%{org_name} does not use %{rent_period} as a rent period. Choose another rent period, or a data coordinator can add rent periods to your organisation" + managing_org: "%{org_name} does not use %{rent_period} as a rent period. Set another rent period on this log, or a data coordinator can add rent periods to this organisation" carehome: out_of_range: "Household rent and other charges must be between %{min_chcharge} and %{max_chcharge} if paying %{period}" not_provided: "Enter how much rent and other charges the household pays %{period}" diff --git a/spec/models/validations/financial_validations_spec.rb b/spec/models/validations/financial_validations_spec.rb index c743381f7..a6eefa708 100644 --- a/spec/models/validations/financial_validations_spec.rb +++ b/spec/models/validations/financial_validations_spec.rb @@ -165,7 +165,13 @@ RSpec.describe Validations::FinancialValidations do financial_validator.validate_rent_period(record) expect(record.errors["period"]) .to include(match I18n.t( - "validations.financial.rent_period.invalid_for_org", + "validations.financial.rent_period.invalid_for_org.period", + org_name: user.organisation.name, + rent_period: "every 4 weeks", + )) + expect(record.errors["managing_organisation_id"]) + .to include(match I18n.t( + "validations.financial.rent_period.invalid_for_org.managing_org", org_name: user.organisation.name, rent_period: "every 4 weeks", )) diff --git a/spec/services/bulk_upload/lettings/year2024/row_parser_spec.rb b/spec/services/bulk_upload/lettings/year2024/row_parser_spec.rb index fbff000fd..7cae5eeae 100644 --- a/spec/services/bulk_upload/lettings/year2024/row_parser_spec.rb +++ b/spec/services/bulk_upload/lettings/year2024/row_parser_spec.rb @@ -750,6 +750,18 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do expect(parser.errors[:field_15]).to eq(["You must answer tenant has seen the privacy notice"]) end end + + context "when there is a :skip_bu_error error" do + let(:managing_org) { create(:organisation, :with_old_visible_id, rent_periods: [4, 1]) } + let(:attributes) { valid_attributes.merge({ field_123: 3, field_128: 80 }) } + + it "does not add that error" do + parser.valid? + + expect(parser.log.errors.map(&:attribute).sort).to eql(%i[managing_organisation_id period]) + expect(parser.errors.map(&:attribute)).to eql(%i[field_123]) + end + end end describe "#validate_nulls" do