From 9fb1201077f1096437e54855c53ee70dd9b0837f Mon Sep 17 00:00:00 2001 From: Phil Lee Date: Wed, 8 Feb 2023 13:00:56 +0000 Subject: [PATCH] bulk upload validate leaving reason if renewal --- .../bulk_upload/lettings/row_parser.rb | 9 ++++++ .../bulk_upload/lettings/row_parser_spec.rb | 29 +++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/app/services/bulk_upload/lettings/row_parser.rb b/app/services/bulk_upload/lettings/row_parser.rb index ab8280058..449074638 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,14 @@ private end end + def leaving_reason_for_renewal + if field_134 == 1 && ![40, 42].include?(field_52) + message = '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' + + errors.add(:field_52, message) + end + end + def validate_relevant_collection_window return unless start_date && bulk_upload.form diff --git a/spec/services/bulk_upload/lettings/row_parser_spec.rb b/spec/services/bulk_upload/lettings/row_parser_spec.rb index 85438f4b1..898df685d 100644 --- a/spec/services/bulk_upload/lettings/row_parser_spec.rb +++ b/spec/services/bulk_upload/lettings/row_parser_spec.rb @@ -250,6 +250,35 @@ 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 + parser.field_52 = "1" + 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 } }