diff --git a/app/services/imports/sales_logs_import_service.rb b/app/services/imports/sales_logs_import_service.rb index 7955cbe6e..63cb7ee57 100644 --- a/app/services/imports/sales_logs_import_service.rb +++ b/app/services/imports/sales_logs_import_service.rb @@ -82,7 +82,7 @@ module Imports attributes["exmonth"] = safe_string_as_integer(xml_doc, "EXMONTH") attributes["exyear"] = safe_string_as_integer(xml_doc, "EXYEAR") attributes["resale"] = unsafe_string_as_integer(xml_doc, "Q17Resale") - attributes["deposit"] = deposit(xml_doc, attributes) + attributes["deposit"] = deposit(xml_doc, attributes) attributes["cashdis"] = safe_string_as_decimal(xml_doc, "Q27SocialHomeBuy") attributes["disabled"] = unsafe_string_as_integer(xml_doc, "Disability") attributes["lanomagr"] = unsafe_string_as_integer(xml_doc, "Q19Rehoused") @@ -126,13 +126,11 @@ module Imports attributes["pcode2"] = string_or_nil(xml_doc, "PCODE2") attributes["postcode_full"] = compose_postcode(xml_doc, "PCODE1", "PCODE2") attributes["pcodenk"] = 0 if attributes["postcode_full"].present? # known if given - attributes["bulk_upload_id"] = nil - attributes["saledate_check"] = nil - attributes["ethnic_group2"] = nil - attributes["ethnicbuy2"] = nil - attributes["prevshared"] = nil - attributes["staircasesale"] = nil attributes["soctenant"] = soctenant(attributes) + attributes["ethnic_group2"] = nil # 23/24 variable + attributes["ethnicbuy2"] = nil # 23/24 variable + 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? @@ -154,7 +152,6 @@ module Imports def save_sales_log(attributes, previous_status) sales_log = SalesLog.new(attributes) - binding.pry begin sales_log.save! sales_log @@ -203,7 +200,8 @@ module Imports old_persons_shared_ownership_value_check staircase_bought_value_check monthly_charges_value_check - hodate_check] + hodate_check + saledate_check] end def check_status_completed(sales_log, previous_status) @@ -234,14 +232,15 @@ module Imports end end - def mortgage_lender(xml_doc, attributes) #this comes through as a string, need to map to a corresponding integer + # this comes through as a string, need to map to a corresponding integer + def mortgage_lender(xml_doc, attributes) case attributes["ownershipsch"] when 1 - string_or_nil(xml_doc, "Q24aMortgageLender") + unsafe_string_as_integer(xml_doc, "Q24aMortgageLender") when 2 - string_or_nil(xml_doc, "Q34a") + unsafe_string_as_integer(xml_doc, "Q34a") when 3 - string_or_nil(xml_doc, "Q41aMortgageLender") + unsafe_string_as_integer(xml_doc, "Q41aMortgageLender") end end @@ -334,8 +333,6 @@ module Imports safe_string_as_decimal(xml_doc, "Q29MonthlyCharges") when 2 safe_string_as_decimal(xml_doc, "Q37MonthlyCharges") - when 3 - #what should this be? end end end diff --git a/spec/services/imports/sales_logs_import_service_spec.rb b/spec/services/imports/sales_logs_import_service_spec.rb index 0df00ed50..e34447b37 100644 --- a/spec/services/imports/sales_logs_import_service_spec.rb +++ b/spec/services/imports/sales_logs_import_service_spec.rb @@ -16,7 +16,7 @@ RSpec.describe Imports::SalesLogsImportService do end before do - WebMock.stub_request(:get, /api.postcodes.io\/postcodes\/LS166FT/) + WebMock.stub_request(:get, /api.postcodes.io\/postcodes/) .to_return(status: 200, body: '{"status":200,"result":{"admin_district":"Westminster","codes":{"admin_district":"E08000035"}}}', headers: {}) allow(Organisation).to receive(:find_by).and_return(nil) @@ -126,8 +126,8 @@ RSpec.describe Imports::SalesLogsImportService do sales_log_service.send(:create_log, sales_log_xml) sales_log = SalesLog.find_by(old_id: sales_log_id) - applicable_questions = sales_log.form.subsections.map { |s| s.applicable_questions(sales_log) }.flatten.map(&:id) - expect(applicable_questions.filter { |q| sales_log[q].blank? }).to be_empty + applicable_questions = sales_log.form.subsections.map { |s| s.applicable_questions(sales_log) }.flatten + expect(applicable_questions.filter { |q| q.unanswered?(sales_log) }.map(&:id)).to be_empty end end @@ -139,8 +139,8 @@ RSpec.describe Imports::SalesLogsImportService do sales_log_service.send(:create_log, sales_log_xml) sales_log = SalesLog.find_by(old_id: sales_log_id) - applicable_questions = sales_log.form.subsections.map { |s| s.applicable_questions(sales_log) }.flatten.map(&:id) - expect(applicable_questions.filter { |q| sales_log[q].blank? }).to be_empty + applicable_questions = sales_log.form.subsections.map { |s| s.applicable_questions(sales_log) }.flatten + expect(applicable_questions.filter { |q| q.unanswered?(sales_log) }.map(&:id)).to be_empty end end @@ -152,8 +152,8 @@ RSpec.describe Imports::SalesLogsImportService do sales_log_service.send(:create_log, sales_log_xml) sales_log = SalesLog.find_by(old_id: sales_log_id) - applicable_questions = sales_log.form.subsections.map { |s| s.applicable_questions(sales_log) }.flatten.map(&:id) - expect(applicable_questions.filter { |q| sales_log[q].blank? }).to be_empty + applicable_questions = sales_log.form.subsections.map { |s| s.applicable_questions(sales_log) }.flatten + expect(applicable_questions.filter { |q| q.unanswered?(sales_log) }.map(&:id)).to be_empty end end end