Browse Source

Clear location and scheme if location is inactive during the tenancy start date

pull/1479/head
Kat 3 years ago
parent
commit
7501d85063
  1. 2
      app/models/validations/shared_validations.rb
  2. 5
      app/services/imports/lettings_logs_import_service.rb
  3. 27
      spec/services/imports/lettings_logs_import_service_spec.rb

2
app/models/validations/shared_validations.rb

@ -47,7 +47,7 @@ module Validations::SharedValidations
if location_inactive_status.present?
date, scope, deactivation_date = location_inactive_status.values_at(:date, :scope, :deactivation_date)
record.errors.add field, I18n.t("validations.setup.startdate.location.#{scope}", postcode: record.location.postcode, date:, deactivation_date:)
record.errors.add field, :not_active, message: I18n.t("validations.setup.startdate.location.#{scope}", postcode: record.location.postcode, date:, deactivation_date:)
end
end

5
app/services/imports/lettings_logs_import_service.rb

@ -385,6 +385,11 @@ module Imports
@logs_overridden << lettings_log.old_id
%w[brent scharge pscharge supcharg tcharge].each { |name| attributes.delete(name) }
save_lettings_log(attributes, previous_status)
elsif lettings_log.errors.of_kind?(:location_id, :not_active)
@logger.warn("Log #{lettings_log.old_id}: Removing scheme and location because it was not active during the tenancy start date/")
@logs_overridden << lettings_log.old_id
%w[location_id scheme_id].each { |name| attributes.delete(name) }
save_lettings_log(attributes, previous_status)
else
@logger.error("Log #{lettings_log.old_id}: Failed to import")
lettings_log.errors.each do |error|

27
spec/services/imports/lettings_logs_import_service_spec.rb

@ -667,6 +667,33 @@ RSpec.describe Imports::LettingsLogsImportService do
end
end
context "and location is not active during the period" do
let(:lettings_log_id) { "0b4a68df-30cc-474a-93c0-a56ce8fdad3b" }
before do
location = Location.find_by(old_visible_id: "10")
FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2021, 10, 10), location:)
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 and location because it was not active during the tenancy start date/)
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 the net income soft validation is triggered (net_income_value_check)" do
before do
lettings_log_xml.at_xpath("//xmlns:Q8a").content = "1 Weekly"

Loading…
Cancel
Save