Browse Source

Update tests, clean up import

pull/1331/head
Kat 3 years ago
parent
commit
ae72f4dd74
  1. 27
      app/services/imports/sales_logs_import_service.rb
  2. 14
      spec/services/imports/sales_logs_import_service_spec.rb

27
app/services/imports/sales_logs_import_service.rb

@ -82,7 +82,7 @@ module Imports
attributes["exmonth"] = safe_string_as_integer(xml_doc, "EXMONTH") attributes["exmonth"] = safe_string_as_integer(xml_doc, "EXMONTH")
attributes["exyear"] = safe_string_as_integer(xml_doc, "EXYEAR") attributes["exyear"] = safe_string_as_integer(xml_doc, "EXYEAR")
attributes["resale"] = unsafe_string_as_integer(xml_doc, "Q17Resale") 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["cashdis"] = safe_string_as_decimal(xml_doc, "Q27SocialHomeBuy")
attributes["disabled"] = unsafe_string_as_integer(xml_doc, "Disability") attributes["disabled"] = unsafe_string_as_integer(xml_doc, "Disability")
attributes["lanomagr"] = unsafe_string_as_integer(xml_doc, "Q19Rehoused") attributes["lanomagr"] = unsafe_string_as_integer(xml_doc, "Q19Rehoused")
@ -126,13 +126,11 @@ module Imports
attributes["pcode2"] = string_or_nil(xml_doc, "PCODE2") attributes["pcode2"] = string_or_nil(xml_doc, "PCODE2")
attributes["postcode_full"] = compose_postcode(xml_doc, "PCODE1", "PCODE2") attributes["postcode_full"] = compose_postcode(xml_doc, "PCODE1", "PCODE2")
attributes["pcodenk"] = 0 if attributes["postcode_full"].present? # known if given 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["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) # 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?
@ -154,7 +152,6 @@ module Imports
def save_sales_log(attributes, previous_status) def save_sales_log(attributes, previous_status)
sales_log = SalesLog.new(attributes) sales_log = SalesLog.new(attributes)
binding.pry
begin begin
sales_log.save! sales_log.save!
sales_log sales_log
@ -203,7 +200,8 @@ module Imports
old_persons_shared_ownership_value_check old_persons_shared_ownership_value_check
staircase_bought_value_check staircase_bought_value_check
monthly_charges_value_check monthly_charges_value_check
hodate_check] hodate_check
saledate_check]
end end
def check_status_completed(sales_log, previous_status) def check_status_completed(sales_log, previous_status)
@ -234,14 +232,15 @@ module Imports
end end
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"] case attributes["ownershipsch"]
when 1 when 1
string_or_nil(xml_doc, "Q24aMortgageLender") unsafe_string_as_integer(xml_doc, "Q24aMortgageLender")
when 2 when 2
string_or_nil(xml_doc, "Q34a") unsafe_string_as_integer(xml_doc, "Q34a")
when 3 when 3
string_or_nil(xml_doc, "Q41aMortgageLender") unsafe_string_as_integer(xml_doc, "Q41aMortgageLender")
end end
end end
@ -334,8 +333,6 @@ module Imports
safe_string_as_decimal(xml_doc, "Q29MonthlyCharges") safe_string_as_decimal(xml_doc, "Q29MonthlyCharges")
when 2 when 2
safe_string_as_decimal(xml_doc, "Q37MonthlyCharges") safe_string_as_decimal(xml_doc, "Q37MonthlyCharges")
when 3
#what should this be?
end end
end end
end end

14
spec/services/imports/sales_logs_import_service_spec.rb

@ -16,7 +16,7 @@ RSpec.describe Imports::SalesLogsImportService do
end end
before do 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: {}) .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) 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_service.send(:create_log, sales_log_xml)
sales_log = SalesLog.find_by(old_id: sales_log_id) 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) applicable_questions = sales_log.form.subsections.map { |s| s.applicable_questions(sales_log) }.flatten
expect(applicable_questions.filter { |q| sales_log[q].blank? }).to be_empty expect(applicable_questions.filter { |q| q.unanswered?(sales_log) }.map(&:id)).to be_empty
end end
end end
@ -139,8 +139,8 @@ RSpec.describe Imports::SalesLogsImportService do
sales_log_service.send(:create_log, sales_log_xml) sales_log_service.send(:create_log, sales_log_xml)
sales_log = SalesLog.find_by(old_id: sales_log_id) 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) applicable_questions = sales_log.form.subsections.map { |s| s.applicable_questions(sales_log) }.flatten
expect(applicable_questions.filter { |q| sales_log[q].blank? }).to be_empty expect(applicable_questions.filter { |q| q.unanswered?(sales_log) }.map(&:id)).to be_empty
end end
end end
@ -152,8 +152,8 @@ RSpec.describe Imports::SalesLogsImportService do
sales_log_service.send(:create_log, sales_log_xml) sales_log_service.send(:create_log, sales_log_xml)
sales_log = SalesLog.find_by(old_id: sales_log_id) 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) applicable_questions = sales_log.form.subsections.map { |s| s.applicable_questions(sales_log) }.flatten
expect(applicable_questions.filter { |q| sales_log[q].blank? }).to be_empty expect(applicable_questions.filter { |q| q.unanswered?(sales_log) }.map(&:id)).to be_empty
end end
end end
end end

Loading…
Cancel
Save