Browse Source

Map letting_allocation_value on import

pull/670/head v0.1.21
baarkerlounger 3 years ago
parent
commit
00c29f1322
  1. 4
      app/services/imports/case_logs_field_import_service.rb
  2. 12
      app/services/imports/case_logs_import_service.rb
  3. 4
      spec/fixtures/softwire_imports/case_logs/893ufj2s-lq77-42m4-rty6-ej09gh585uy1.xml
  4. 28
      spec/services/imports/case_logs_field_import_service_spec.rb

4
app/services/imports/case_logs_field_import_service.rb

@ -36,6 +36,10 @@ module Imports
record.update!(cap: 0)
@logger.info("Case Log #{record.id}'s cap value has been updated'")
end
if cbl == 2 && chr == 2 && cap == 2 && record.letting_allocation_unknown.nil?
record.update!(letting_allocation_unknown: 1)
@logger.info("Case Log #{record.id}'s letting_allocation_unknown value has been updated'")
end
else
@logger.warn("Could not find record matching legacy ID #{old_id}")
end

12
app/services/imports/case_logs_import_service.rb

@ -126,6 +126,7 @@ module Imports
attributes["cbl"] = allocation_system(unsafe_string_as_integer(xml_doc, "Q15CBL"))
attributes["chr"] = allocation_system(unsafe_string_as_integer(xml_doc, "Q15CHR"))
attributes["cap"] = allocation_system(unsafe_string_as_integer(xml_doc, "Q15CAP"))
attributes["letting_allocation_unknown"] = allocation_system_unknown(attributes["cbl"], attributes["chr"], attributes["cap"])
attributes["referral"] = unsafe_string_as_integer(xml_doc, "Q16")
attributes["period"] = unsafe_string_as_integer(xml_doc, "Q17")
@ -562,6 +563,17 @@ module Imports
end
end
def allocation_system_unknown(cbl, chr, cap)
allocation_values = [cbl, chr, cap]
if allocation_values.all? { |att| att.nil? }
nil
elsif allocation_values.all? { |att| att&.zero? }
1
else
0
end
end
def apply_date_consistency!(attributes)
return if attributes["voiddate"].nil? || attributes["startdate"].nil?

4
spec/fixtures/softwire_imports/case_logs/893ufj2s-lq77-42m4-rty6-ej09gh585uy1.xml vendored

@ -2,7 +2,7 @@
<meta:metadata xmlns:es="http://www.ecmascript.org/" xmlns:xqx="http://www.w3.org/2005/XQueryX" xmlns:XSLT="http://www.w3.org/1999/XSL/Transform/compile">
<meta:form-name>2021-CORE-IR-GN</meta:form-name>
<meta:document-id>893ufj2s-lq77-42m4-rty6-ej09gh585uy1</meta:document-id>
<meta:owner-user-id>e29c492473446dca4d50224f2bb7cf965a261d6f</meta:owner-user-id>
<meta:owner-user-id>c3061a2e6ea0b702e6f6210d5c52d2a92612d2aa</meta:owner-user-id>
<meta:owner-institution-id>7c5bd5fb549c09a2c55d7cb90d7ba84927e64618</meta:owner-institution-id>
<meta:managing-institution-id>7c5bd5fb549c09a2c55d7cb90d7ba84927e64618</meta:managing-institution-id>
<meta:created-date>2022-04-11T13:46:23.953121Z</meta:created-date>
@ -132,7 +132,7 @@
</Group>
<Group>
<Q15CBL>2 No</Q15CBL>
<Q15CHR>1 Yes</Q15CHR>
<Q15CHR>2 No</Q15CHR>
<Q15CAP>2 No</Q15CAP>
</Group>
<Group>

28
spec/services/imports/case_logs_field_import_service_spec.rb

@ -79,6 +79,7 @@ RSpec.describe Imports::CaseLogsFieldImportService do
let(:case_log) { CaseLog.find_by(old_id: case_log_id) }
before do
allow(logger).to receive(:warn)
Imports::CaseLogsImportService.new(storage_service, logger).create_logs(fixture_directory)
case_log_file.rewind
end
@ -163,6 +164,33 @@ RSpec.describe Imports::CaseLogsFieldImportService do
end
end
end
context "when allocation type is none of cap, chr, cbl" do
let(:case_log_id) { "893ufj2s-lq77-42m4-rty6-ej09gh585uy1" }
context "when it did not have a value set for letting_allocation_unknown" do
before do
case_log.update!(letting_allocation_unknown: nil)
end
it "updates the value" do
expect(logger).to receive(:info).with(/Case Log \d+'s letting_allocation_unknown value has been updated/)
expect { import_service.send(:update_field, field, remote_folder) }
.to(change { case_log.reload.letting_allocation_unknown }.from(nil).to(1))
end
end
context "when it had a value set for letting_allocation_unknown" do
before do
case_log.update!(letting_allocation_unknown: 1)
end
it "updates the value" do
expect { import_service.send(:update_field, field, remote_folder) }
.not_to(change { case_log.reload.letting_allocation_unknown })
end
end
end
end
context "when updating major repairs" do

Loading…
Cancel
Save