Browse Source

Set income and savings not known for in progress logs (#1911)

pull/1914/head
kosiakkatrina 1 year ago committed by GitHub
parent
commit
3da6416950
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      app/services/imports/sales_logs_import_service.rb
  2. 67
      spec/services/imports/sales_logs_import_service_spec.rb

3
app/services/imports/sales_logs_import_service.rb

@ -68,11 +68,14 @@ module Imports
attributes["la"] = string_or_nil(xml_doc, "Q14ONSLACode")
attributes["income1"] = safe_string_as_integer(xml_doc, "Q2Person1Income")
attributes["income1nk"] = income_known(unsafe_string_as_integer(xml_doc, "P1IncKnown"))
attributes["income1nk"] ||= 0 if attributes["income1"].present?
attributes["inc1mort"] = unsafe_string_as_integer(xml_doc, "Q2Person1Mortgage")
attributes["income2"] = safe_string_as_integer(xml_doc, "Q2Person2Income")
attributes["income2nk"] = income_known(unsafe_string_as_integer(xml_doc, "P2IncKnown"))
attributes["income2nk"] ||= 0 if attributes["income2"].present?
attributes["savings"] = safe_string_as_integer(xml_doc, "Q3Savings")&.round(-1)
attributes["savingsnk"] = savings_known(xml_doc)
attributes["savingsnk"] ||= 0 if attributes["savings"].present?
attributes["prevown"] = unsafe_string_as_integer(xml_doc, "Q4PrevOwnedProperty")
attributes["mortgage"] = safe_string_as_decimal(xml_doc, "CALCMORT")
attributes["inc2mort"] = unsafe_string_as_integer(xml_doc, "Q2Person2MortApplication")

67
spec/services/imports/sales_logs_import_service_spec.rb

@ -2200,5 +2200,72 @@ RSpec.describe Imports::SalesLogsImportService do
end
end
end
context "when setting income for in progress logs" do
let(:sales_log_id) { "shared_ownership_sales_log" }
before do
sales_log_xml.at_xpath("//meta:status").content = "saved"
end
it "sets income to known if not answered but income is given for person 1" do
sales_log_xml.at_xpath("//xmlns:joint").content = "2 No"
sales_log_xml.at_xpath("//xmlns:P1IncKnown").content = ""
sales_log_xml.at_xpath("//xmlns:Q2Person1Income").content = "20000"
sales_log_xml.at_xpath("//xmlns:P2IncKnown").content = ""
sales_log_xml.at_xpath("//xmlns:Q2Person2Income").content = "30000"
sales_log_service.send(:create_log, sales_log_xml)
sales_log = SalesLog.find_by(old_id: sales_log_id)
expect(sales_log&.income1nk).to eq(0)
expect(sales_log&.income1).to eq(20_000)
expect(sales_log&.income2nk).to eq(nil)
expect(sales_log&.income2).to eq(nil)
end
it "sets income to known if not answered but income is given for person 2" do
sales_log_xml.at_xpath("//xmlns:joint").content = "1 Yes"
sales_log_xml.at_xpath("//xmlns:JointMore").content = "2 No"
sales_log_xml.at_xpath("//xmlns:P1IncKnown").content = ""
sales_log_xml.at_xpath("//xmlns:Q2Person1Income").content = "20000"
sales_log_xml.at_xpath("//xmlns:P2IncKnown").content = ""
sales_log_xml.at_xpath("//xmlns:Q2Person2Income").content = "30000"
sales_log_service.send(:create_log, sales_log_xml)
sales_log = SalesLog.find_by(old_id: sales_log_id)
expect(sales_log&.income1nk).to eq(0)
expect(sales_log&.income1).to eq(20_000)
expect(sales_log&.income2nk).to eq(0)
expect(sales_log&.income2).to eq(30_000)
end
it "sets savings to known if savings are given" do
sales_log_xml.at_xpath("//xmlns:Q3Savings").content = "10000"
sales_log_xml.at_xpath("//xmlns:savingsKnown").content = ""
sales_log_service.send(:create_log, sales_log_xml)
sales_log = SalesLog.find_by(old_id: sales_log_id)
expect(sales_log&.savingsnk).to eq(0)
expect(sales_log&.savings).to eq(10_000)
end
it "does not set savings or income fields when values aren't given" do
sales_log_xml.at_xpath("//xmlns:P1IncKnown").content = ""
sales_log_xml.at_xpath("//xmlns:Q2Person1Income").content = ""
sales_log_xml.at_xpath("//xmlns:P2IncKnown").content = ""
sales_log_xml.at_xpath("//xmlns:Q2Person2Income").content = ""
sales_log_xml.at_xpath("//xmlns:Q3Savings").content = ""
sales_log_xml.at_xpath("//xmlns:savingsKnown").content = ""
sales_log_service.send(:create_log, sales_log_xml)
sales_log = SalesLog.find_by(old_id: sales_log_id)
expect(sales_log&.income1nk).to eq(nil)
expect(sales_log&.income1).to eq(nil)
expect(sales_log&.income2nk).to eq(nil)
expect(sales_log&.income2).to eq(nil)
expect(sales_log&.savingsnk).to eq(nil)
expect(sales_log&.savings).to eq(nil)
end
end
end
end

Loading…
Cancel
Save