diff --git a/app/services/imports/sales_logs_import_service.rb b/app/services/imports/sales_logs_import_service.rb index 3593a1227..2db2ee246 100644 --- a/app/services/imports/sales_logs_import_service.rb +++ b/app/services/imports/sales_logs_import_service.rb @@ -76,7 +76,7 @@ module Imports attributes["inc2mort"] = unsafe_string_as_integer(xml_doc, "Q2Person2MortApplication") attributes["hb"] = unsafe_string_as_integer(xml_doc, "Q2a") attributes["frombeds"] = safe_string_as_integer(xml_doc, "Q20Bedrooms") - attributes["staircase"] = unsafe_string_as_integer(xml_doc, "Q17aStaircase") + attributes["staircase"] = unsafe_string_as_integer(xml_doc, "Q17aStaircase") if attributes["ownershipsch"] == 1 attributes["stairbought"] = safe_string_as_integer(xml_doc, "PercentBought") attributes["stairowned"] = safe_string_as_integer(xml_doc, "PercentOwns") if attributes["staircase"] == 1 attributes["mrent"] = safe_string_as_decimal(xml_doc, "Q28MonthlyRent") @@ -102,7 +102,6 @@ module Imports attributes["ppcodenk"] = previous_postcode_known(xml_doc, attributes["ppostcode_full"], attributes["prevloc"]) # Q7UNKNOWNPOSTCODE check mapping attributes["ppostc1"] = string_or_nil(xml_doc, "PPOSTC1") attributes["ppostc2"] = string_or_nil(xml_doc, "PPOSTC2") - attributes["previous_la_known"] = nil attributes["hhregres"] = unsafe_string_as_integer(xml_doc, "ArmedF") attributes["hhregresstill"] = still_serving(xml_doc) attributes["proplen"] = safe_string_as_integer(xml_doc, "Q16aProplen2") || safe_string_as_integer(xml_doc, "Q16aProplensec2") @@ -130,9 +129,8 @@ module Imports attributes["prevshared"] = nil # 23/24 variable attributes["staircasesale"] = nil # 23/24 variable - # Required for our form invalidated questions (not present in import) - attributes["previous_la_known"] = 1 if attributes["prevloc"].present? && attributes["ppostcode_full"].blank? - if attributes["la"].present? && attributes["postcode_full"].blank? + attributes["previous_la_known"] = 1 if attributes["prevloc"].present? + if attributes["la"].present? attributes["la_known"] = 1 attributes["is_la_inferred"] = false end diff --git a/spec/services/imports/sales_logs_import_service_spec.rb b/spec/services/imports/sales_logs_import_service_spec.rb index d2dc4ad94..6ec580839 100644 --- a/spec/services/imports/sales_logs_import_service_spec.rb +++ b/spec/services/imports/sales_logs_import_service_spec.rb @@ -17,14 +17,6 @@ RSpec.describe Imports::SalesLogsImportService do end before do - { "GL519EX" => "E07000078", - "SW1A2AA" => "E09000033", - "SW1A1AA" => "E09000033", - "SW147QP" => "E09000027", - "B955HZ" => "E07000221" }.each do |postcode, district_code| - WebMock.stub_request(:get, /api.postcodes.io\/postcodes\/#{postcode}/).to_return(status: 200, body: "{\"status\":200,\"result\":{\"admin_district\":\"#{district_code}\",\"codes\":{\"admin_district\":\"#{district_code}\"}}}", headers: {}) - end - allow(Organisation).to receive(:find_by).and_return(nil) allow(Organisation).to receive(:find_by).with(old_visible_id: organisation.old_visible_id).and_return(organisation) allow(Organisation).to receive(:find_by).with(old_visible_id: managing_organisation.old_visible_id).and_return(managing_organisation) @@ -799,6 +791,19 @@ RSpec.describe Imports::SalesLogsImportService do expect(sales_log&.ppostcode_full).to eq("GL51 9EX") expect(sales_log&.status).to eq("completed") end + + it "correctly sets location fields for when location cannot be inferred from postcode" do + sales_log_xml.at_xpath("//xmlns:Q14ONSLACode").content = "E07000142" + sales_log_xml.at_xpath("//xmlns:Q14Postcode").content = "A11AA" + 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(0) # postcode known + # expect(sales_log&.is_la_inferred).to eq(nil) + 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 end context "when setting default buyer 1 previous tenancy" do