Browse Source

CLDC-1285: Additional fixes for import (#640)

* Clears referral answer if combined with a fixed-term or lifetime previous tenancy at import
* Handles a different value for age refused during import
pull/644/head v0.1.18
Stéphane Meny 3 years ago committed by GitHub
parent
commit
9fee5c28b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      app/models/validations/household_validations.rb
  2. 7
      app/services/imports/case_logs_import_service.rb
  3. 23
      spec/services/imports/case_logs_import_service_spec.rb

4
app/models/validations/household_validations.rb

@ -111,8 +111,8 @@ module Validations::HouseholdValidations
def validate_referral(record) def validate_referral(record)
if record.is_internal_transfer? && record.owning_organisation.provider_type == "PRP" && record.is_prevten_la_general_needs? if record.is_internal_transfer? && record.owning_organisation.provider_type == "PRP" && record.is_prevten_la_general_needs?
record.errors.add :referral, I18n.t("validations.household.referral.la_general_needs.internal_transfer") record.errors.add :prevten, :internal_transfer_fixed_or_lifetime, message: I18n.t("validations.household.prevten.la_general_needs.internal_transfer")
record.errors.add :prevten, I18n.t("validations.household.prevten.la_general_needs.internal_transfer") record.errors.add :referral, :internal_transfer_fixed_or_lifetime, message: I18n.t("validations.household.referral.la_general_needs.internal_transfer")
end end
if record.owning_organisation.provider_type == "LA" && record.local_housing_referral? if record.owning_organisation.provider_type == "LA" && record.local_housing_referral?

7
app/services/imports/case_logs_import_service.rb

@ -226,6 +226,11 @@ module Imports
@logs_overridden << case_log.old_id @logs_overridden << case_log.old_id
attributes.delete("referral") attributes.delete("referral")
save_case_log(attributes) save_case_log(attributes)
elsif case_log.errors.of_kind?(:referral, :internal_transfer_fixed_or_lifetime)
@logger.warn("Log #{case_log.old_id}: Removing internal transfer referral since previous tenancy is fixed terms or lifetime")
@logs_overridden << case_log.old_id
attributes.delete("referral")
save_case_log(attributes)
else else
raise exception raise exception
end end
@ -378,7 +383,7 @@ module Imports
age_refused = string_or_nil(xml_doc, "P#{index}AR") age_refused = string_or_nil(xml_doc, "P#{index}AR")
if age_refused.present? if age_refused.present?
if age_refused.casecmp("AGE_REFUSED").zero? if age_refused.casecmp?("AGE_REFUSED") || age_refused.casecmp?("No")
return 1 # No return 1 # No
else else
return 0 # Yes return 0 # Yes

23
spec/services/imports/case_logs_import_service_spec.rb

@ -178,6 +178,29 @@ RSpec.describe Imports::CaseLogsImportService do
expect(case_log).not_to be_nil expect(case_log).not_to be_nil
expect(case_log.referral).to be_nil expect(case_log.referral).to be_nil
end end
context "and this is an internal transfer from a previous fixed term tenancy" do
before do
case_log_xml.at_xpath("//xmlns:Q11").content = "30 Fixed term Local Authority General Needs tenancy"
case_log_xml.at_xpath("//xmlns:Q16").content = "1 Internal Transfer"
end
it "intercepts the relevant validation error" do
expect(logger).to receive(:warn).with(/Removing internal transfer referral since previous tenancy is fixed terms or lifetime/)
expect { case_log_service.send(:create_log, case_log_xml) }
.not_to raise_error
end
it "clears out the referral answer" do
allow(logger).to receive(:warn)
case_log_service.send(:create_log, case_log_xml)
case_log = CaseLog.find_by(old_id: case_log_id)
expect(case_log).not_to be_nil
expect(case_log.referral).to be_nil
end
end
end end
end end
end end

Loading…
Cancel
Save