Browse Source

Rounds savings to the nearest 10

pull/1605/head
Kat 3 years ago
parent
commit
dfb6fb429f
  1. 2
      app/services/imports/sales_logs_import_service.rb
  2. 20
      spec/services/imports/sales_logs_import_service_spec.rb

2
app/services/imports/sales_logs_import_service.rb

@ -70,7 +70,7 @@ module Imports
attributes["inc1mort"] = unsafe_string_as_integer(xml_doc, "Q2Person1Mortgage") attributes["inc1mort"] = unsafe_string_as_integer(xml_doc, "Q2Person1Mortgage")
attributes["income2"] = safe_string_as_integer(xml_doc, "Q2Person2Income") attributes["income2"] = safe_string_as_integer(xml_doc, "Q2Person2Income")
attributes["income2nk"] = income_known(unsafe_string_as_integer(xml_doc, "P2IncKnown")) attributes["income2nk"] = income_known(unsafe_string_as_integer(xml_doc, "P2IncKnown"))
attributes["savings"] = safe_string_as_integer(xml_doc, "Q3Savings") attributes["savings"] = safe_string_as_integer(xml_doc, "Q3Savings")&.round(-1)
attributes["savingsnk"] = savings_known(xml_doc) attributes["savingsnk"] = savings_known(xml_doc)
attributes["prevown"] = unsafe_string_as_integer(xml_doc, "Q4PrevOwnedProperty") attributes["prevown"] = unsafe_string_as_integer(xml_doc, "Q4PrevOwnedProperty")
attributes["mortgage"] = safe_string_as_decimal(xml_doc, "CALCMORT") attributes["mortgage"] = safe_string_as_decimal(xml_doc, "CALCMORT")

20
spec/services/imports/sales_logs_import_service_spec.rb

@ -817,6 +817,26 @@ RSpec.describe Imports::SalesLogsImportService do
end end
end end
context "when the savings is given not to the nearest 10" do
let(:sales_log_id) { "discounted_ownership_sales_log" }
before do
sales_log_xml.at_xpath("//xmlns:Q3Savings").content = "10013"
allow(logger).to receive(:warn).and_return(nil)
end
it "does not error" do
expect { sales_log_service.send(:create_log, sales_log_xml) }.not_to raise_error
end
it "sets savings to the nearest 10" do
sales_log_service.send(:create_log, sales_log_xml)
sales_log = SalesLog.find_by(old_id: sales_log_id)
expect(sales_log&.savings).to be(10_010)
end
end
context "when inferring age known" do context "when inferring age known" do
let(:sales_log_id) { "discounted_ownership_sales_log" } let(:sales_log_id) { "discounted_ownership_sales_log" }

Loading…
Cancel
Save