Browse Source

Set default income used and pregblank

pull/1353/head
Kat 3 years ago
parent
commit
2e9bf368ea
  1. 6
      app/services/imports/sales_logs_import_service.rb
  2. 68
      spec/services/imports/sales_logs_import_service_spec.rb

6
app/services/imports/sales_logs_import_service.rb

@ -419,7 +419,10 @@ module Imports
attributes["prevown"] ||= 3 attributes["prevown"] ||= 3
attributes["savingsnk"] ||= attributes["savings"].present? ? 0 : 1 attributes["savingsnk"] ||= attributes["savings"].present? ? 0 : 1
attributes["jointmore"] ||= 3 if attributes["jointpur"] == 1 attributes["jointmore"] ||= 3 if attributes["jointpur"] == 1
# attributes["noint"] = 1 # not interviewed attributes["inc1mort"] ||= 3
if [attributes["pregyrha"], attributes["pregla"], attributes["pregghb"], attributes["pregother"]].all?(&:blank?)
attributes["pregblank"] = 1
end
# buyer 1 characteristics # buyer 1 characteristics
attributes["age1_known"] ||= 1 attributes["age1_known"] ||= 1
@ -438,6 +441,7 @@ module Imports
attributes["ecstat2"] ||= 10 attributes["ecstat2"] ||= 10
attributes["income2nk"] ||= attributes["income2"].present? ? 0 : 1 attributes["income2nk"] ||= attributes["income2"].present? ? 0 : 1
attributes["relat2"] ||= "R" attributes["relat2"] ||= "R"
attributes["inc2mort"] ||= 3
end end
# other household members characteristics # other household members characteristics

68
spec/services/imports/sales_logs_import_service_spec.rb

@ -578,6 +578,74 @@ RSpec.describe Imports::SalesLogsImportService do
expect(sales_log&.hholdcount).to eq(0) expect(sales_log&.hholdcount).to eq(0)
end end
end end
context "when inferring income used" do
let(:sales_log_id) { "discounted_ownership_sales_log" }
before do
allow(logger).to receive(:warn).and_return(nil)
end
it "sets inc1mort and inc2mort to don't know if not answered" do
sales_log_xml.at_xpath("//xmlns:joint").content = "1 Yes"
sales_log_xml.at_xpath("//xmlns:Q2Person1Mortgage").content = ""
sales_log_xml.at_xpath("//xmlns:Q2Person2MortApplication").content = ""
sales_log_service.send(:create_log, sales_log_xml)
sales_log = SalesLog.find_by(old_id: sales_log_id)
expect(sales_log&.inc1mort).to eq(3)
expect(sales_log&.inc2mort).to eq(3)
end
it "sets inc1mort and inc2mort correctly if answered" do
sales_log_xml.at_xpath("//xmlns:joint").content = "1 Yes"
sales_log_xml.at_xpath("//xmlns:Q2Person1Mortgage").content = "1 Yes"
sales_log_xml.at_xpath("//xmlns:Q2Person2MortApplication").content = "2 No"
sales_log_service.send(:create_log, sales_log_xml)
sales_log = SalesLog.find_by(old_id: sales_log_id)
expect(sales_log&.inc1mort).to eq(1)
expect(sales_log&.inc2mort).to eq(2)
end
end
context "when inferring buyer organisation" do
let(:sales_log_id) { "discounted_ownership_sales_log" }
before do
allow(logger).to receive(:warn).and_return(nil)
end
it "sets pregblank to true know if no other organisations are selected" do
sales_log_xml.at_xpath("//xmlns:PREGYRHA").content = ""
sales_log_xml.at_xpath("//xmlns:PREGLA").content = ""
sales_log_xml.at_xpath("//xmlns:PREGHBA").content = ""
sales_log_xml.at_xpath("//xmlns:PREGOTHER").content = ""
sales_log_service.send(:create_log, sales_log_xml)
sales_log = SalesLog.find_by(old_id: sales_log_id)
expect(sales_log&.pregyrha).to eq(nil)
expect(sales_log&.pregla).to eq(nil)
expect(sales_log&.pregghb).to eq(nil)
expect(sales_log&.pregother).to eq(nil)
expect(sales_log&.pregblank).to eq(1)
end
it "sets pregblank and other organisation fields correctly if answered" do
sales_log_xml.at_xpath("//xmlns:PREGYRHA").content = "Yes"
sales_log_xml.at_xpath("//xmlns:PREGLA").content = "Yes"
sales_log_xml.at_xpath("//xmlns:PREGHBA").content = "Yes"
sales_log_xml.at_xpath("//xmlns:PREGOTHER").content = "Yes"
sales_log_service.send(:create_log, sales_log_xml)
sales_log = SalesLog.find_by(old_id: sales_log_id)
expect(sales_log&.pregyrha).to eq(1)
expect(sales_log&.pregla).to eq(1)
expect(sales_log&.pregghb).to eq(1)
expect(sales_log&.pregother).to eq(1)
expect(sales_log&.pregblank).to eq(nil)
end
end
end end
end end
end end

Loading…
Cancel
Save