Browse Source

CLDC-1938 Set soft validations to confirmed (#1384)

* Set soft validations to confirmed

* Add remaining default soft validation values

* Clears invalidated fields for in progress logs
pull/1387/head
kosiakkatrina 2 years ago committed by GitHub
parent
commit
931922b018
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 48
      app/services/imports/sales_logs_import_service.rb
  2. 2
      spec/fixtures/imports/sales_logs/shared_ownership_sales_log3.xml
  3. 191
      spec/services/imports/sales_logs_import_service_spec.rb

48
app/services/imports/sales_logs_import_service.rb

@ -137,6 +137,23 @@ module Imports
attributes["is_la_inferred"] = false attributes["is_la_inferred"] = false
end end
# Soft validations can become required answers, set them to yes by default
attributes["mortgage_value_check"] = 0
attributes["shared_ownership_deposit_value_check"] = 0
attributes["value_value_check"] = 0
attributes["savings_value_check"] = 0
attributes["income1_value_check"] = 0
attributes["deposit_value_check"] = 0
attributes["wheel_value_check"] = 0
attributes["retirement_value_check"] = 0
attributes["extrabor_value_check"] = 0
attributes["grant_value_check"] = 0
attributes["staircase_bought_value_check"] = 0
attributes["deposit_and_mortgage_value_check"] = 0
attributes["old_persons_shared_ownership_value_check"] = 0
attributes["income2_value_check"] = 0
attributes["monthly_charges_value_check"] = 0
# Sets the log creator # Sets the log creator
owner_id = meta_field_value(xml_doc, "owner-user-id").strip owner_id = meta_field_value(xml_doc, "owner-user-id").strip
if owner_id.present? if owner_id.present?
@ -168,17 +185,26 @@ module Imports
end end
end end
def rescue_validation_or_raise(sales_log, attributes, _previous_status, exception) def rescue_validation_or_raise(sales_log, attributes, previous_status, exception)
@logger.error("Log #{sales_log.old_id}: Failed to import") if %w[saved submitted-invalid].include?(previous_status)
sales_log.errors.each do |error| sales_log.errors.each do |error|
@logger.error("Validation error: Field #{error.attribute}:") @logger.warn("Log #{sales_log.old_id}: Removing field #{error.attribute} from log triggering validation: #{error.type}")
@logger.error("\tOwning Organisation: #{sales_log.owning_organisation&.name}") attributes.delete(error.attribute.to_s)
@logger.error("\tOld CORE ID: #{sales_log.old_id}") end
@logger.error("\tOld CORE: #{attributes[error.attribute.to_s]&.inspect}") @logs_overridden << sales_log.old_id
@logger.error("\tNew CORE: #{sales_log.read_attribute(error.attribute)&.inspect}") save_sales_log(attributes, previous_status)
@logger.error("\tError message: #{error.type}") else
@logger.error("Log #{sales_log.old_id}: Failed to import")
sales_log.errors.each do |error|
@logger.error("Validation error: Field #{error.attribute}:")
@logger.error("\tOwning Organisation: #{sales_log.owning_organisation&.name}")
@logger.error("\tOld CORE ID: #{sales_log.old_id}")
@logger.error("\tOld CORE: #{attributes[error.attribute.to_s]&.inspect}")
@logger.error("\tNew CORE: #{sales_log.read_attribute(error.attribute)&.inspect}")
@logger.error("\tError message: #{error.type}")
end
raise exception
end end
raise exception
end end
def compute_differences(sales_log, attributes) def compute_differences(sales_log, attributes)
@ -197,6 +223,7 @@ module Imports
def fields_not_present_in_softwire_data def fields_not_present_in_softwire_data
%w[created_by %w[created_by
income1_value_check income1_value_check
income2_value_check
mortgage_value_check mortgage_value_check
savings_value_check savings_value_check
deposit_value_check deposit_value_check
@ -396,7 +423,6 @@ module Imports
end end
def monthly_charges(xml_doc, attributes) def monthly_charges(xml_doc, attributes)
safe_string_as_decimal(xml_doc, "Q29MonthlyCharges")
case attributes["ownershipsch"] case attributes["ownershipsch"]
when 1 when 1
safe_string_as_decimal(xml_doc, "Q29MonthlyCharges") safe_string_as_decimal(xml_doc, "Q29MonthlyCharges")

2
spec/fixtures/imports/sales_logs/shared_ownership_sales_log3.xml vendored

@ -144,7 +144,7 @@
<P7RRefused>0</P7RRefused> <P7RRefused>0</P7RRefused>
<P8RRefused>0</P8RRefused> <P8RRefused>0</P8RRefused>
<TotRRefused>0</TotRRefused> <TotRRefused>0</TotRRefused>
<CALCMORT>76000</CALCMORT> <CALCMORT></CALCMORT>
<MORTGAGEUSED>1</MORTGAGEUSED> <MORTGAGEUSED>1</MORTGAGEUSED>
<IM1>47000</IM1> <IM1>47000</IM1>
<IM2>0</IM2> <IM2>0</IM2>

191
spec/services/imports/sales_logs_import_service_spec.rb

@ -203,6 +203,197 @@ RSpec.describe Imports::SalesLogsImportService do
end end
end end
context "and the mortgage soft validation is triggered (mortgage_value_check)" do
let(:sales_log_id) { "discounted_ownership_sales_log" }
before do
sales_log_xml.at_xpath("//xmlns:Q2Person1Income").content = "10"
end
it "completes the log" do
sales_log_service.send(:create_log, sales_log_xml)
sales_log = SalesLog.find_by(old_id: sales_log_id)
expect(sales_log.status).to eq("completed")
end
end
context "and the shared ownership deposit soft validation is triggered (shared_ownership_deposit_value_check)" do
let(:sales_log_id) { "shared_ownership_sales_log" }
before do
sales_log_xml.at_xpath("//xmlns:DerSaleType").content = "2"
sales_log_xml.at_xpath("//xmlns:CALCMORT").content = "275000"
end
it "completes the log" do
sales_log_service.send(:create_log, sales_log_xml)
sales_log = SalesLog.find_by(old_id: sales_log_id)
expect(sales_log.status).to eq("completed")
end
end
context "and the purchase price soft validation is triggered (value_value_check)" do
let(:sales_log_id) { "shared_ownership_sales_log" }
before do
LaSaleRange.create!(la: "E09000033", bedrooms: 2, soft_min: 177_000, soft_max: 384_000, start_year: 2022)
sales_log_xml.at_xpath("//xmlns:Q22PurchasePrice").content = "2750"
sales_log_xml.at_xpath("//xmlns:CALCMORT").content = "2750"
end
it "completes the log" do
sales_log_service.send(:create_log, sales_log_xml)
sales_log = SalesLog.find_by(old_id: sales_log_id)
expect(sales_log.status).to eq("completed")
end
end
context "and the purchase price soft validation is triggered (income1_value_check, income2_value_check)" do
let(:sales_log_id) { "shared_ownership_sales_log" }
before do
sales_log_xml.at_xpath("//xmlns:Q2Person1Income").content = "20"
sales_log_xml.at_xpath("//xmlns:Q2Person2Income").content = "10"
sales_log_xml.at_xpath("//xmlns:P2Eco").content = "1"
sales_log_xml.at_xpath("//xmlns:joint").content = "1 Yes"
sales_log_xml.at_xpath("//xmlns:JointMore").content = "2 No"
end
it "completes the log" do
sales_log_service.send(:create_log, sales_log_xml)
sales_log = SalesLog.find_by(old_id: sales_log_id)
expect(sales_log.status).to eq("completed")
end
end
context "and the savings soft validation is triggered (savings_value_check)" do
let(:sales_log_id) { "shared_ownership_sales_log" }
before do
sales_log_xml.at_xpath("//xmlns:Q3Savings").content = "200750"
end
it "completes the log" do
sales_log_service.send(:create_log, sales_log_xml)
sales_log = SalesLog.find_by(old_id: sales_log_id)
expect(sales_log.status).to eq("completed")
end
end
context "and the deposit soft validation is triggered (deposit_value_check)" do
let(:sales_log_id) { "shared_ownership_sales_log" }
before do
sales_log_xml.at_xpath("//xmlns:Q3Savings").content = "10"
end
it "completes the log" do
sales_log_service.send(:create_log, sales_log_xml)
sales_log = SalesLog.find_by(old_id: sales_log_id)
expect(sales_log.status).to eq("completed")
end
end
context "and the wheelchair soft validation is triggered (wheel_value_check)" do
let(:sales_log_id) { "shared_ownership_sales_log" }
before do
sales_log_xml.at_xpath("//xmlns:Q10Wheelchair").content = "1"
sales_log_xml.at_xpath("//xmlns:Disability").content = "2"
end
it "completes the log" do
sales_log_service.send(:create_log, sales_log_xml)
sales_log = SalesLog.find_by(old_id: sales_log_id)
expect(sales_log.status).to eq("completed")
end
end
context "and the retirement soft validation is triggered (retirement_value_check)" do
let(:sales_log_id) { "shared_ownership_sales_log" }
before do
sales_log_xml.at_xpath("//xmlns:P1Eco").content = "5"
end
it "completes the log" do
sales_log_service.send(:create_log, sales_log_xml)
sales_log = SalesLog.find_by(old_id: sales_log_id)
expect(sales_log.status).to eq("completed")
end
end
context "and the grant soft validation is triggered (grant_value_check)" do
let(:sales_log_id) { "discounted_ownership_sales_log" }
before do
sales_log_xml.at_xpath("//xmlns:Q32Reductions").content = "5000"
sales_log_xml.at_xpath("//xmlns:CALCMORT").content = "270000"
sales_log_xml.at_xpath("//xmlns:Q33Discount").content = ""
sales_log_xml.at_xpath("//xmlns:DerSaleType").content = "22"
end
it "completes the log" do
sales_log_service.send(:create_log, sales_log_xml)
sales_log = SalesLog.find_by(old_id: sales_log_id)
expect(sales_log.status).to eq("completed")
end
end
context "and the stairbought soft validation is triggered (staircase_bought_value_check)" do
let(:sales_log_id) { "shared_ownership_sales_log" }
before do
sales_log_xml.at_xpath("//xmlns:PercentBought").content = "51"
sales_log_xml.at_xpath("//xmlns:PercentOwns").content = "81"
sales_log_xml.at_xpath("//xmlns:Q17aStaircase").content = "1"
sales_log_xml.at_xpath("//xmlns:Q17Resale").content = ""
sales_log_xml.at_xpath("//xmlns:EXDAY").content = ""
sales_log_xml.at_xpath("//xmlns:EXMONTH").content = ""
sales_log_xml.at_xpath("//xmlns:EXYEAR").content = ""
sales_log_xml.at_xpath("//xmlns:HODAY").content = ""
sales_log_xml.at_xpath("//xmlns:HOMONTH").content = ""
sales_log_xml.at_xpath("//xmlns:HOYEAR").content = ""
end
it "completes the log" do
sales_log_service.send(:create_log, sales_log_xml)
sales_log = SalesLog.find_by(old_id: sales_log_id)
expect(sales_log.status).to eq("completed")
end
end
context "and it has an invalid record with invalid child, student and 16-19 age combination" 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:P2Age").content = 16
sales_log_xml.at_xpath("//xmlns:P2Eco").content = 7
sales_log_xml.at_xpath("//xmlns:P2Rel").content = "X"
end
it "intercepts the relevant validation error" do
expect(logger).to receive(:warn).with(/Removing field age2 from log triggering validation: Person cannot be aged 16-19 if they are a student but don't have relationship ‘child’/)
expect(logger).to receive(:warn).with(/Removing field relat2 from log triggering validation: Answer must be ‘child’ if the person is aged 16-19 and a student/)
expect(logger).to receive(:warn).with(/Removing field ecstat2 from log triggering validation: Person cannot be a student if they are aged 16-19 but don‘t have relationship ‘child’/)
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.age2).to be_nil
expect(sales_log.relat2).to be_nil
expect(sales_log.ecstat2).to be_nil
end
end
context "when inferring default answers for completed sales logs" do context "when inferring default answers for completed sales logs" do
context "when the armedforcesspouse is not answered" do context "when the armedforcesspouse is not answered" do
let(:sales_log_id) { "discounted_ownership_sales_log" } let(:sales_log_id) { "discounted_ownership_sales_log" }

Loading…
Cancel
Save