Browse Source

Clear import fields failing non_temp_accommodation validation

pull/1463/head
Kat 3 years ago
parent
commit
ad4eb331c0
  1. 2
      app/models/validations/household_validations.rb
  2. 6
      app/services/imports/lettings_logs_import_service.rb
  3. 30
      spec/services/imports/lettings_logs_import_service_spec.rb

2
app/models/validations/household_validations.rb

@ -63,7 +63,7 @@ module Validations::HouseholdValidations
def validate_previous_housing_situation(record)
if record.is_relet_to_temp_tenant? && !record.previous_tenancy_was_temporary?
record.errors.add :prevten, I18n.t("validations.household.prevten.non_temp_accommodation")
record.errors.add :prevten, :non_temp_accommodation, message: I18n.t("validations.household.prevten.non_temp_accommodation")
end
if record.age1.present? && record.age1 > 19 && record.previous_tenancy_was_foster_care?

6
app/services/imports/lettings_logs_import_service.rb

@ -311,6 +311,12 @@ module Imports
attributes.delete("prevten")
attributes.delete("age1")
save_lettings_log(attributes, previous_status)
elsif lettings_log.errors.of_kind?(:prevten, :non_temp_accommodation)
@logger.warn("Log #{lettings_log.old_id}: Removing vacancy reason and previous tenancy since this accommodation is not temporary")
@logs_overridden << lettings_log.old_id
attributes.delete("prevten")
attributes.delete("rsnvac")
save_lettings_log(attributes, previous_status)
else
@logger.error("Log #{lettings_log.old_id}: Failed to import")
lettings_log.errors.each do |error|

30
spec/services/imports/lettings_logs_import_service_spec.rb

@ -366,6 +366,36 @@ RSpec.describe Imports::LettingsLogsImportService do
end
end
context "and this is a non temporary acommodation" do
before do
lettings_log_xml.at_xpath("//xmlns:Q27").content = "9"
lettings_log_xml.at_xpath("//xmlns:Q11").content = "4"
lettings_log_xml.at_xpath("//xmlns:VDAY").content = ""
lettings_log_xml.at_xpath("//xmlns:VMONTH").content = ""
lettings_log_xml.at_xpath("//xmlns:VYEAR").content = ""
lettings_log_xml.at_xpath("//xmlns:MRCDAY").content = ""
lettings_log_xml.at_xpath("//xmlns:MRCMONTH").content = ""
lettings_log_xml.at_xpath("//xmlns:MRCYEAR").content = ""
end
it "intercepts the relevant validation error" do
expect(logger).to receive(:warn).with(/Removing vacancy reason and previous tenancy since this accommodation is not temporary/)
expect { lettings_log_service.send(:create_log, lettings_log_xml) }
.not_to raise_error
end
it "clears out the referral answer" do
allow(logger).to receive(:warn)
lettings_log_service.send(:create_log, lettings_log_xml)
lettings_log = LettingsLog.find_by(old_id: lettings_log_id)
expect(lettings_log).not_to be_nil
expect(lettings_log.rsnvac).to be_nil
expect(lettings_log.prevten).to be_nil
end
end
context "and the net income soft validation is triggered (net_income_value_check)" do
before do
lettings_log_xml.at_xpath("//xmlns:Q8a").content = "1 Weekly"

Loading…
Cancel
Save