From 00c29f1322a72fd0185910a595a265aca976e279 Mon Sep 17 00:00:00 2001 From: baarkerlounger Date: Wed, 15 Jun 2022 17:28:17 +0100 Subject: [PATCH] Map letting_allocation_value on import --- .../imports/case_logs_field_import_service.rb | 4 +++ .../imports/case_logs_import_service.rb | 12 ++++++++ .../893ufj2s-lq77-42m4-rty6-ej09gh585uy1.xml | 4 +-- .../case_logs_field_import_service_spec.rb | 28 +++++++++++++++++++ 4 files changed, 46 insertions(+), 2 deletions(-) diff --git a/app/services/imports/case_logs_field_import_service.rb b/app/services/imports/case_logs_field_import_service.rb index 30871af56..97d8afbf8 100644 --- a/app/services/imports/case_logs_field_import_service.rb +++ b/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 diff --git a/app/services/imports/case_logs_import_service.rb b/app/services/imports/case_logs_import_service.rb index 7af00b12c..528058238 100644 --- a/app/services/imports/case_logs_import_service.rb +++ b/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? diff --git a/spec/fixtures/softwire_imports/case_logs/893ufj2s-lq77-42m4-rty6-ej09gh585uy1.xml b/spec/fixtures/softwire_imports/case_logs/893ufj2s-lq77-42m4-rty6-ej09gh585uy1.xml index 3f14dbf1f..654ade4cd 100644 --- a/spec/fixtures/softwire_imports/case_logs/893ufj2s-lq77-42m4-rty6-ej09gh585uy1.xml +++ b/spec/fixtures/softwire_imports/case_logs/893ufj2s-lq77-42m4-rty6-ej09gh585uy1.xml @@ -2,7 +2,7 @@ 2021-CORE-IR-GN 893ufj2s-lq77-42m4-rty6-ej09gh585uy1 - e29c492473446dca4d50224f2bb7cf965a261d6f + c3061a2e6ea0b702e6f6210d5c52d2a92612d2aa 7c5bd5fb549c09a2c55d7cb90d7ba84927e64618 7c5bd5fb549c09a2c55d7cb90d7ba84927e64618 2022-04-11T13:46:23.953121Z @@ -132,7 +132,7 @@ 2 No - 1 Yes + 2 No 2 No diff --git a/spec/services/imports/case_logs_field_import_service_spec.rb b/spec/services/imports/case_logs_field_import_service_spec.rb index 8d3062bb0..419ddbea3 100644 --- a/spec/services/imports/case_logs_field_import_service_spec.rb +++ b/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