Browse Source

CLDC-1882 Bulk upload validate leaving reason if renewal (#1278)

* bulk upload validate leaving reason if renewal

* move validation string to locales
pull/1286/head
Phil Lee 2 years ago committed by GitHub
parent
commit
1bc63c9fab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      app/services/bulk_upload/lettings/row_parser.rb
  2. 1
      config/locales/en.yml
  3. 28
      spec/services/bulk_upload/lettings/row_parser_spec.rb

7
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

1
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:

28
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 } }

Loading…
Cancel
Save