From fb6d25b33c233dcaceda0e3506a1a14187e518c9 Mon Sep 17 00:00:00 2001 From: kosiakkatrina <54268893+kosiakkatrina@users.noreply.github.com> Date: Thu, 2 Mar 2023 09:28:39 +0000 Subject: [PATCH] CLDC-1938 Import relevant logs in sales and lettings log import (#1353) * Only process sales logs in sales import job * Only process lettings logs in lettings import job * Add sales log import task to the full import * change review app import bucket name * Update mortgageused and joinmore * Update jointmore and ownership scheme * Fix ownershipsch so that it doesn't override to nil * Set default relat2, update default household count * het ownership from type if not given * Improve logging * Remove mortgageused method * Look at Q16aProplensec2 column if Q16aProplen2 is empty * Set default income used and pregblank * Remove fields calculated internally * Comment out sales import from full import task * typo and change bucket name --- .../imports/lettings_logs_import_service.rb | 2 + .../imports/sales_logs_import_service.rb | 40 +- lib/tasks/full_import.rake | 1 + .../logs/shared_ownership_sales_log.xml | 333 +++++++++++ .../imports/sales_logs/lettings_log.xml | 524 ++++++++++++++++++ spec/lib/tasks/full_import_spec.rb | 4 + .../lettings_logs_import_service_spec.rb | 6 +- .../imports/sales_logs_import_service_spec.rb | 73 ++- 8 files changed, 970 insertions(+), 13 deletions(-) create mode 100644 spec/fixtures/imports/logs/shared_ownership_sales_log.xml create mode 100644 spec/fixtures/imports/sales_logs/lettings_log.xml diff --git a/app/services/imports/lettings_logs_import_service.rb b/app/services/imports/lettings_logs_import_service.rb index 3aa73db4b..34582091d 100644 --- a/app/services/imports/lettings_logs_import_service.rb +++ b/app/services/imports/lettings_logs_import_service.rb @@ -55,6 +55,8 @@ module Imports }.freeze def create_log(xml_doc) + return if meta_field_value(xml_doc, "form-name").include?("Sales") + attributes = {} previous_status = meta_field_value(xml_doc, "status") diff --git a/app/services/imports/sales_logs_import_service.rb b/app/services/imports/sales_logs_import_service.rb index deea3fab6..b8fa80453 100644 --- a/app/services/imports/sales_logs_import_service.rb +++ b/app/services/imports/sales_logs_import_service.rb @@ -16,6 +16,8 @@ module Imports private def create_log(xml_doc) + return unless meta_field_value(xml_doc, "form-name").include?("Sales") + attributes = {} previous_status = meta_field_value(xml_doc, "status") @@ -31,9 +33,10 @@ module Imports attributes["updated_at"] = Time.zone.parse(meta_field_value(xml_doc, "modified-date")) attributes["purchid"] = string_or_nil(xml_doc, "PurchaserCode") attributes["ownershipsch"] = unsafe_string_as_integer(xml_doc, "Ownership") + attributes["ownershipsch"] = ownership_from_type(attributes) if attributes["ownershipsch"].blank? # sometimes Ownership is missing, but type is set attributes["othtype"] = string_or_nil(xml_doc, "Q38OtherSale") - attributes["jointmore"] = unsafe_string_as_integer(xml_doc, "JointMore") attributes["jointpur"] = unsafe_string_as_integer(xml_doc, "joint") + attributes["jointmore"] = unsafe_string_as_integer(xml_doc, "JointMore") if attributes["jointpur"] == 1 attributes["beds"] = safe_string_as_integer(xml_doc, "Q11Bedrooms") attributes["companybuy"] = unsafe_string_as_integer(xml_doc, "company") if attributes["ownershipsch"] == 3 attributes["hhmemb"] = safe_string_as_integer(xml_doc, "HHMEMB") @@ -102,10 +105,12 @@ module Imports 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") + attributes["proplen"] = safe_string_as_integer(xml_doc, "Q16aProplen2") || safe_string_as_integer(xml_doc, "Q16aProplensec2") attributes["mscharge"] = monthly_charges(xml_doc, attributes) attributes["mscharge_known"] = 1 if attributes["mscharge"].present? attributes["prevten"] = unsafe_string_as_integer(xml_doc, "Q6PrevTenure") + attributes["mortlen"] = mortgage_length(xml_doc, attributes) + attributes["extrabor"] = borrowing(xml_doc, attributes) attributes["mortgageused"] = unsafe_string_as_integer(xml_doc, "MORTGAGEUSED") attributes["wchair"] = unsafe_string_as_integer(xml_doc, "Q15Wheelchair") attributes["armedforcesspouse"] = unsafe_string_as_integer(xml_doc, "ARMEDFORCESSPOUSE") @@ -117,11 +122,6 @@ module Imports attributes["socprevten"] = unsafe_string_as_integer(xml_doc, "PrevRentType") attributes["mortgagelender"] = mortgage_lender(xml_doc, attributes) attributes["mortgagelenderother"] = mortgage_lender_other(xml_doc, attributes) - attributes["mortlen"] = mortgage_length(xml_doc, attributes) - attributes["extrabor"] = borrowing(xml_doc, attributes) - attributes["totadult"] = safe_string_as_integer(xml_doc, "TOTADULT") # would get overridden - attributes["totchild"] = safe_string_as_integer(xml_doc, "TOTCHILD") # would get overridden - attributes["hhtype"] = unsafe_string_as_integer(xml_doc, "HHTYPE") attributes["pcode1"] = string_or_nil(xml_doc, "PCODE1") attributes["pcode2"] = string_or_nil(xml_doc, "PCODE2") attributes["postcode_full"] = compose_postcode(xml_doc, "PCODE1", "PCODE2") @@ -396,6 +396,17 @@ module Imports end end + def ownership_from_type(attributes) + case attributes["type"] + when 2, 24, 18, 16, 28, 31, 30 + 1 # shared ownership + when 8, 14, 27, 9, 29, 21, 22 + 2 # discounted ownership + when 10, 12 + 3 # outright sale + end + end + def set_default_values(attributes) attributes["armedforcesspouse"] ||= 7 attributes["hhregres"] ||= 8 @@ -404,7 +415,11 @@ module Imports attributes["hb"] ||= 4 attributes["prevown"] ||= 3 attributes["savingsnk"] ||= attributes["savings"].present? ? 0 : 1 - # attributes["noint"] = 1 # not interviewed + attributes["jointmore"] ||= 3 if attributes["jointpur"] == 1 + attributes["inc1mort"] ||= 3 + if [attributes["pregyrha"], attributes["pregla"], attributes["pregghb"], attributes["pregother"]].all?(&:blank?) + attributes["pregblank"] = 1 + end # buyer 1 characteristics attributes["age1_known"] ||= 1 @@ -422,6 +437,8 @@ module Imports attributes["sex2"] ||= "R" attributes["ecstat2"] ||= 10 attributes["income2nk"] ||= attributes["income2"].present? ? 0 : 1 + attributes["relat2"] ||= "R" + attributes["inc2mort"] ||= 3 end # other household members characteristics @@ -434,15 +451,16 @@ module Imports end def missing_answers(sales_log) - applicable_questions = sales_log.form.subsections.map { |s| s.applicable_questions(sales_log) }.flatten + applicable_questions = sales_log.form.subsections.map { |s| s.applicable_questions(sales_log).select { |q| q.enabled?(sales_log) } }.flatten applicable_questions.filter { |q| q.unanswered?(sales_log) }.map(&:id) end - # just for testing, logic might need to change + # just for testing, logic will need to change to match the number of people details known def default_household_count(attributes) return 0 if attributes["hhmemb"].zero? || attributes["hhmemb"].blank? - attributes["jointpur"] == 1 ? attributes["hhmemb"] - 2 : attributes["hhmemb"] - 1 + household_count = attributes["jointpur"] == 1 ? attributes["hhmemb"] - 2 : attributes["hhmemb"] - 1 + household_count.positive? ? household_count : 0 end end end diff --git a/lib/tasks/full_import.rake b/lib/tasks/full_import.rake index e141b6520..35943db2d 100644 --- a/lib/tasks/full_import.rake +++ b/lib/tasks/full_import.rake @@ -18,6 +18,7 @@ namespace :core do Import.new(Imports::DataProtectionConfirmationImportService, :create_data_protection_confirmations, "dataprotect"), Import.new(Imports::OrganisationRentPeriodImportService, :create_organisation_rent_periods, "rent-period"), Import.new(Imports::LettingsLogsImportService, :create_logs, "logs"), + # Import.new(Imports::SalesLogsImportService, :create_logs, "logs"), ] import_list.each do |step| diff --git a/spec/fixtures/imports/logs/shared_ownership_sales_log.xml b/spec/fixtures/imports/logs/shared_ownership_sales_log.xml new file mode 100644 index 000000000..6e0c11174 --- /dev/null +++ b/spec/fixtures/imports/logs/shared_ownership_sales_log.xml @@ -0,0 +1,333 @@ + + + 2022-CORE-Sales + shared_ownership_sales_log + c3061a2e6ea0b702e6f6210d5c52d2a92612d2aa + 7c5bd5fb549c09a2c55d7cb90d7ba84927e64618 + 7c5bd5fb549c09a2c55d7cb90d7ba84927e64618 + 2023-02-21T11:48:28.255968Z + 2023-02-22T11:00:06.575832Z + submitted-valid + 2022 + Manual Entry + + + + + Yes + 2023-01-17 + Shared ownership example + 1 Yes - a shared ownership scheme + 2 Shared Ownership + + + + 2 No + 1 Yes + 2 No + + 2 Yes + + + 2 + 1 Flat or maisonette + 1 Purpose built + SW1A 1AA + Westminster + E09000033 + 3 Don’t know + + + 30 + Male + 1 Full Time - 30 hours or more a week + 2 White: Irish + 18 United Kingdom + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1 Yes + + + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 76000 + 1 + 47000 + 0 + 235000 + 0 +
300204
+
+ + + + + + + + + + + + + + + + + + + + + + + + 1 + 0 + 0 + 1 + 1 + 2 + 3 + 17 + 1 + 2023 + 6 + 9 + 2022 + 8 + 1 + 2023 + SW14 + 7QP + SW1A + 1AA + + + + 2 Private registered provider (PRP) or housing association tenant + SW14 7QP + + Richmond-upon-Thames + E09000027 + Yes + + + + + + + 8 Don’t know + + + 2 No + 2 No + + + 1 Yes + 47000 + 1 Yes + + + + 4 Don’t know + 1 Yes + 89000 + 1 Yes + + + + + 1 + 2 No + + 30 + 2 No + 2023-01-08 + 2022-09-06 + 2 No + + + + 550000 + 30 + 1 Yes + 76000 + Nationwide + 33 + 2 No + 89000 + + 912.00 + 134.24 + + + + + + + + + + + + + + + + + + + + + + + + + 1 + 1 + 0 + + + 3 = 1 adult + + + 2 Shared Ownership + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + + + + + E12000007 + 1 + 1 Test + 655 + +
diff --git a/spec/fixtures/imports/sales_logs/lettings_log.xml b/spec/fixtures/imports/sales_logs/lettings_log.xml new file mode 100644 index 000000000..1f7f794f6 --- /dev/null +++ b/spec/fixtures/imports/sales_logs/lettings_log.xml @@ -0,0 +1,524 @@ + + + 2021-CORE-SR-SH + lettings_log + c3061a2e6ea0b702e6f6210d5c52d2a92612d2aa + 7c5bd5fb549c09z2c55d9cb90d7ba84927e64618 + 7c5bd5fb549c09z2c55d9cb90d7ba84927e64618 + 2022-01-05T12:50:20.39153Z + 2022-01-05T12:50:20.39153Z + submitted-valid + 2021 + Manual Entry + + + + + Yes + 2021-11-05 +
123456
+ 2 Local Authority + + <_1cmangroupcode>0123 + <_1cschemecode>10 + + 3 No + +
+ + <_2a>2 No + 1 Secure (inc flexible) + + <_2bTenCode>14044912001 + <_2cYears>2 + + + 72 + + Female + 5) Retired + 1 White: English/Scottish/Welsh/Northern Irish/British + 1 UK national resident in UK + 74 + + Male + Partner + 5) Retired + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 2 No + + + 2 No + + + 9 Not in receipt of either UC or HB + + + 2 Some + Refused + + + + + 13 Property unsuitable because of ill health / disability + + + + <_9b override-field="">2 No + + + + + Yes + + 1 Yes + + + Yes + + + + + + + + 26 Owner occupation (private) + DLUHC + E08000035 + S80 4DJ + + 5 5 years or more + 9 3 years but under 4 years + + + 1 Not homeless + 2 No + + + + + + + + 1 Yes + 1 Yes + 1 Yes + + + 2 Tenant applied direct (no referral or nomination) + + + + 7 Weekly for 48 weeks + 125.00 + + + 7.00 + 132.00 + + + + + 2021-08-24 + + + 0 + 14044912 + + + 1 Yes + 15 First let of newbuild property + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + <_100>0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + <_70>1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 1 + 1 + 2 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 2 + 74 + 0 + 0 + 0 + 0 + 0 + 0 + 74 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 72 + 0 + 74 + 2022-01-05Z + 2022-01-20Z + + + + + + + + + + + + + 0 + 0 + 0 + 0 + 20 + 0 + 20 + A + 1 + 1 + 1 + 1 + 4 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + 0.00 + 2 + 1 New Tenant + + 73 + 2 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 1 + 2 = 2 Adults at least one is an Elder + + + 15.00 + + + 2 Local Authority + + + E12000004 + 1 + DLUHC + DLUHC + N/A + N/A + + 2 + false + + + + + + + + + + + + + + + 15 + 15 + 000001005048 + D + 15 + 6 + 7 + 1 + 2 + A + P + M + + DLUHC + E08000035 + S80 4QE + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + 115.38 + 121.85 + + + 6.46 + + 115.38 + 121.85 + + + 6.46 + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + + 115.38 + 0 + + 0 + 117.4 + 10 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 5 + 11 + 2021 + 24 + 8 + 2021 + + + + LS16 + 6FT + LS16 + 6FT + +
diff --git a/spec/lib/tasks/full_import_spec.rb b/spec/lib/tasks/full_import_spec.rb index a735db40d..67e8ca715 100644 --- a/spec/lib/tasks/full_import_spec.rb +++ b/spec/lib/tasks/full_import_spec.rb @@ -22,6 +22,7 @@ describe "rake core:full_import", type: :task do context "when starting a full import" do let(:lettings_logs_service) { instance_double(Imports::LettingsLogsImportService) } + let(:sales_logs_service) { instance_double(Imports::SalesLogsImportService) } let(:rent_period_service) { instance_double(Imports::OrganisationRentPeriodImportService) } let(:data_protection_service) { instance_double(Imports::DataProtectionConfirmationImportService) } let(:user_service) { instance_double(Imports::UserImportService) } @@ -37,6 +38,7 @@ describe "rake core:full_import", type: :task do allow(Imports::DataProtectionConfirmationImportService).to receive(:new).and_return(data_protection_service) allow(Imports::OrganisationRentPeriodImportService).to receive(:new).and_return(rent_period_service) allow(Imports::LettingsLogsImportService).to receive(:new).and_return(lettings_logs_service) + allow(Imports::SalesLogsImportService).to receive(:new).and_return(sales_logs_service) end it "raises an exception if no parameters are provided" do @@ -54,6 +56,7 @@ describe "rake core:full_import", type: :task do expect(data_protection_service).to receive(:create_data_protection_confirmations).with("dataprotect") expect(rent_period_service).to receive(:create_organisation_rent_periods).with("rent-period") expect(lettings_logs_service).to receive(:create_logs).with("logs") + # expect(sales_logs_service).to receive(:create_logs).with("logs") task.invoke(fixture_path) end @@ -73,6 +76,7 @@ describe "rake core:full_import", type: :task do expect(data_protection_service).to receive(:create_data_protection_confirmations) expect(rent_period_service).to receive(:create_organisation_rent_periods) expect(lettings_logs_service).to receive(:create_logs) + # expect(sales_logs_service).to receive(:create_logs) expect(scheme_service).not_to receive(:create_schemes) expect(location_service).not_to receive(:create_scheme_locations) diff --git a/spec/services/imports/lettings_logs_import_service_spec.rb b/spec/services/imports/lettings_logs_import_service_spec.rb index be650c484..846c266a5 100644 --- a/spec/services/imports/lettings_logs_import_service_spec.rb +++ b/spec/services/imports/lettings_logs_import_service_spec.rb @@ -47,11 +47,12 @@ RSpec.describe Imports::LettingsLogsImportService do let(:lettings_log_id2) { "166fc004-392e-47a8-acb8-1c018734882b" } let(:lettings_log_id3) { "00d2343e-d5fa-4c89-8400-ec3854b0f2b4" } let(:lettings_log_id4) { "0b4a68df-30cc-474a-93c0-a56ce8fdad3b" } + let(:sales_log) { "shared_ownership_sales_log" } before do # Stub the S3 file listing and download allow(storage_service).to receive(:list_files) - .and_return(%W[#{remote_folder}/#{lettings_log_id}.xml #{remote_folder}/#{lettings_log_id2}.xml #{remote_folder}/#{lettings_log_id3}.xml #{remote_folder}/#{lettings_log_id4}.xml]) + .and_return(%W[#{remote_folder}/#{lettings_log_id}.xml #{remote_folder}/#{lettings_log_id2}.xml #{remote_folder}/#{lettings_log_id3}.xml #{remote_folder}/#{lettings_log_id4}.xml #{remote_folder}/#{sales_log}.xml]) allow(storage_service).to receive(:get_file_io) .with("#{remote_folder}/#{lettings_log_id}.xml") .and_return(open_file(fixture_directory, lettings_log_id), open_file(fixture_directory, lettings_log_id)) @@ -64,6 +65,9 @@ RSpec.describe Imports::LettingsLogsImportService do allow(storage_service).to receive(:get_file_io) .with("#{remote_folder}/#{lettings_log_id4}.xml") .and_return(open_file(fixture_directory, lettings_log_id4), open_file(fixture_directory, lettings_log_id4)) + allow(storage_service).to receive(:get_file_io) + .with("#{remote_folder}/#{sales_log}.xml") + .and_return(open_file(fixture_directory, sales_log), open_file(fixture_directory, sales_log)) end it "successfully create all lettings logs" do diff --git a/spec/services/imports/sales_logs_import_service_spec.rb b/spec/services/imports/sales_logs_import_service_spec.rb index f57e2f3be..bb51b9ad3 100644 --- a/spec/services/imports/sales_logs_import_service_spec.rb +++ b/spec/services/imports/sales_logs_import_service_spec.rb @@ -38,7 +38,7 @@ RSpec.describe Imports::SalesLogsImportService do before do # Stub the S3 file listing and download allow(storage_service).to receive(:list_files) - .and_return(%W[#{remote_folder}/shared_ownership_sales_log.xml #{remote_folder}/shared_ownership_sales_log2.xml #{remote_folder}/outright_sale_sales_log.xml #{remote_folder}/discounted_ownership_sales_log.xml]) + .and_return(%W[#{remote_folder}/shared_ownership_sales_log.xml #{remote_folder}/shared_ownership_sales_log2.xml #{remote_folder}/outright_sale_sales_log.xml #{remote_folder}/discounted_ownership_sales_log.xml #{remote_folder}/lettings_log.xml]) allow(storage_service).to receive(:get_file_io) .with("#{remote_folder}/shared_ownership_sales_log.xml") .and_return(open_file(fixture_directory, "shared_ownership_sales_log"), open_file(fixture_directory, "shared_ownership_sales_log")) @@ -51,6 +51,9 @@ RSpec.describe Imports::SalesLogsImportService do allow(storage_service).to receive(:get_file_io) .with("#{remote_folder}/discounted_ownership_sales_log.xml") .and_return(open_file(fixture_directory, "discounted_ownership_sales_log"), open_file(fixture_directory, "discounted_ownership_sales_log")) + allow(storage_service).to receive(:get_file_io) + .with("#{remote_folder}/lettings_log.xml") + .and_return(open_file(fixture_directory, "lettings_log"), open_file(fixture_directory, "lettings_log")) end it "successfully creates all sales logs" do @@ -575,6 +578,74 @@ RSpec.describe Imports::SalesLogsImportService do expect(sales_log&.hholdcount).to eq(0) end end + + context "when inferring income used" do + let(:sales_log_id) { "discounted_ownership_sales_log" } + + before do + allow(logger).to receive(:warn).and_return(nil) + end + + it "sets inc1mort and inc2mort to don't know if not answered" do + sales_log_xml.at_xpath("//xmlns:joint").content = "1 Yes" + sales_log_xml.at_xpath("//xmlns:Q2Person1Mortgage").content = "" + sales_log_xml.at_xpath("//xmlns:Q2Person2MortApplication").content = "" + sales_log_service.send(:create_log, sales_log_xml) + + sales_log = SalesLog.find_by(old_id: sales_log_id) + expect(sales_log&.inc1mort).to eq(3) + expect(sales_log&.inc2mort).to eq(3) + end + + it "sets inc1mort and inc2mort correctly if answered" do + sales_log_xml.at_xpath("//xmlns:joint").content = "1 Yes" + sales_log_xml.at_xpath("//xmlns:Q2Person1Mortgage").content = "1 Yes" + sales_log_xml.at_xpath("//xmlns:Q2Person2MortApplication").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&.inc1mort).to eq(1) + expect(sales_log&.inc2mort).to eq(2) + end + end + + context "when inferring buyer organisation" do + let(:sales_log_id) { "discounted_ownership_sales_log" } + + before do + allow(logger).to receive(:warn).and_return(nil) + end + + it "sets pregblank to true know 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 = "" + sales_log_xml.at_xpath("//xmlns:PREGOTHER").content = "" + sales_log_service.send(:create_log, sales_log_xml) + + sales_log = SalesLog.find_by(old_id: sales_log_id) + expect(sales_log&.pregyrha).to eq(nil) + expect(sales_log&.pregla).to eq(nil) + expect(sales_log&.pregghb).to eq(nil) + expect(sales_log&.pregother).to eq(nil) + expect(sales_log&.pregblank).to eq(1) + end + + it "sets pregblank and other organisation fields correctly if answered" do + sales_log_xml.at_xpath("//xmlns:PREGYRHA").content = "Yes" + sales_log_xml.at_xpath("//xmlns:PREGLA").content = "Yes" + sales_log_xml.at_xpath("//xmlns:PREGHBA").content = "Yes" + sales_log_xml.at_xpath("//xmlns:PREGOTHER").content = "Yes" + sales_log_service.send(:create_log, sales_log_xml) + + sales_log = SalesLog.find_by(old_id: sales_log_id) + expect(sales_log&.pregyrha).to eq(1) + expect(sales_log&.pregla).to eq(1) + expect(sales_log&.pregghb).to eq(1) + expect(sales_log&.pregother).to eq(1) + expect(sales_log&.pregblank).to eq(nil) + end + end end end end