Browse Source

Clear joint tenancy if there is only 1 person in the household

pull/1463/head
Kat 3 years ago
parent
commit
264836c561
  1. 2
      app/models/validations/tenancy_validations.rb
  2. 5
      app/services/imports/lettings_logs_import_service.rb
  3. 1
      spec/fixtures/imports/logs/0ead17cb-1668-442d-898c-0d52879ff592.xml
  4. 36
      spec/services/imports/lettings_logs_import_service_spec.rb

2
app/models/validations/tenancy_validations.rb

@ -43,7 +43,7 @@ module Validations::TenancyValidations
return unless record.collection_start_year && record.joint
if record.hhmemb == 1 && record.joint != 2 && record.collection_start_year >= 2022
record.errors.add :joint, I18n.t("validations.tenancy.not_joint")
record.errors.add :joint, :not_joint_tenancy, message: I18n.t("validations.tenancy.not_joint")
record.errors.add :hhmemb, I18n.t("validations.tenancy.joint_more_than_one_member")
end
end

5
app/services/imports/lettings_logs_import_service.rb

@ -317,6 +317,11 @@ module Imports
attributes.delete("prevten")
attributes.delete("rsnvac")
save_lettings_log(attributes, previous_status)
elsif lettings_log.errors.of_kind?(:joint, :not_joint_tenancy)
@logger.warn("Log #{lettings_log.old_id}: Removing joint tenancy as there is only 1 person in the household")
@logs_overridden << lettings_log.old_id
attributes.delete("joint")
save_lettings_log(attributes, previous_status)
else
@logger.error("Log #{lettings_log.old_id}: Failed to import")
lettings_log.errors.each do |error|

1
spec/fixtures/imports/logs/0ead17cb-1668-442d-898c-0d52879ff592.xml vendored

@ -119,6 +119,7 @@
<Q10-g>Yes</Q10-g>
<Q10-h/>
<Q10ia>2 No</Q10ia>
<joint>2 No</joint>
<Q10ib-1/>
<Q10ib-2/>
<Q10ib-3/>

36
spec/services/imports/lettings_logs_import_service_spec.rb

@ -590,5 +590,41 @@ RSpec.describe Imports::LettingsLogsImportService do
.to change(OrganisationRelationship, :count).by(1)
end
end
context "when this is a joint tenancy with 1 person in the household" do
let(:lettings_log_id) { "0ead17cb-1668-442d-898c-0d52879ff592" }
let(:lettings_log_file) { open_file(fixture_directory, lettings_log_id) }
let(:lettings_log_xml) { Nokogiri::XML(lettings_log_file) }
before do
lettings_log_xml.at_xpath("//xmlns:joint").content = "1"
lettings_log_xml.at_xpath("//xmlns:HHMEMB").content = "1"
lettings_log_xml.at_xpath("//xmlns:P2Age").content = ""
lettings_log_xml.at_xpath("//xmlns:P2Rel").content = ""
lettings_log_xml.at_xpath("//xmlns:P2Sex").content = ""
lettings_log_xml.at_xpath("//xmlns:P1Nat").content = "18"
lettings_log_xml.at_xpath("//xmlns:P2Eco").content = ""
lettings_log_xml.at_xpath("//xmlns:DAY").content = "2"
lettings_log_xml.at_xpath("//xmlns:MONTH").content = "10"
lettings_log_xml.at_xpath("//xmlns:YEAR").content = "2022"
end
it "intercepts the relevant validation error" do
expect(logger).to receive(:warn).with(/Removing joint tenancy as there is only 1 person in the household/)
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.joint).to be_nil
expect(lettings_log.hhmemb).to eq(1)
end
end
end
end

Loading…
Cancel
Save