Browse Source

Clear layear if it's invalid for renewal

pull/1646/head
Kat 3 years ago
parent
commit
5351250617
  1. 2
      app/models/validations/household_validations.rb
  2. 1
      app/services/imports/lettings_logs_import_service.rb
  3. 81
      spec/services/imports/lettings_logs_import_service_spec.rb

2
app/models/validations/household_validations.rb

@ -116,7 +116,7 @@ module Validations::HouseholdValidations
return unless record.layear && record.renewal return unless record.layear && record.renewal
if record.is_renewal? && record.layear == 1 if record.is_renewal? && record.layear == 1
record.errors.add :layear, I18n.t("validations.household.renewal_just_moved_to_area.layear") record.errors.add :layear, :renewal_just_moved, message: I18n.t("validations.household.renewal_just_moved_to_area.layear")
record.errors.add :renewal, I18n.t("validations.household.renewal_just_moved_to_area.renewal") record.errors.add :renewal, I18n.t("validations.household.renewal_just_moved_to_area.renewal")
end end
end end

1
app/services/imports/lettings_logs_import_service.rb

@ -325,6 +325,7 @@ module Imports
%i[tcharge under_10] => charges_attributes, %i[tcharge under_10] => charges_attributes,
%i[brent over_hard_max] => charges_attributes, %i[brent over_hard_max] => charges_attributes,
%i[period wrong_rent_period] => %w[period], %i[period wrong_rent_period] => %w[period],
%i[layear renewal_just_moved] => %w[layear],
} }
(2..8).each do |person| (2..8).each do |person|

81
spec/services/imports/lettings_logs_import_service_spec.rb

@ -1310,6 +1310,87 @@ RSpec.describe Imports::LettingsLogsImportService do
end end
end end
context "when this is a renewal and layear is just moved to local authority" do
let(:lettings_log_id) { "0ead17cb-1668-442d-898c-0d52879ff592" }
let(:lettings_log_file) { open_file(fixture_directory, lettings_log_id) }
let(:lettings_log_xml) { Nokogiri::XML(lettings_log_file) }
before do
lettings_log_xml.at_xpath("//xmlns:DAY").content = "10"
lettings_log_xml.at_xpath("//xmlns:MONTH").content = "10"
lettings_log_xml.at_xpath("//xmlns:YEAR").content = "2022"
lettings_log_xml.at_xpath("//xmlns:Q27").content = "14"
lettings_log_xml.at_xpath("//xmlns:Q12c").content = "1"
lettings_log_xml.at_xpath("//xmlns:Q26").content = "1"
lettings_log_xml.at_xpath("//xmlns:MRCDAY").content = ""
lettings_log_xml.at_xpath("//xmlns:MRCMONTH").content = ""
lettings_log_xml.at_xpath("//xmlns:MRCYEAR").content = ""
lettings_log_xml.at_xpath("//xmlns:VDAY").content = "10"
lettings_log_xml.at_xpath("//xmlns:VMONTH").content = "10"
lettings_log_xml.at_xpath("//xmlns:VYEAR").content = "2022"
lettings_log_xml.at_xpath("//xmlns:P1Nat").content = ""
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"
end
it "intercepts the relevant validation error" do
expect(logger).to receive(:warn).with(/Removing layear with error: The household cannot have just moved to the local authority area if this letting is a renewal/)
expect { lettings_log_service.send(:create_log, lettings_log_xml) }
.not_to raise_error
end
it "clears out the layear answer" 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.layear).to be_nil
end
end
context "when this is a void date is after major repairs day" do
let(:lettings_log_id) { "0ead17cb-1668-442d-898c-0d52879ff592" }
let(:lettings_log_file) { open_file(fixture_directory, lettings_log_id) }
let(:lettings_log_xml) { Nokogiri::XML(lettings_log_file) }
before do
lettings_log_xml.at_xpath("//xmlns:DAY").content = "10"
lettings_log_xml.at_xpath("//xmlns:MONTH").content = "10"
lettings_log_xml.at_xpath("//xmlns:YEAR").content = "2022"
# lettings_log_xml.at_xpath("//xmlns:Q12c").content = "1"
# lettings_log_xml.at_xpath("//xmlns:Q26").content = "1"
lettings_log_xml.at_xpath("//xmlns:MRCDAY").content = "9"
lettings_log_xml.at_xpath("//xmlns:MRCMONTH").content = "9"
lettings_log_xml.at_xpath("//xmlns:MRCYEAR").content = "2021"
lettings_log_xml.at_xpath("//xmlns:VDAY").content = "10"
lettings_log_xml.at_xpath("//xmlns:VMONTH").content = "10"
lettings_log_xml.at_xpath("//xmlns:VYEAR").content = "2021"
# lettings_log_xml.at_xpath("//xmlns:P1Nat").content = ""
# 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"
end
it "intercepts the relevant validation error" do
expect(logger).to receive(:warn).with(/Removing layear with error: The household cannot have just moved to the local authority area if this letting is a renewal/)
expect { lettings_log_service.send(:create_log, lettings_log_xml) }
.not_to raise_error
end
it "clears out the layear answer" 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.layear).to be_nil
end
end
context "and the earnings is not a whole number" do context "and the earnings is not a whole number" do
let(:lettings_log_id) { "00d2343e-d5fa-4c89-8400-ec3854b0f2b4" } let(:lettings_log_id) { "00d2343e-d5fa-4c89-8400-ec3854b0f2b4" }
let(:lettings_log_file) { open_file(fixture_directory, lettings_log_id) } let(:lettings_log_file) { open_file(fixture_directory, lettings_log_id) }

Loading…
Cancel
Save