Browse Source

Fix location import

pull/1375/head
Kat 3 years ago
parent
commit
78f06fe1cf
  1. 6
      app/services/imports/sales_logs_import_service.rb
  2. 37
      spec/services/imports/sales_logs_import_service_spec.rb

6
app/services/imports/sales_logs_import_service.rb

@ -134,7 +134,10 @@ module Imports
# Required for our form invalidated questions (not present in import) # Required for our form invalidated questions (not present in import)
attributes["previous_la_known"] = 1 if attributes["prevloc"].present? && attributes["ppostcode_full"].blank? attributes["previous_la_known"] = 1 if attributes["prevloc"].present? && attributes["ppostcode_full"].blank?
attributes["la_known"] = 1 if attributes["la"].present? && attributes["postcode_full"].blank? if attributes["la"].present? && attributes["postcode_full"].blank?
attributes["la_known"] = 1
attributes["is_la_inferred"] = false
end
# 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
@ -452,6 +455,7 @@ module Imports
if [attributes["pregyrha"], attributes["pregla"], attributes["pregghb"], attributes["pregother"]].all?(&:blank?) if [attributes["pregyrha"], attributes["pregla"], attributes["pregghb"], attributes["pregother"]].all?(&:blank?)
attributes["pregblank"] = 1 attributes["pregblank"] = 1
end end
attributes["pcodenk"] ||= 1
# buyer 1 characteristics # buyer 1 characteristics
attributes["age1_known"] ||= 1 attributes["age1_known"] ||= 1

37
spec/services/imports/sales_logs_import_service_spec.rb

@ -754,6 +754,43 @@ RSpec.describe Imports::SalesLogsImportService do
expect(sales_log&.buy2livein).to eq(nil) expect(sales_log&.buy2livein).to eq(nil)
end end
end end
context "when setting location fields" do
let(:sales_log_id) { "outright_sale_sales_log" }
before do
allow(logger).to receive(:warn).and_return(nil)
end
it "correctly sets LA if postcode is not given" do
sales_log_xml.at_xpath("//xmlns:Q14ONSLACode").content = "E07000142"
sales_log_xml.at_xpath("//xmlns:PCODE1").content = ""
sales_log_xml.at_xpath("//xmlns:PCODE2").content = ""
sales_log_service.send(:create_log, sales_log_xml)
sales_log = SalesLog.find_by(old_id: sales_log_id)
expect(sales_log&.pcodenk).to eq(1) # postcode not known
expect(sales_log&.is_la_inferred).to eq(false)
expect(sales_log&.la_known).to eq(1) # la known
expect(sales_log&.la).to eq("E07000142")
expect(sales_log&.status).to eq("completed")
end
it "correctly sets previous LA if postcode is not given" do
sales_log_xml.at_xpath("//xmlns:Q7ONSLACode").content = "E07000142"
sales_log_xml.at_xpath("//xmlns:PPOSTC1").content = ""
sales_log_xml.at_xpath("//xmlns:PPOSTC2").content = ""
sales_log_xml.at_xpath("//xmlns:Q7UnknownPostcode").content = ""
sales_log_service.send(:create_log, sales_log_xml)
sales_log = SalesLog.find_by(old_id: sales_log_id)
expect(sales_log&.ppcodenk).to eq(1) # previous postcode not known
expect(sales_log&.is_previous_la_inferred).to eq(false)
expect(sales_log&.previous_la_known).to eq(1) # la known
expect(sales_log&.prevloc).to eq("E07000142")
expect(sales_log&.status).to eq("completed")
end
end
end end
end end
end end

Loading…
Cancel
Save