Browse Source

Clear scheme if it has no confirmed locations (#1649)

pull/1650/head v0.3.22
kosiakkatrina 2 years ago committed by GitHub
parent
commit
f57ac0589e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      app/models/validations/setup_validations.rb
  2. 1
      app/services/imports/lettings_logs_import_service.rb
  3. 28
      spec/services/imports/lettings_logs_import_service_spec.rb

2
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

1
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|

28
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" }

Loading…
Cancel
Save