Browse Source

Reimport childrens social care referral values (#1926)

pull/1932/head
kosiakkatrina 1 year ago committed by GitHub
parent
commit
de5bfe6597
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 16
      app/services/imports/lettings_logs_field_import_service.rb
  2. 12
      config/forms/2021_2022.json
  3. 2
      lib/tasks/data_import_field.rake
  4. 12
      spec/lib/tasks/data_import_field_spec.rb
  5. 56
      spec/services/imports/lettings_logs_field_import_service_spec.rb

16
app/services/imports/lettings_logs_field_import_service.rb

@ -26,6 +26,8 @@ module Imports
import_from(folder, :update_general_needs_referral) import_from(folder, :update_general_needs_referral)
when "person_details" when "person_details"
import_from(folder, :update_person_details) import_from(folder, :update_person_details)
when "childrens_care_referral"
import_from(folder, :update_childrens_care_referral)
else else
raise "Updating #{field} is not supported by the field import service" raise "Updating #{field} is not supported by the field import service"
end end
@ -409,5 +411,19 @@ module Imports
def person_exists_on_the_log?(record, person_index) def person_exists_on_the_log?(record, person_index)
person_index <= record.hhmemb person_index <= record.hhmemb
end end
def update_childrens_care_referral(xml_doc)
return if meta_field_value(xml_doc, "form-name").include?("Sales")
old_id = meta_field_value(xml_doc, "document-id")
record = LettingsLog.find_by(old_id:)
return @logger.warn("lettings log with old id #{old_id} not found") unless record
return @logger.info("lettings log #{record.id} has a value for referral, skipping update") if record.referral.present?
return @logger.info("lettings log #{record.id} reimport referral value is not 17, skipping update") if unsafe_string_as_integer(xml_doc, "Q16") != 17
record.update!(referral: 17, values_updated_at: Time.zone.now)
@logger.info("lettings log #{record.id}'s referral value has been set to 17")
end
end end
end end

12
config/forms/2021_2022.json

@ -7103,6 +7103,9 @@
"13": { "13": {
"value": "Youth offending team" "value": "Youth offending team"
}, },
"17": {
"value": "Children’s Social Care"
},
"16": { "16": {
"value": "Other" "value": "Other"
} }
@ -7163,6 +7166,9 @@
"13": { "13": {
"value": "Youth offending team" "value": "Youth offending team"
}, },
"17": {
"value": "Children’s Social Care"
},
"16": { "16": {
"value": "Other" "value": "Other"
} }
@ -7220,6 +7226,9 @@
"13": { "13": {
"value": "Youth offending team" "value": "Youth offending team"
}, },
"17": {
"value": "Children’s Social Care"
},
"16": { "16": {
"value": "Other" "value": "Other"
} }
@ -7280,6 +7289,9 @@
"13": { "13": {
"value": "Youth offending team" "value": "Youth offending team"
}, },
"17": {
"value": "Children’s Social Care"
},
"16": { "16": {
"value": "Other" "value": "Other"
} }

2
lib/tasks/data_import_field.rake

@ -7,7 +7,7 @@ namespace :core do
# We only allow a reduced list of known fields to be updatable # We only allow a reduced list of known fields to be updatable
case field case field
when "tenancycode", "major_repairs", "lettings_allocation", "offered", "address", "reason", "homeless", "created_by", "sex_and_relat", "general_needs_referral", "person_details" when "tenancycode", "major_repairs", "lettings_allocation", "offered", "address", "reason", "homeless", "created_by", "sex_and_relat", "general_needs_referral", "person_details", "childrens_care_referral"
s3_service = Storage::S3Service.new(PlatformHelper.is_paas? ? Configuration::PaasConfigurationService.new : Configuration::EnvConfigurationService.new, ENV["IMPORT_PAAS_INSTANCE"]) s3_service = Storage::S3Service.new(PlatformHelper.is_paas? ? Configuration::PaasConfigurationService.new : Configuration::EnvConfigurationService.new, ENV["IMPORT_PAAS_INSTANCE"])
archive_io = s3_service.get_file_io(path) archive_io = s3_service.get_file_io(path)
archive_service = Storage::ArchiveService.new(archive_io) archive_service = Storage::ArchiveService.new(archive_io)

12
spec/lib/tasks/data_import_field_spec.rb

@ -176,6 +176,18 @@ describe "data_import_field imports" do
end end
end end
context "and we update the childrens_care_referral field" do
let(:field) { "childrens_care_referral" }
it "updates the 2023 logs from the given XML file" do
expect(Storage::S3Service).to receive(:new).with(paas_config_service, instance_name)
expect(storage_service).to receive(:get_file_io).with("spec/fixtures/imports/logs")
expect(Imports::LettingsLogsFieldImportService).to receive(:new).with(archive_service)
expect(import_service).to receive(:update_field).with(field, "logs")
task.invoke(field, fixture_path)
end
end
it "raises an exception if no parameters are provided" do it "raises an exception if no parameters are provided" do
expect { task.invoke }.to raise_error(/Usage/) expect { task.invoke }.to raise_error(/Usage/)
end end

56
spec/services/imports/lettings_logs_field_import_service_spec.rb

@ -1353,4 +1353,60 @@ RSpec.describe Imports::LettingsLogsFieldImportService do
end end
end end
end end
context "when updating referral with children's care" do
let(:lettings_log) { LettingsLog.find_by(old_id: lettings_log_id) }
before do
Imports::LettingsLogsImportService.new(storage_service, logger).create_logs(fixture_directory)
lettings_log_file.rewind
lettings_log_xml.at_xpath("//xmlns:Q16").content = "17"
lettings_log.owning_organisation.update!(provider_type: "PRP")
end
context "when the lettings log has no referral value" do
before do
lettings_log.update!(renewal: 0, referral: nil, values_updated_at: nil)
end
it "updates the lettings_log referral value" do
expect(logger).to receive(:info).with(/lettings log \d+'s referral value has been set to 17/)
expect { import_service.send(:update_childrens_care_referral, lettings_log_xml) }
.to(change { lettings_log.reload.referral }.from(nil).to(17))
expect(lettings_log.values_updated_at).not_to be_nil
end
end
context "when the lettings log has a referral value" do
before do
lettings_log.update!(referral: 2, values_updated_at: nil)
end
it "does not update the lettings_log referral value" do
expect(logger).to receive(:info).with(/lettings log \d+ has a value for referral, skipping update/)
import_service.send(:update_childrens_care_referral, lettings_log_xml)
lettings_log.reload
expect(lettings_log.referral).to eq(2)
expect(lettings_log.values_updated_at).to be_nil
end
end
context "and the new value does not set referral to 17" do
let(:lettings_log) { LettingsLog.find_by(old_id: lettings_log_id) }
before do
lettings_log.update!(referral: nil, values_updated_at: nil)
lettings_log_xml.at_xpath("//xmlns:Q16").content = "1"
end
it "skips update" do
expect(logger).to receive(:info).with(/lettings log \d+ reimport referral value is not 17, skipping update/)
expect { import_service.send(:update_childrens_care_referral, lettings_log_xml) }
.not_to(change { lettings_log.reload.referral })
expect(lettings_log.values_updated_at).to be_nil
end
end
end
end end

Loading…
Cancel
Save