diff --git a/app/models/validations/setup_validations.rb b/app/models/validations/setup_validations.rb index ff814ea35..d42ca2ec7 100644 --- a/app/models/validations/setup_validations.rb +++ b/app/models/validations/setup_validations.rb @@ -24,7 +24,7 @@ module Validations::SetupValidations return unless record.scheme unless record.scheme.locations.confirmed.any? - record.errors.add :scheme_id, I18n.t("validations.scheme.no_completed_locations") + record.errors.add :scheme_id, :no_completed_locations, message: I18n.t("validations.scheme.no_completed_locations") end end diff --git a/app/services/imports/lettings_logs_import_service.rb b/app/services/imports/lettings_logs_import_service.rb index bd758ab45..5930e60d9 100644 --- a/app/services/imports/lettings_logs_import_service.rb +++ b/app/services/imports/lettings_logs_import_service.rb @@ -328,6 +328,7 @@ module Imports %i[layear renewal_just_moved] => %w[layear], %i[voiddate after_mrcdate] => %w[voiddate mrcdate majorrepairs], %i[tshortfall more_than_rent] => %w[tshortfall tshortfall_known], + %i[scheme_id no_completed_locations] => %w[scheme_id location_id], } (2..8).each do |person| diff --git a/spec/services/imports/lettings_logs_import_service_spec.rb b/spec/services/imports/lettings_logs_import_service_spec.rb index 13c1bbe49..40c92c5ce 100644 --- a/spec/services/imports/lettings_logs_import_service_spec.rb +++ b/spec/services/imports/lettings_logs_import_service_spec.rb @@ -875,6 +875,34 @@ RSpec.describe Imports::LettingsLogsImportService do end end + context "and no scheme locations are confirmed" do + let(:lettings_log_id) { "0b4a68df-30cc-474a-93c0-a56ce8fdad3b" } + + before do + scheme = Scheme.find_by(old_visible_id: "0123") + scheme.locations.update!(confirmed: false, mobility_type: nil) + end + + it "intercepts the relevant validation error" do + expect(logger).to receive(:warn).with(/Differences found when saving log/) + expect(logger).to receive(:warn).with(/Removing scheme_id with error: This scheme cannot be chosen as it has no completed locations/) + expect(logger).to receive(:warn).with(/Removing location_id with error: This scheme cannot be chosen as it has no completed locations/) + expect { lettings_log_service.send(:create_log, lettings_log_xml) } + .not_to raise_error + end + + it "clears out the location answers" do + allow(logger).to receive(:warn) + + lettings_log_service.send(:create_log, lettings_log_xml) + lettings_log = LettingsLog.find_by(old_id: lettings_log_id) + + expect(lettings_log).not_to be_nil + expect(lettings_log.location).to be_nil + expect(lettings_log.scheme).to be_nil + end + end + context "and carehome charges are out of range" do let(:lettings_log_id) { "0b4a68df-30cc-474a-93c0-a56ce8fdad3b" }