Browse Source

Reimport lettings log form ID (#1950)

pull/1955/head v0.3.63
kosiakkatrina 1 year ago committed by GitHub
parent
commit
7a4edeb17c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 21
      app/services/imports/lettings_logs_field_import_service.rb
  2. 2
      lib/tasks/data_import_field.rake
  3. 12
      spec/lib/tasks/data_import_field_spec.rb
  4. 33
      spec/services/imports/lettings_logs_field_import_service_spec.rb

21
app/services/imports/lettings_logs_field_import_service.rb

@ -28,6 +28,8 @@ module Imports
import_from(folder, :update_person_details)
when "childrens_care_referral"
import_from(folder, :update_childrens_care_referral)
when "old_form_id"
import_from(folder, :update_old_form_id)
else
raise "Updating #{field} is not supported by the field import service"
end
@ -432,5 +434,24 @@ module Imports
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
def update_old_form_id(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:)
if record.present?
if record.old_form_id.present?
@logger.info("lettings log #{record.id} has a value for old_form_id, skipping update")
else
old_form_id = safe_string_as_integer(xml_doc, "FORM")
record.update!(old_form_id:)
@logger.info("lettings log #{record.id}'s old_form_id value has been set to #{old_form_id}")
end
else
@logger.warn("lettings log with old id #{old_id} not found")
end
end
end
end

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
case field
when "tenancycode", "major_repairs", "lettings_allocation", "offered", "address", "reason", "homeless", "created_by", "sex_and_relat", "general_needs_referral", "person_details", "childrens_care_referral"
when "tenancycode", "major_repairs", "lettings_allocation", "offered", "address", "reason", "homeless", "created_by", "sex_and_relat", "general_needs_referral", "person_details", "childrens_care_referral", "old_form_id"
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_service = Storage::ArchiveService.new(archive_io)

12
spec/lib/tasks/data_import_field_spec.rb

@ -188,6 +188,18 @@ describe "data_import_field imports" do
end
end
context "and we update the old_form_id field" do
let(:field) { "old_form_id" }
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
expect { task.invoke }.to raise_error(/Usage/)
end

33
spec/services/imports/lettings_logs_field_import_service_spec.rb

@ -1417,4 +1417,37 @@ RSpec.describe Imports::LettingsLogsFieldImportService do
end
end
end
context "when updating old_form_id" do
let(:field) { "old_form_id" }
let(:lettings_log) { LettingsLog.find_by(old_id: lettings_log_id) }
context "when the lettings log has no old_form_id value" do
before do
Imports::LettingsLogsImportService.new(storage_service, logger).create_logs(fixture_directory)
lettings_log_file.rewind
lettings_log.update!(old_form_id: nil)
end
it "updates the lettings_log old_form_id value" do
expect(logger).to receive(:info).with("lettings log #{lettings_log.id}'s old_form_id value has been set to 5786509")
expect { import_service.send(:update_field, field, remote_folder) }
.to(change { lettings_log.reload.old_form_id }.from(nil).to(5_786_509))
end
end
context "when the lettings log has a different old_form_id value" do
before do
Imports::LettingsLogsImportService.new(storage_service, logger).create_logs(fixture_directory)
lettings_log_file.rewind
lettings_log.update!(old_form_id: 123)
end
it "does not update the lettings_log old_form_id value" do
expect(logger).to receive(:info).with(/lettings log \d+ has a value for old_form_id, skipping update/)
expect { import_service.send(:update_field, field, remote_folder) }
.not_to(change { lettings_log.reload.old_form_id })
end
end
end
end

Loading…
Cancel
Save