Browse Source

CLDC-2729 Reimport referral for general needs PRP (#1923)

* Reimport referral for general needs PRP

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

18
app/services/imports/lettings_logs_field_import_service.rb

@ -22,6 +22,8 @@ module Imports
import_from(folder, :update_created_by) import_from(folder, :update_created_by)
when "sex_and_relat" when "sex_and_relat"
import_from(folder, :update_sex_and_relat) import_from(folder, :update_sex_and_relat)
when "general_needs_referral"
import_from(folder, :update_general_needs_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
@ -281,5 +283,21 @@ module Imports
record.save! record.save!
end end
end end
def update_general_needs_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} is a supported housing log, skipping update") if record.needstype == 2
return @logger.info("lettings log #{record.id}'s owning organisation's provider type is LA, skipping update") if record.owning_organisation.provider_type == "LA"
return @logger.info("lettings log #{record.id} reimport referral value is not 4, skipping update") if unsafe_string_as_integer(xml_doc, "Q16") != 4
record.update!(referral: 4, referral_value_check: 0, values_updated_at: Time.zone.now)
@logger.info("lettings log #{record.id}'s referral value has been set to 4")
end
end end
end end

3
config/forms/2021_2022.json

@ -7136,6 +7136,9 @@
"3": { "3": {
"value": "Nominated by a local housing authority" "value": "Nominated by a local housing authority"
}, },
"4": {
"value": "Referred by local authority housing department"
},
"8": { "8": {
"value": "Re-located through official housing mobility scheme" "value": "Re-located through official housing mobility scheme"
}, },

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" when "tenancycode", "major_repairs", "lettings_allocation", "offered", "address", "reason", "homeless", "created_by", "sex_and_relat", "general_needs_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

@ -152,6 +152,18 @@ describe "data_import_field imports" do
end end
end end
context "and we update the referral (for general needs) field" do
let(:field) { "general_needs_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

84
spec/services/imports/lettings_logs_field_import_service_spec.rb

@ -937,4 +937,88 @@ RSpec.describe Imports::LettingsLogsFieldImportService do
end end
end end
end end
context "when updating referral" do
let(:field) { "referral" }
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 = "4"
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 4/)
expect { import_service.send(:update_general_needs_referral, lettings_log_xml) }
.to(change { lettings_log.reload.referral }.from(nil).to(4))
expect(lettings_log.referral_value_check).to eq(0)
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_general_needs_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 "when the lettings log is supported housing" do
before do
lettings_log.update!(referral: nil, needstype: 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+ is a supported housing log, skipping update/)
expect { import_service.send(:update_general_needs_referral, lettings_log_xml) }
.not_to(change { lettings_log.reload.referral })
expect(lettings_log.values_updated_at).to be_nil
end
end
context "when the owning organisation is LA" do
before do
lettings_log.update!(referral: nil, values_updated_at: nil)
lettings_log.owning_organisation.update!(provider_type: "LA")
end
it "does not update the lettings_log referral value" do
expect(logger).to receive(:info).with(/lettings log \d+'s owning organisation's provider type is LA, skipping update/)
expect { import_service.send(:update_general_needs_referral, lettings_log_xml) }
.not_to(change { lettings_log.reload.referral })
expect(lettings_log.values_updated_at).to be_nil
end
end
context "and the new value does not set referral to 4" 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 4, skipping update/)
expect { import_service.send(:update_general_needs_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