From 8770343384500a74dee41f11cd6efbcf69fb104f Mon Sep 17 00:00:00 2001
From: Dushan <47317567+dushan-madetech@users.noreply.github.com>
Date: Fri, 27 May 2022 16:01:40 +0100
Subject: [PATCH] Cldc 1220 better logging status discrepancies (#620)
* Fix spec description
* add test and code for logging old id of status discrepancies
* add test and code for logging all case logs with status discrepancies
* lint fixes
* fix spec descriptions
---
.../imports/case_logs_import_service.rb | 5 +
app/services/imports/import_service.rb | 1 +
.../5ybz29dj-l33t-k1l0-hj86-n4k4ma77xkcd.xml | 514 ++++++++++++++++++
.../893ufj2s-lq77-42m4-rty6-ej09gh585uy1.xml | 514 ++++++++++++++++++
.../imports/case_logs_import_service_spec.rb | 37 +-
.../organisation_la_import_service_spec.rb | 2 +-
...isation_rent_period_import_service_spec.rb | 2 +-
7 files changed, 1072 insertions(+), 3 deletions(-)
create mode 100644 spec/fixtures/softwire_imports/case_logs/5ybz29dj-l33t-k1l0-hj86-n4k4ma77xkcd.xml
create mode 100644 spec/fixtures/softwire_imports/case_logs/893ufj2s-lq77-42m4-rty6-ej09gh585uy1.xml
diff --git a/app/services/imports/case_logs_import_service.rb b/app/services/imports/case_logs_import_service.rb
index 0b74e2fc5..6b670ce81 100644
--- a/app/services/imports/case_logs_import_service.rb
+++ b/app/services/imports/case_logs_import_service.rb
@@ -2,6 +2,9 @@ module Imports
class CaseLogsImportService < ImportService
def create_logs(folder)
import_from(folder, :create_log)
+ if @logs_with_discrepancies.count.positive?
+ @logger.warn("The following case logs had status discrepancies: [#{@logs_with_discrepancies.join(', ')}]")
+ end
end
private
@@ -226,6 +229,8 @@ module Imports
def check_status_completed(case_log, previous_status)
if previous_status.include?("submitted") && case_log.status != "completed"
@logger.warn "Case log #{case_log.id} is not completed"
+ @logger.warn "Case log with old id:#{case_log.old_id} is incomplete but status should be complete"
+ @logs_with_discrepancies << case_log.old_id
end
end
diff --git a/app/services/imports/import_service.rb b/app/services/imports/import_service.rb
index 664790055..e45498004 100644
--- a/app/services/imports/import_service.rb
+++ b/app/services/imports/import_service.rb
@@ -5,6 +5,7 @@ module Imports
def initialize(storage_service, logger = Rails.logger)
@storage_service = storage_service
@logger = logger
+ @logs_with_discrepancies = []
end
def import_from(folder, create_method)
diff --git a/spec/fixtures/softwire_imports/case_logs/5ybz29dj-l33t-k1l0-hj86-n4k4ma77xkcd.xml b/spec/fixtures/softwire_imports/case_logs/5ybz29dj-l33t-k1l0-hj86-n4k4ma77xkcd.xml
new file mode 100644
index 000000000..2531314dd
--- /dev/null
+++ b/spec/fixtures/softwire_imports/case_logs/5ybz29dj-l33t-k1l0-hj86-n4k4ma77xkcd.xml
@@ -0,0 +1,514 @@
+
+
+ 2021-CORE-IR-GN
+ 5ybz29dj-l33t-k1l0-hj86-n4k4ma77xkcd
+ e29c492473446dca4d50224f2bb7cf965a261d6f
+ 7c5bd5fb549c09a2c55d7cb90d7ba84927e64618
+ 7c5bd5fb549c09a2c55d7cb90d7ba84927e64618
+ 2022-04-11T13:46:23.953121Z
+ 2022-04-11T13:46:23.953121Z
+ submitted-valid
+ 2021
+ Manual Entry
+
+
+
+
+ Yes
+ 2 London Living Rent
+
+ 2021-11-10
+
+ 1 Private Registered Provider
+
+ <_1btenagree>1 This Landlord
+ <_1bifanother/>
+ <_1bCOREcode/>
+
+
+
+ <_2a>2 No
+ 2 Assured
+
+ <_2bTenCode>TEN0021
+ <_2cYears/>
+
+
+ 37
+
+ Female
+ 1) Full Time
+ 1 White: English/Scottish/Welsh/Northern Irish/British
+ 1 UK national resident in UK
+ 34
+
+ Female
+ Other
+ 1) Full Time
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 2 No
+
+
+ 2 No
+
+
+ 7 UC – without housing element (not in receipt of HB and tenants not eligible for housing support e.g. residential care home)
+
+
+ 3 None
+
+
+
+
+
+ 8 (Non-violent) relationship breakdown with partner
+
+
+
+ <_9b override-field="">2 No
+
+
+
+
+ Yes
+
+ 1 Yes
+
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1.xml b/spec/fixtures/softwire_imports/case_logs/893ufj2s-lq77-42m4-rty6-ej09gh585uy1.xml
new file mode 100644
index 000000000..f01bb1baa
--- /dev/null
+++ b/spec/fixtures/softwire_imports/case_logs/893ufj2s-lq77-42m4-rty6-ej09gh585uy1.xml
@@ -0,0 +1,514 @@
+
+
+ 2021-CORE-IR-GN
+ 893ufj2s-lq77-42m4-rty6-ej09gh585uy1
+ e29c492473446dca4d50224f2bb7cf965a261d6f
+ 7c5bd5fb549c09a2c55d7cb90d7ba84927e64618
+ 7c5bd5fb549c09a2c55d7cb90d7ba84927e64618
+ 2022-04-11T13:46:23.953121Z
+ 2022-04-11T13:46:23.953121Z
+ submitted-valid
+ 2021
+ Manual Entry
+
+
+
+
+ Yes
+ 2 London Living Rent
+
+ 2021-11-10
+
+ 1 Private Registered Provider
+
+ <_1btenagree>1 This Landlord
+ <_1bifanother/>
+ <_1bCOREcode/>
+
+
+
+ <_2a>2 No
+ 2 Assured
+
+ <_2bTenCode>TEN0021
+ <_2cYears/>
+
+
+ 37
+
+ Female
+ 1) Full Time
+ 1 White: English/Scottish/Welsh/Northern Irish/British
+ 1 UK national resident in UK
+ 34
+
+ Female
+ Other
+ 1) Full Time
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 2 No
+
+
+ 2 No
+
+
+ 7 UC – without housing element (not in receipt of HB and tenants not eligible for housing support e.g. residential care home)
+
+
+ 3 None
+
+
+
+
+
+ 8 (Non-violent) relationship breakdown with partner
+
+
+
+ <_9b override-field="">2 No
+
+
+
+
+ Yes
+
+ 1 Yes
+
+
+
+ Yes
+
+
+
+
+
+
+ 28 Living with friends or family
+ Blackpool
+ E09000009
+ FY1 1JD
+
+ 1 Just moved to Local Authority area
+ 1 Just moved to Local Authority area
+
+
+ 1 Not homeless
+ 2 No
+
+
+
+
+
+
+
+ 2 No
+ 2 No
+ 2 No
+
+
+ 10 Other social landlord
+
+
+
+ 1 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+ 0
+ 1
+ 0
+ 0
+ 0
+ 0
+ 0
+ 0
+ 1
+ 0
+ 0
+ 0
+ 0
+ 0
+ 0
+ 0
+ 0
+ 0
+ 0
+ 0
+ 0
+ 0
+ 0
+ 0
+ 0
+ 0
+
+
+ 2
+ 2 Existing Tenant
+ 1
+ 1
+ 209
+ 2
+ 1
+ 1
+ 0
+ 0
+ 0
+ 0
+ 0
+ 0
+ 2
+ 0
+ 0
+ 0
+ 0
+ 0
+ 0
+ 0
+ 0
+ 0
+ 0
+ 0
+ 0
+ 0
+ 0
+ 0
+ 0
+ 0
+ 0
+ 4 = 2 adults
+ 200.00
+ 200.00
+ 13
+
+ 200.00
+ 1 Private Registered Provider
+
+
+ E12000008
+ 1
+ DLUHC
+ DLUHC
+ 655
+ 655
+
+ 1
+
+
+
+
+
+
+
+
+
+
+
+
+ 13
+
+
+ 13
+ 0
+ 0
+ 0
+ 0
+ 0
+ 0
+ 0
+ 0
+ 0
+
+
+ 100.00
+ 100.00
+
+
+
+ 0.00
+
+
+
+ 100.00
+ 100.00
+
+
+
+ 0
+
+
+ 0
+ 2
+ 0
+ 0
+ 0
+ 0
+ 0
+ 0
+ 0
+ 0
+ 0
+ 0
+ 0
+ 0
+ 0
+ 0
+ 2
+ 0
+ 100.00
+ 23.35
+
+ 0
+ 0
+ 0
+
+
+ 0
+ 0
+ 23.35
+ 0
+ 0
+ 0
+ 0
+ 0
+ 0
+ 10
+ 11
+ 2021
+ 15
+ 4
+ 2021
+
+
+
+ FY1
+ 1JD
+
+
+
+
diff --git a/spec/services/imports/case_logs_import_service_spec.rb b/spec/services/imports/case_logs_import_service_spec.rb
index 0f1ee40b6..797a42e16 100644
--- a/spec/services/imports/case_logs_import_service_spec.rb
+++ b/spec/services/imports/case_logs_import_service_spec.rb
@@ -30,7 +30,7 @@ RSpec.describe Imports::CaseLogsImportService do
.to_return(status: 200, body: '{"status":200,"result":{"codes":{"admin_district":"E08000035"}}}', headers: {})
end
- context "when importing users" do
+ context "when importing case logs" do
let(:remote_folder) { "case_logs" }
let(:case_log_id) { "0ead17cb-1668-442d-898c-0d52879ff592" }
let(:case_log_id2) { "166fc004-392e-47a8-acb8-1c018734882b" }
@@ -66,6 +66,39 @@ RSpec.describe Imports::CaseLogsImportService do
expect { 2.times { case_log_service.create_logs(remote_folder) } }
.to change(CaseLog, :count).by(3)
end
+
+ context "when there are status discrepancies" do
+ let(:case_log_id4) { "893ufj2s-lq77-42m4-rty6-ej09gh585uy1" }
+ let(:case_log_id5) { "5ybz29dj-l33t-k1l0-hj86-n4k4ma77xkcd" }
+ let(:case_log_file) { open_file(fixture_directory, case_log_id4) }
+ let(:case_log_xml) { Nokogiri::XML(case_log_file) }
+
+ before do
+ allow(storage_service).to receive(:get_file_io)
+ .with("#{remote_folder}/#{case_log_id4}.xml")
+ .and_return(open_file(fixture_directory, case_log_id4), open_file(fixture_directory, case_log_id4))
+ allow(storage_service).to receive(:get_file_io)
+ .with("#{remote_folder}/#{case_log_id5}.xml")
+ .and_return(open_file(fixture_directory, case_log_id5), open_file(fixture_directory, case_log_id5))
+ end
+
+ it "the logger logs a warning with the case log's old id/filename" do
+ expect(logger).to receive(:warn).with(/is not completed/).once
+ expect(logger).to receive(:warn).with(/Case log with old id:#{case_log_id4} is incomplete but status should be complete/).once
+
+ case_log_service.send(:create_log, case_log_xml)
+ end
+
+ it "on completion the ids of all logs with status discrepancies are logged in a warning" do
+ allow(storage_service).to receive(:list_files)
+ .and_return(%W[#{remote_folder}/#{case_log_id4}.xml #{remote_folder}/#{case_log_id5}.xml])
+ allow(logger).to receive(:warn).with(/is not completed/)
+ allow(logger).to receive(:warn).with(/is incomplete but status should be complete/)
+ expect(logger).to receive(:warn).with(/The following case logs had status discrepancies: \[893ufj2s-lq77-42m4-rty6-ej09gh585uy1, 5ybz29dj-l33t-k1l0-hj86-n4k4ma77xkcd\]/).once
+
+ case_log_service.create_logs(remote_folder)
+ end
+ end
end
context "when importing a specific log" do
@@ -78,6 +111,8 @@ RSpec.describe Imports::CaseLogsImportService do
it "does not import the voiddate" do
allow(logger).to receive(:warn).with(/is not completed/)
+ allow(logger).to receive(:warn).with(/Case log with old id:#{case_log_id} is incomplete but status should be complete/)
+
case_log_service.send(:create_log, case_log_xml)
case_log = CaseLog.where(old_id: case_log_id).first
diff --git a/spec/services/imports/organisation_la_import_service_spec.rb b/spec/services/imports/organisation_la_import_service_spec.rb
index 8247c2b36..8d5784bb4 100644
--- a/spec/services/imports/organisation_la_import_service_spec.rb
+++ b/spec/services/imports/organisation_la_import_service_spec.rb
@@ -8,7 +8,7 @@ RSpec.describe Imports::OrganisationLaImportService do
let(:storage_service) { instance_double(StorageService) }
let(:logger) { instance_double(ActiveSupport::Logger) }
- context "when importing data protection confirmations" do
+ context "when importing organisation las" do
subject(:import_service) { described_class.new(storage_service, logger) }
before do
diff --git a/spec/services/imports/organisation_rent_period_import_service_spec.rb b/spec/services/imports/organisation_rent_period_import_service_spec.rb
index 39d2cf369..2921e5a4e 100644
--- a/spec/services/imports/organisation_rent_period_import_service_spec.rb
+++ b/spec/services/imports/organisation_rent_period_import_service_spec.rb
@@ -8,7 +8,7 @@ RSpec.describe Imports::OrganisationRentPeriodImportService do
let(:storage_service) { instance_double(StorageService) }
let(:logger) { instance_double(ActiveSupport::Logger) }
- context "when importing data protection confirmations" do
+ context "when importing organisation rent periods" do
subject(:import_service) { described_class.new(storage_service, logger) }
before do