Browse Source

CLDC-1225: At import updates relationship to child when a person is under 16 (#609)

pull/619/head
Stéphane Meny 3 years ago committed by baarkerlounger
parent
commit
46a2783a4a
  1. 15
      app/services/imports/case_logs_import_service.rb
  2. 44
      spec/services/imports/case_logs_import_service_spec.rb

15
app/services/imports/case_logs_import_service.rb

@ -138,8 +138,6 @@ module Imports
0 0
end end
apply_date_consistency!(attributes)
attributes["offered"] = safe_string_as_integer(xml_doc, "Q20") attributes["offered"] = safe_string_as_integer(xml_doc, "Q20")
attributes["propcode"] = string_or_nil(xml_doc, "Q21a") attributes["propcode"] = string_or_nil(xml_doc, "Q21a")
attributes["beds"] = safe_string_as_integer(xml_doc, "Q22") attributes["beds"] = safe_string_as_integer(xml_doc, "Q22")
@ -188,6 +186,9 @@ module Imports
attributes["created_by"] = User.find_by(old_user_id: owner_id) attributes["created_by"] = User.find_by(old_user_id: owner_id)
end end
apply_date_consistency!(attributes)
apply_household_consistency!(attributes)
case_log = CaseLog.new(attributes) case_log = CaseLog.new(attributes)
save_case_log(case_log, attributes) save_case_log(case_log, attributes)
compute_differences(case_log, attributes) compute_differences(case_log, attributes)
@ -524,5 +525,15 @@ module Imports
attributes.delete("voiddate") attributes.delete("voiddate")
end end
end end
def apply_household_consistency!(attributes)
(2..8).each do |index|
next if attributes["age#{index}"].nil?
if attributes["age#{index}"] < 16 && attributes["relat#{index}"] == "R"
attributes["relat#{index}"] = "C"
end
end
end
end end
end end

44
spec/services/imports/case_logs_import_service_spec.rb

@ -71,35 +71,55 @@ RSpec.describe Imports::CaseLogsImportService do
context "when importing a specific log" do context "when importing a specific log" do
let(:case_log_id) { "0ead17cb-1668-442d-898c-0d52879ff592" } let(:case_log_id) { "0ead17cb-1668-442d-898c-0d52879ff592" }
let(:case_log_file) { open_file(fixture_directory, case_log_id) } let(:case_log_file) { open_file(fixture_directory, case_log_id) }
let(:case_log_xml) { Nokogiri::XML(case_log_file) }
context "and the void date is after the start date" do context "and the void date is after the start date" do
let(:case_log_xml) do before { case_log_xml.at_xpath("//xmlns:VYEAR").content = 2023 }
xml_doc = Nokogiri::XML(case_log_file)
xml_doc.at_xpath("//xmlns:VYEAR").content = 2023
xml_doc
end
it "does not import the voiddate" do it "does not import the voiddate" do
allow(logger).to receive(:warn).with(/is not completed/) allow(logger).to receive(:warn).with(/is not completed/)
case_log_service.send(:create_log, case_log_xml) case_log_service.send(:create_log, case_log_xml)
case_log = CaseLog.where(old_id: case_log_id).first case_log = CaseLog.where(old_id: case_log_id).first
expect(case_log).not_to be_nil expect(case_log&.voiddate).to be_nil
expect(case_log.voiddate).to be_nil
end end
end end
context "and the organisation legacy ID does not exist" do context "and the organisation legacy ID does not exist" do
let(:case_log_xml) do before { case_log_xml.at_xpath("//xmlns:OWNINGORGID").content = 99_999 }
xml_doc = Nokogiri::XML(case_log_file)
xml_doc.at_xpath("//xmlns:OWNINGORGID").content = 99_999
xml_doc
end
it "raises an exception" do it "raises an exception" do
expect { case_log_service.send(:create_log, case_log_xml) } expect { case_log_service.send(:create_log, case_log_xml) }
.to raise_error(RuntimeError, "Organisation not found with legacy ID 99999") .to raise_error(RuntimeError, "Organisation not found with legacy ID 99999")
end end
end end
context "and a person is under 16" do
before { case_log_xml.at_xpath("//xmlns:P2Age").content = 14 }
context "when the economic status is set to refuse" do
before { case_log_xml.at_xpath("//xmlns:P2Eco").content = "10) Refused" }
it "sets the economic status to child under 16" do
# The update is done when calculating derived variables
allow(logger).to receive(:warn).with(/Differences found when saving log/)
case_log_service.send(:create_log, case_log_xml)
case_log = CaseLog.where(old_id: case_log_id).first
expect(case_log&.ecstat2).to be(9)
end
end
context "when the relationship to lead tenant is set to refuse" do
before { case_log_xml.at_xpath("//xmlns:P2Rel").content = "Refused" }
it "sets the relationship to lead tenant to child" do
case_log_service.send(:create_log, case_log_xml)
case_log = CaseLog.where(old_id: case_log_id).first
expect(case_log&.relat2).to eq("C")
end
end
end
end end
end end

Loading…
Cancel
Save