Browse Source

CLDC-2452: Add method for importing the 'offered' field into already imported lettings logs (#1709)

* Add method for importing the 'offered' field into already imported lettings logs

* Add minimal tests

* feat: update tests

---------

Co-authored-by: natdeanlewissoftwire <nat.dean-lewis@softwire.com>
pull/1727/head
Rachael Booth 2 years ago committed by GitHub
parent
commit
82b066d83b
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
      spec/fixtures/imports/logs/0ead17cb-1668-442d-898c-0d52879ff592.xml
  3. 36
      spec/services/imports/lettings_logs_field_import_service_spec.rb
  4. 3
      spec/services/imports/lettings_logs_import_service_spec.rb

21
app/services/imports/lettings_logs_field_import_service.rb

@ -1,5 +1,5 @@
module Imports module Imports
class LettingsLogsFieldImportService < ImportService class LettingsLogsFieldImportService < LogsImportService
def update_field(field, folder) def update_field(field, folder)
case field case field
when "tenancycode" when "tenancycode"
@ -8,6 +8,8 @@ module Imports
import_from(folder, :update_major_repairs) import_from(folder, :update_major_repairs)
when "lettings_allocation" when "lettings_allocation"
import_from(folder, :update_lettings_allocation) import_from(folder, :update_lettings_allocation)
when "offered"
import_from(folder, :update_offered)
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
@ -15,6 +17,23 @@ module Imports
private private
def update_offered(xml_doc)
old_id = meta_field_value(xml_doc, "document-id")
record = LettingsLog.find_by(old_id:)
if record.present?
if record.offered.present?
@logger.info("lettings log #{record.id} has a value for offered, skipping update")
else
offered = safe_string_as_integer(xml_doc, "Q20")
record.update!(offered:)
@logger.info("lettings log #{record.id}'s offered value has been set to #{offered}'")
end
else
@logger.warn("lettings log with old id #{old_id} not found")
end
end
def update_lettings_allocation(xml_doc) def update_lettings_allocation(xml_doc)
old_id = meta_field_value(xml_doc, "document-id") old_id = meta_field_value(xml_doc, "document-id")
previous_status = meta_field_value(xml_doc, "status") previous_status = meta_field_value(xml_doc, "status")

2
spec/fixtures/imports/logs/0ead17cb-1668-442d-898c-0d52879ff592.xml vendored

@ -170,7 +170,7 @@
<Q18dyes override-field="true"/> <Q18dyes override-field="true"/>
<Q19void>2021-09-30</Q19void> <Q19void>2021-09-30</Q19void>
<Q19repair/> <Q19repair/>
<Q20 override-field="">0</Q20> <Q20 override-field="">21</Q20>
<Q21a>MCB003</Q21a> <Q21a>MCB003</Q21a>
</Group> </Group>
<Group> <Group>

36
spec/services/imports/lettings_logs_field_import_service_spec.rb

@ -249,4 +249,40 @@ RSpec.describe Imports::LettingsLogsFieldImportService do
end end
end end
end end
context "when updating offered" do
let(:field) { "offered" }
context "when the lettings log has no offered value" 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.update!(offered: nil)
end
it "updates the lettings_log offered value" do
expect(logger).to receive(:info).with(/lettings log \d+'s offered value has been set to 21/)
expect { import_service.send(:update_field, field, remote_folder) }
.to(change { lettings_log.reload.offered }.from(nil).to(21))
end
end
context "when the lettings log has a different offered value" 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.update!(offered: 18)
end
it "does not update the lettings_log offered value" do
expect(logger).to receive(:info).with(/lettings log \d+ has a value for offered, skipping update/)
expect { import_service.send(:update_field, field, remote_folder) }
.not_to(change { lettings_log.reload.offered })
end
end
end
end end

3
spec/services/imports/lettings_logs_import_service_spec.rb

@ -456,7 +456,7 @@ RSpec.describe Imports::LettingsLogsImportService do
end end
end end
context "and the number the property was relet is over 150" do context "and the number of times the property was relet is over 150" do
before do before do
lettings_log_xml.at_xpath("//xmlns:Q20").content = "155" lettings_log_xml.at_xpath("//xmlns:Q20").content = "155"
end end
@ -1360,6 +1360,7 @@ RSpec.describe Imports::LettingsLogsImportService do
lettings_log_xml.at_xpath("//xmlns:Q9a").content = "" lettings_log_xml.at_xpath("//xmlns:Q9a").content = ""
lettings_log_xml.at_xpath("//xmlns:Q11").content = "32" lettings_log_xml.at_xpath("//xmlns:Q11").content = "32"
lettings_log_xml.at_xpath("//xmlns:Q16").content = "1" lettings_log_xml.at_xpath("//xmlns:Q16").content = "1"
lettings_log_xml.at_xpath("//xmlns:Q20").content = "0"
end end
it "intercepts the relevant validation error" do it "intercepts the relevant validation error" do

Loading…
Cancel
Save