diff --git a/app/services/bulk_upload/lettings/row_parser.rb b/app/services/bulk_upload/lettings/row_parser.rb index ab8280058..cee5fa319 100644 --- a/app/services/bulk_upload/lettings/row_parser.rb +++ b/app/services/bulk_upload/lettings/row_parser.rb @@ -148,6 +148,7 @@ class BulkUpload::Lettings::RowParser validate :validate_relevant_collection_window validate :validate_la_with_local_housing_referral validate :validate_cannot_be_la_referral_if_general_needs + validate :leaving_reason_for_renewal def valid? errors.clear @@ -182,6 +183,12 @@ private end end + def leaving_reason_for_renewal + if field_134 == 1 && ![40, 42].include?(field_52) + errors.add(:field_52, I18n.t("validations.household.reason.renewal_reason_needed")) + end + end + def validate_relevant_collection_window return unless start_date && bulk_upload.form diff --git a/config/locales/en.yml b/config/locales/en.yml index f2e980cee..a97863c30 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -376,6 +376,7 @@ en: male_refuge: "Answer cannot be ‘male’ as you told us their housing situation immediately before this letting was a refuge" reason: not_internal_transfer: "Answer cannot be ‘permanently decanted from another property owned by this landlord’ as you told us the source of referral for this tenancy was not an internal transfer" + renewal_reason_needed: 'The reason for leaving must be "End of assured shorthold tenancy - no fault" or "End of fixed term tenancy - no fault" if the letting is a renewal' condition_effects: no_choices: "You cannot answer this question as you told us nobody in the household has a physical or mental health condition (or other illness) expected to last 12 months or more" postcode: diff --git a/spec/services/bulk_upload/lettings/row_parser_spec.rb b/spec/services/bulk_upload/lettings/row_parser_spec.rb index 85438f4b1..297b9fd46 100644 --- a/spec/services/bulk_upload/lettings/row_parser_spec.rb +++ b/spec/services/bulk_upload/lettings/row_parser_spec.rb @@ -250,6 +250,34 @@ RSpec.describe BulkUpload::Lettings::RowParser do end end + describe "#field_52" do # leaving reason + context "when field_134 is 1 meaning it is a renewal" do + context "when field_52 is 40" do + let(:attributes) { { bulk_upload:, field_52: "40", field_134: "1" } } + + it "is permitted" do + expect(parser.errors[:field_52]).to be_blank + end + end + + context "when field_52 is 42" do + let(:attributes) { { bulk_upload:, field_52: "42", field_134: "1" } } + + it "is permitted" do + expect(parser.errors[:field_52]).to be_blank + end + end + + context "when field_52 is not 40 or 42" do + let(:attributes) { { bulk_upload:, field_52: "1", field_134: "1" } } + + it "is not permitted" do + expect(parser.errors[:field_52]).to be_present + end + 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 } }