diff --git a/app/services/imports/lettings_logs_field_import_service.rb b/app/services/imports/lettings_logs_field_import_service.rb
index e59e178f2..8e33da0c2 100644
--- a/app/services/imports/lettings_logs_field_import_service.rb
+++ b/app/services/imports/lettings_logs_field_import_service.rb
@@ -1,5 +1,5 @@
module Imports
- class LettingsLogsFieldImportService < ImportService
+ class LettingsLogsFieldImportService < LogsImportService
def update_field(field, folder)
case field
when "tenancycode"
@@ -8,6 +8,8 @@ module Imports
import_from(folder, :update_major_repairs)
when "lettings_allocation"
import_from(folder, :update_lettings_allocation)
+ when "offered"
+ import_from(folder, :update_offered)
else
raise "Updating #{field} is not supported by the field import service"
end
@@ -15,6 +17,23 @@ module Imports
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)
old_id = meta_field_value(xml_doc, "document-id")
previous_status = meta_field_value(xml_doc, "status")
diff --git a/spec/fixtures/imports/logs/0ead17cb-1668-442d-898c-0d52879ff592.xml b/spec/fixtures/imports/logs/0ead17cb-1668-442d-898c-0d52879ff592.xml
index 15f97ce5b..87797e242 100644
--- a/spec/fixtures/imports/logs/0ead17cb-1668-442d-898c-0d52879ff592.xml
+++ b/spec/fixtures/imports/logs/0ead17cb-1668-442d-898c-0d52879ff592.xml
@@ -170,7 +170,7 @@
2021-09-30
- 0
+ 21
MCB003
diff --git a/spec/services/imports/lettings_logs_field_import_service_spec.rb b/spec/services/imports/lettings_logs_field_import_service_spec.rb
index 0c55139e8..3cd4e930d 100644
--- a/spec/services/imports/lettings_logs_field_import_service_spec.rb
+++ b/spec/services/imports/lettings_logs_field_import_service_spec.rb
@@ -249,4 +249,40 @@ RSpec.describe Imports::LettingsLogsFieldImportService do
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
diff --git a/spec/services/imports/lettings_logs_import_service_spec.rb b/spec/services/imports/lettings_logs_import_service_spec.rb
index 00db327d5..869bd36fc 100644
--- a/spec/services/imports/lettings_logs_import_service_spec.rb
+++ b/spec/services/imports/lettings_logs_import_service_spec.rb
@@ -456,7 +456,7 @@ RSpec.describe Imports::LettingsLogsImportService do
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
lettings_log_xml.at_xpath("//xmlns:Q20").content = "155"
end
@@ -1360,6 +1360,7 @@ RSpec.describe Imports::LettingsLogsImportService do
lettings_log_xml.at_xpath("//xmlns:Q9a").content = ""
lettings_log_xml.at_xpath("//xmlns:Q11").content = "32"
lettings_log_xml.at_xpath("//xmlns:Q16").content = "1"
+ lettings_log_xml.at_xpath("//xmlns:Q20").content = "0"
end
it "intercepts the relevant validation error" do