Browse Source

Set default buy2livein (#1371)

pull/1374/head
kosiakkatrina 2 years ago committed by GitHub
parent
commit
7e4d40cd96
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      app/services/imports/sales_logs_import_service.rb
  2. 76
      spec/services/imports/sales_logs_import_service_spec.rb

1
app/services/imports/sales_logs_import_service.rb

@ -468,6 +468,7 @@ module Imports
attributes["income2nk"] ||= attributes["income2"].present? ? 0 : 1
attributes["relat2"] ||= "R"
attributes["inc2mort"] ||= 3
attributes["buy2livein"] ||= 1 unless attributes["ownershipsch"] == 3
end
# other household members characteristics

76
spec/services/imports/sales_logs_import_service_spec.rb

@ -643,7 +643,7 @@ RSpec.describe Imports::SalesLogsImportService do
allow(logger).to receive(:warn).and_return(nil)
end
it "sets pregblank to true know if no other organisations are selected" do
it "sets pregblank to true 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 = ""
@ -673,6 +673,80 @@ RSpec.describe Imports::SalesLogsImportService do
expect(sales_log&.pregblank).to eq(nil)
end
end
context "when setting default buyer 2 live in for discounted ownership" do
let(:sales_log_id) { "discounted_ownership_sales_log" }
before do
allow(logger).to receive(:warn).and_return(nil)
end
it "sets buy2livein to true if it is joint purchase and it's not answered" 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:LiveInBuyer2").content = ""
sales_log_service.send(:create_log, sales_log_xml)
sales_log = SalesLog.find_by(old_id: sales_log_id)
expect(sales_log&.buy2livein).to eq(1)
end
it "sets buy2livein correctly if it's answered" 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:LiveInBuyer2").content = "1 Yes"
sales_log_service.send(:create_log, sales_log_xml)
sales_log = SalesLog.find_by(old_id: sales_log_id)
expect(sales_log&.buy2livein).to eq(1)
end
end
context "when setting default buyer 2 live in for shared ownership" do
let(:sales_log_id) { "shared_ownership_sales_log" }
before do
allow(logger).to receive(:warn).and_return(nil)
end
it "sets buy2livein to true if it is joint purchase and it's not answered" 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:LiveInBuyer2").content = ""
sales_log_service.send(:create_log, sales_log_xml)
sales_log = SalesLog.find_by(old_id: sales_log_id)
expect(sales_log&.buy2livein).to eq(1)
end
it "sets buy2livein correctly if it's answered" 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:LiveInBuyer2").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&.buy2livein).to eq(2)
end
end
context "when setting default buyer 2 live in for outright sale" do
let(:sales_log_id) { "outright_sale_sales_log" }
before do
allow(logger).to receive(:warn).and_return(nil)
end
it "does not set buy2livein if it is joint purchase and it's not answered" 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:LiveInBuyer2").content = ""
sales_log_service.send(:create_log, sales_log_xml)
sales_log = SalesLog.find_by(old_id: sales_log_id)
expect(sales_log&.buy2livein).to eq(nil)
end
end
end
end
end

Loading…
Cancel
Save