Browse Source

CLDC-1938 Reset invalid postcodes (#1385)

* Reset invalid postcodes

* lint

* Look at the correct previuos postcode field

* Check the error before clearing postcode known
pull/1394/head
kosiakkatrina 2 years ago committed by GitHub
parent
commit
ecab6ba2e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      app/models/validations/sales/household_validations.rb
  2. 5
      app/services/imports/sales_logs_import_service.rb
  3. 31
      spec/services/imports/sales_logs_import_service_spec.rb

4
app/models/validations/sales/household_validations.rb

@ -14,8 +14,8 @@ module Validations::Sales::HouseholdValidations
return unless record.postcode_full && record.ppostcode_full && record.discounted_ownership_sale?
unless record.postcode_full == record.ppostcode_full
record.errors.add :postcode_full, I18n.t("validations.household.postcode.discounted_ownership")
record.errors.add :ppostcode_full, I18n.t("validations.household.postcode.discounted_ownership")
record.errors.add :postcode_full, :postcodes_not_matching, message: I18n.t("validations.household.postcode.discounted_ownership")
record.errors.add :ppostcode_full, :postcodes_not_matching, message: I18n.t("validations.household.postcode.discounted_ownership")
end
end

5
app/services/imports/sales_logs_import_service.rb

@ -192,6 +192,11 @@ module Imports
attributes.delete(error.attribute.to_s)
end
@logs_overridden << sales_log.old_id
if sales_log.errors.of_kind?(:postcode_full, :postcodes_not_matching)
@logger.warn("Log #{sales_log.old_id}: Removing postcode known and previous postcode known as the postcodes are invalid")
attributes.delete("pcodenk")
attributes.delete("ppcodenk")
end
save_sales_log(attributes, previous_status)
else
@logger.error("Log #{sales_log.old_id}: Failed to import")

31
spec/services/imports/sales_logs_import_service_spec.rb

@ -394,6 +394,37 @@ RSpec.describe Imports::SalesLogsImportService do
end
end
context "and it has an invalid record with invalid postcodes" do
let(:sales_log_id) { "discounted_ownership_sales_log" }
before do
sales_log_xml.at_xpath("//meta:status").content = "submitted-invalid"
sales_log_xml.at_xpath("//xmlns:Q7Postcode").content = "A1 1AA"
sales_log_xml.at_xpath("//xmlns:Q14Postcode").content = "A1 2AA"
end
it "intercepts the relevant validation error" do
expect(logger).to receive(:warn).with(/Removing field postcode_full from log triggering validation: Buyer's last accommodation and discounted ownership postcodes must match/)
expect(logger).to receive(:warn).with(/Removing field ppostcode_full from log triggering validation: Buyer's last accommodation and discounted ownership postcodes must match/)
expect(logger).to receive(:warn).with(/Removing field postcode_full from log triggering validation: postcodes_not_matching/)
expect(logger).to receive(:warn).with(/Removing field ppostcode_full from log triggering validation: postcodes_not_matching/)
expect(logger).to receive(:warn).with(/Removing postcode known and previous postcode known as the postcodes are invalid/)
expect { sales_log_service.send(:create_log, sales_log_xml) }
.not_to raise_error
end
it "clears out the invalid answers" do
allow(logger).to receive(:warn)
sales_log_service.send(:create_log, sales_log_xml)
sales_log = SalesLog.find_by(old_id: sales_log_id)
expect(sales_log).not_to be_nil
expect(sales_log.postcode_full).to be_nil
expect(sales_log.ppostcode_full).to be_nil
end
end
context "when inferring default answers for completed sales logs" do
context "when the armedforcesspouse is not answered" do
let(:sales_log_id) { "discounted_ownership_sales_log" }

Loading…
Cancel
Save