Browse Source

CLDC-2591: Rewrite import task (#1803)

* Rewrite import task

* Fix lettings log import service test
pull/1805/head
Rachael Booth 1 year ago committed by GitHub
parent
commit
b8c01e0caa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 16
      app/services/imports/lettings_logs_import_service.rb
  2. 16
      app/services/imports/sales_logs_import_service.rb
  3. 25
      app/services/imports/user_import_service.rb
  4. 93
      lib/tasks/full_import.rake
  5. 90
      spec/lib/tasks/full_import_spec.rb
  6. 119
      spec/services/imports/lettings_logs_import_service_spec.rb
  7. 53
      spec/services/imports/sales_logs_import_service_spec.rb

16
app/services/imports/lettings_logs_import_service.rb

@ -8,9 +8,6 @@ module Imports
def create_logs(folder) def create_logs(folder)
import_from(folder, :create_log) import_from(folder, :create_log)
if @logs_with_discrepancies.count.positive?
@logger.warn("The following lettings logs had status discrepancies: [#{@logs_with_discrepancies.join(', ')}]")
end
end end
private private
@ -254,7 +251,6 @@ module Imports
owner_id = meta_field_value(xml_doc, "owner-user-id").strip owner_id = meta_field_value(xml_doc, "owner-user-id").strip
if owner_id.present? if owner_id.present?
user = LegacyUser.find_by(old_user_id: owner_id)&.user user = LegacyUser.find_by(old_user_id: owner_id)&.user
@logger.warn "Missing user! We expected to find a legacy user with old_user_id #{owner_id}" unless user
attributes["created_by"] = user attributes["created_by"] = user
end end
@ -278,10 +274,7 @@ module Imports
record = LettingsLog.find_by(old_id: legacy_id) record = LettingsLog.find_by(old_id: legacy_id)
if allow_updates if allow_updates
attributes["updated_at"] = Time.zone.now attributes["updated_at"] = Time.zone.now
@logger.info "Updating lettings log #{record.id} with legacy ID #{legacy_id}"
record.update!(attributes) record.update!(attributes)
else
@logger.info "Lettings log #{record.id} with legacy ID #{legacy_id} already present, skipping."
end end
record record
rescue ActiveRecord::RecordInvalid => e rescue ActiveRecord::RecordInvalid => e
@ -295,7 +288,6 @@ module Imports
# Blank out all invalid fields for in-progress logs # Blank out all invalid fields for in-progress logs
if %w[saved submitted-invalid].include?(previous_status) if %w[saved submitted-invalid].include?(previous_status)
lettings_log.errors.each do |error| lettings_log.errors.each do |error|
@logger.warn("Log #{lettings_log.old_id}: Removing field #{error.attribute} from log triggering validation: #{error.type}")
attributes.delete(error.attribute.to_s) attributes.delete(error.attribute.to_s)
charges_attributes.each { |attribute| attributes.delete(attribute) } if error.attribute == :tcharge charges_attributes.each { |attribute| attributes.delete(attribute) } if error.attribute == :tcharge
end end
@ -339,9 +331,7 @@ module Imports
errors.each do |(error, fields)| errors.each do |(error, fields)|
next unless lettings_log.errors.of_kind?(*error) next unless lettings_log.errors.of_kind?(*error)
attribute, _type = error
fields.each do |field| fields.each do |field|
@logger.warn("Log #{lettings_log.old_id}: Removing #{field} with error: #{lettings_log.errors[attribute].sort.join(', ')}")
attributes.delete(field) attributes.delete(field)
end end
@logs_overridden << lettings_log.old_id @logs_overridden << lettings_log.old_id
@ -349,8 +339,6 @@ module Imports
end end
if lettings_log.errors.of_kind?(:earnings, :under_hard_min) if lettings_log.errors.of_kind?(:earnings, :under_hard_min)
@logger.warn("Log #{lettings_log.old_id}: Removing earnings with error: #{lettings_log.errors[:earnings].join(', ')}")
@logger.warn("Log #{lettings_log.old_id}: Removing incfreq with error: #{lettings_log.errors[:earnings].join(', ')}")
@logs_overridden << lettings_log.old_id @logs_overridden << lettings_log.old_id
attributes.delete("earnings") attributes.delete("earnings")
attributes.delete("incfreq") attributes.delete("incfreq")
@ -360,7 +348,6 @@ module Imports
end end
if lettings_log.errors.of_kind?(:uprn, :uprn_error) if lettings_log.errors.of_kind?(:uprn, :uprn_error)
@logger.warn("Log #{lettings_log.old_id}: Setting uprn_known to no with error: #{lettings_log.errors[:uprn].join(', ')}")
@logs_overridden << lettings_log.old_id @logs_overridden << lettings_log.old_id
attributes["uprn_known"] = 0 attributes["uprn_known"] = 0
return save_lettings_log(attributes, previous_status) return save_lettings_log(attributes, previous_status)
@ -389,7 +376,6 @@ module Imports
differences.push("#{key} #{value.inspect} #{lettings_log_value.inspect}") differences.push("#{key} #{value.inspect} #{lettings_log_value.inspect}")
end end
end end
@logger.warn "Differences found when saving log #{lettings_log.old_id}: #{differences}" unless differences.empty?
end end
def fields_not_present_in_softwire_data def fields_not_present_in_softwire_data
@ -398,8 +384,6 @@ module Imports
def check_status_completed(lettings_log, previous_status) def check_status_completed(lettings_log, previous_status)
if previous_status.include?("submitted") && lettings_log.status != "completed" if previous_status.include?("submitted") && lettings_log.status != "completed"
@logger.warn "lettings log #{lettings_log.id} is not completed"
@logger.warn "lettings log with old id:#{lettings_log.old_id} is incomplete but status should be complete"
@logs_with_discrepancies << lettings_log.old_id @logs_with_discrepancies << lettings_log.old_id
end end
end end

16
app/services/imports/sales_logs_import_service.rb

@ -8,9 +8,6 @@ module Imports
def create_logs(folder) def create_logs(folder)
import_from(folder, :create_log) import_from(folder, :create_log)
if @logs_with_discrepancies.count.positive?
@logger.warn("The following sales logs had status discrepancies: [#{@logs_with_discrepancies.join(', ')}]")
end
end end
private private
@ -180,7 +177,6 @@ module Imports
owner_id = meta_field_value(xml_doc, "owner-user-id").strip owner_id = meta_field_value(xml_doc, "owner-user-id").strip
if owner_id.present? if owner_id.present?
user = LegacyUser.find_by(old_user_id: owner_id)&.user user = LegacyUser.find_by(old_user_id: owner_id)&.user
@logger.warn "Missing user! We expected to find a legacy user with old_user_id #{owner_id}" unless user
attributes["created_by"] = user attributes["created_by"] = user
end end
@ -201,11 +197,8 @@ module Imports
record = SalesLog.find_by(old_id: legacy_id) record = SalesLog.find_by(old_id: legacy_id)
if allow_updates if allow_updates
@logger.info "Updating sales log #{record.id} with legacy ID #{legacy_id}"
attributes["updated_at"] = Time.zone.now attributes["updated_at"] = Time.zone.now
record.update!(attributes) record.update!(attributes)
else
@logger.info "Lettings log #{record.id} with legacy ID #{legacy_id} already present, skipping."
end end
record record
rescue ActiveRecord::RecordInvalid => e rescue ActiveRecord::RecordInvalid => e
@ -217,7 +210,6 @@ module Imports
if %w[saved submitted-invalid].include?(previous_status) if %w[saved submitted-invalid].include?(previous_status)
sales_log.errors.each do |error| sales_log.errors.each do |error|
unless error.attribute == :type || error.attribute == :ownershipsch unless error.attribute == :type || error.attribute == :ownershipsch
@logger.warn("Log #{sales_log.old_id}: Removing field #{error.attribute} from log triggering validation: #{error.type}")
attributes.delete(error.attribute.to_s) attributes.delete(error.attribute.to_s)
end end
attributes.delete("pcodenk") if error.attribute == :postcode_full attributes.delete("pcodenk") if error.attribute == :postcode_full
@ -245,9 +237,7 @@ module Imports
errors.each do |(error, fields)| errors.each do |(error, fields)|
next unless sales_log.errors.of_kind?(*error) next unless sales_log.errors.of_kind?(*error)
attribute, _type = error
fields.each do |field| fields.each do |field|
@logger.warn("Log #{sales_log.old_id}: Removing #{field} with error: #{sales_log.errors[attribute].sort.join(', ')}")
attributes.delete(field) attributes.delete(field)
end end
@logs_overridden << sales_log.old_id @logs_overridden << sales_log.old_id
@ -255,19 +245,16 @@ module Imports
end end
if sales_log.errors.of_kind?(:postcode_full, :wrong_format) if sales_log.errors.of_kind?(:postcode_full, :wrong_format)
@logger.warn("Log #{sales_log.old_id}: Removing postcode as the postcode is invalid")
@logs_overridden << sales_log.old_id @logs_overridden << sales_log.old_id
attributes.delete("postcode_full") attributes.delete("postcode_full")
attributes["pcodenk"] = attributes["la"].present? ? 1 : nil attributes["pcodenk"] = attributes["la"].present? ? 1 : nil
save_sales_log(attributes, previous_status) save_sales_log(attributes, previous_status)
elsif sales_log.errors.of_kind?(:ppostcode_full, :wrong_format) elsif sales_log.errors.of_kind?(:ppostcode_full, :wrong_format)
@logger.warn("Log #{sales_log.old_id}: Removing previous postcode as the postcode is invalid")
@logs_overridden << sales_log.old_id @logs_overridden << sales_log.old_id
attributes.delete("ppostcode_full") attributes.delete("ppostcode_full")
attributes["ppcodenk"] = attributes["prevloc"].present? ? 1 : nil attributes["ppcodenk"] = attributes["prevloc"].present? ? 1 : nil
save_sales_log(attributes, previous_status) save_sales_log(attributes, previous_status)
elsif sales_log.errors.of_kind?(:uprn, :uprn_error) elsif sales_log.errors.of_kind?(:uprn, :uprn_error)
@logger.warn("Log #{sales_log.old_id}: Setting uprn_known to no with error: #{sales_log.errors[:uprn].join(', ')}")
@logs_overridden << sales_log.old_id @logs_overridden << sales_log.old_id
attributes["uprn_known"] = 0 attributes["uprn_known"] = 0
save_sales_log(attributes, previous_status) save_sales_log(attributes, previous_status)
@ -295,7 +282,6 @@ module Imports
differences.push("#{key} #{value.inspect} #{sales_log_value.inspect}") differences.push("#{key} #{value.inspect} #{sales_log_value.inspect}")
end end
end end
@logger.warn "Differences found when saving log #{sales_log.old_id}: #{differences}" unless differences.empty?
end end
def fields_not_present_in_softwire_data def fields_not_present_in_softwire_data
@ -327,8 +313,6 @@ module Imports
def check_status_completed(sales_log, previous_status) def check_status_completed(sales_log, previous_status)
if previous_status.include?("submitted") && sales_log.status != "completed" if previous_status.include?("submitted") && sales_log.status != "completed"
@logger.warn "sales log #{sales_log.id} is not completed. The following answers are missing: #{missing_answers(sales_log).join(', ')}"
@logger.warn "sales log with old id:#{sales_log.old_id} is incomplete but status should be complete"
@logs_with_discrepancies << sales_log.old_id @logs_with_discrepancies << sales_log.old_id
end end
end end

25
app/services/imports/user_import_service.rb

@ -26,19 +26,20 @@ module Imports
role = highest_role(user.role, role(user_field_value(xml_document, "user-type"))) role = highest_role(user.role, role(user_field_value(xml_document, "user-type")))
user.update!(role:, is_dpo:) user.update!(role:, is_dpo:)
user.legacy_users.create!(old_user_id:) user.legacy_users.create!(old_user_id:)
@logger.info("Found duplicated email, updating user #{user.id} with role #{role} and is_dpo #{is_dpo}")
else else
user = User.create!( user = User.new
email:, user.email = email
name:, user.name = name
password: Devise.friendly_token, user.password = Devise.friendly_token
phone: user_field_value(xml_document, "telephone-no"), user.phone = user_field_value(xml_document, "telephone-no")
organisation:, user.organisation = organisation
role: role(user_field_value(xml_document, "user-type")), user.role = role(user_field_value(xml_document, "user-type"))
is_dpo: is_dpo?(user_field_value(xml_document, "user-type")), user.is_dpo = is_dpo?(user_field_value(xml_document, "user-type"))
is_key_contact: is_key_contact?(user_field_value(xml_document, "contact-priority-id")), user.is_key_contact = is_key_contact?(user_field_value(xml_document, "contact-priority-id"))
active: user_field_value(xml_document, "active"), user.active = user_field_value(xml_document, "active")
)
user.skip_confirmation_notification!
user.save!
user.legacy_users.create!(old_user_id:) user.legacy_users.create!(old_user_id:)
user user
end end

93
lib/tasks/full_import.rake

@ -1,33 +1,92 @@
Import = Struct.new("Import", :import_class, :import_method, :folder) namespace :import do
desc "Run a full import for the institutions listed in the named file on s3"
namespace :core do task :full, %i[institutions_csv_name] => :environment do |_task, args|
desc "Import all data XMLs from legacy CORE" institutions_csv_name = args[:institutions_csv_name]
task :full_import, %i[archive_path] => :environment do |_task, args| raise "Usage: rake core:full_import['institutions_csv_name']" if institutions_csv_name.blank?
archive_path = args[:archive_path]
raise "Usage: rake core:full_import['path/to/archive']" if archive_path.blank?
s3_service = Storage::S3Service.new(Configuration::PaasConfigurationService.new, ENV["IMPORT_PAAS_INSTANCE"]) s3_service = Storage::S3Service.new(Configuration::PaasConfigurationService.new, ENV["IMPORT_PAAS_INSTANCE"])
archive_io = s3_service.get_file_io(archive_path) csv = CSV.parse(s3_service.get_file_io(institutions_csv_name), headers: true)
archive_service = Storage::ArchiveService.new(archive_io) org_count = csv.length
import_list = [ initial_import_list = [
Import.new(Imports::OrganisationImportService, :create_organisations, "institution"), Import.new(Imports::OrganisationImportService, :create_organisations, "institution"),
Import.new(Imports::SchemeImportService, :create_schemes, "mgmtgroups"), Import.new(Imports::SchemeImportService, :create_schemes, "mgmtgroups"),
Import.new(Imports::SchemeLocationImportService, :create_scheme_locations, "schemes"), Import.new(Imports::SchemeLocationImportService, :create_scheme_locations, "schemes"),
Import.new(Imports::UserImportService, :create_users, "user"), Import.new(Imports::UserImportService, :create_users, "user"),
Import.new(Imports::DataProtectionConfirmationImportService, :create_data_protection_confirmations, "dataprotect"), Import.new(Imports::DataProtectionConfirmationImportService, :create_data_protection_confirmations, "dataprotect"),
Import.new(Imports::OrganisationRentPeriodImportService, :create_organisation_rent_periods, "rent-period"), Import.new(Imports::OrganisationRentPeriodImportService, :create_organisation_rent_periods, "rent-period"),
]
Rails.logger.info("Beginning initial imports for #{org_count} organisations")
csv.each do |row|
archive_path = row[1]
archive_io = s3_service.get_file_io(archive_path)
archive_service = Storage::ArchiveService.new(archive_io)
Rails.logger.info("Performing initial imports for organisation #{row[0]}")
initial_import_list.each do |step|
if archive_service.folder_present?(step.folder)
step.import_class.new(archive_service).send(step.import_method, step.folder)
end
end
end
logs_import_list = [
Import.new(Imports::LettingsLogsImportService, :create_logs, "logs"), Import.new(Imports::LettingsLogsImportService, :create_logs, "logs"),
# Import.new(Imports::SalesLogsImportService, :create_logs, "logs"), Import.new(Imports::SalesLogsImportService, :create_logs, "logs"),
] ]
import_list.each do |step| Rails.logger.info("Initial imports complete, beginning log imports for #{org_count} organisations")
if archive_service.folder_present?(step.folder)
Rails.logger.info("Start importing folder #{step.folder}") csv.each do |row|
step.import_class.new(archive_service).send(step.import_method, step.folder) archive_path = row[1]
else archive_io = s3_service.get_file_io(archive_path)
Rails.logger.info("#{step.folder} does not exist, skipping #{step.import_class}") archive_service = Storage::ArchiveService.new(archive_io)
log_count = row[2].to_i + row[3].to_i + row[4].to_i + row[5].to_i
Rails.logger.info("Importing logs for organisation #{row[0]}, expecting #{log_count} logs")
logs_import_list.each do |step|
if archive_service.folder_present?(step.folder)
step.import_class.new(archive_service).send(step.import_method, step.folder)
end
end end
end end
Rails.logger.info("Log import complete, triggering user invite emails")
csv.each do |row|
organisation = Organisation.find_by(name: row[0])
next unless organisation
users = User.where(organisation:, active: true, initial_confirmation_sent: false)
users.each { |user| ResendInvitationMailer.resend_invitation_email(user).deliver_later }
end
Rails.logger.info("Invite emails triggered, generating report")
rep = CSV.generate do |report|
headers = ["Institution name", "Id", "Old Completed lettings logs", "Old In progress lettings logs", "Old Completed sales logs", "Old In progress sales logs", "New Completed lettings logs", "New In Progress lettings logs", "New Completed sales logs", "New In Progress sales logs"]
report << headers
csv.each do |row|
name = row[0]
organisation = Organisation.find_by(name:)
next unless organisation
completed_sales_logs = organisation.owned_sales_logs.where(status: "completed").count
in_progress_sales_logs = organisation.owned_sales_logs.where(status: "in_progress").count
completed_lettings_logs = organisation.owned_lettings_logs.where(status: "completed").count
in_progress_lettings_logs = organisation.owned_lettings_logs.where(status: "in_progress").count
report << row.push(completed_lettings_logs, in_progress_lettings_logs, completed_sales_logs, in_progress_sales_logs)
end
end
report_name = "MigratedLogsReport_#{institutions_csv_name}"
s3_service.write_file(report_name, rep)
Rails.logger.info("Logs report available in s3 import bucket at #{report_name}")
end end
end end

90
spec/lib/tasks/full_import_spec.rb

@ -1,90 +0,0 @@
require "rails_helper"
require "rake"
require "zip"
describe "rake core:full_import", type: :task do
subject(:task) { Rake::Task["core:full_import"] }
let(:s3_service) { instance_double(Storage::S3Service) }
let(:archive_service) { instance_double(Storage::ArchiveService) }
let(:paas_config_service) { instance_double(Configuration::PaasConfigurationService) }
before do
Rake.application.rake_require("tasks/full_import")
Rake::Task.define_task(:environment)
task.reenable
allow(Configuration::PaasConfigurationService).to receive(:new).and_return(paas_config_service)
allow(Storage::S3Service).to receive(:new).and_return(s3_service)
allow(s3_service).to receive(:get_file_io)
allow(Storage::ArchiveService).to receive(:new).and_return(archive_service)
end
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) }
let(:location_service) { instance_double(Imports::SchemeLocationImportService) }
let(:scheme_service) { instance_double(Imports::SchemeImportService) }
let(:organisation_service) { instance_double(Imports::OrganisationImportService) }
before do
allow(Imports::OrganisationImportService).to receive(:new).and_return(organisation_service)
allow(Imports::SchemeImportService).to receive(:new).and_return(scheme_service)
allow(Imports::SchemeLocationImportService).to receive(:new).and_return(location_service)
allow(Imports::UserImportService).to receive(:new).and_return(user_service)
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
expect { task.invoke }.to raise_error(/Usage/)
end
context "with all folders being present" do
before { allow(archive_service).to receive(:folder_present?).and_return(true) }
it "calls every import method with the correct folder" do
expect(organisation_service).to receive(:create_organisations).with("institution")
expect(scheme_service).to receive(:create_schemes).with("mgmtgroups")
expect(location_service).to receive(:create_scheme_locations).with("schemes")
expect(user_service).to receive(:create_users).with("user")
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
end
context "when a specific folders are missing" do
before do
allow(archive_service).to receive(:folder_present?).and_return(true)
allow(archive_service).to receive(:folder_present?).with("mgmtgroups").and_return(false)
allow(archive_service).to receive(:folder_present?).with("schemes").and_return(false)
allow(Rails.logger).to receive(:info)
end
it "only calls import methods for existing folders" do
expect(organisation_service).to receive(:create_organisations)
expect(user_service).to receive(:create_users)
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)
expect(Rails.logger).to receive(:info).with("mgmtgroups does not exist, skipping Imports::SchemeImportService")
expect(Rails.logger).to receive(:info).with("schemes does not exist, skipping Imports::SchemeLocationImportService")
task.invoke(fixture_path)
end
end
end
end

119
spec/services/imports/lettings_logs_import_service_spec.rb

@ -107,7 +107,6 @@ RSpec.describe Imports::LettingsLogsImportService do
it "only updates existing lettings logs" do it "only updates existing lettings logs" do
expect(logger).not_to receive(:error) expect(logger).not_to receive(:error)
expect(logger).not_to receive(:warn) expect(logger).not_to receive(:warn)
expect(logger).to receive(:info).with(/Updating lettings log/).exactly(3).times
start_time = Time.current start_time = Time.current
@ -127,39 +126,6 @@ RSpec.describe Imports::LettingsLogsImportService do
expect { lettings_log_service.create_logs(remote_folder) } expect { lettings_log_service.create_logs(remote_folder) }
.to change(OrganisationRelationship, :count).by(1) .to change(OrganisationRelationship, :count).by(1)
end end
context "when there are status discrepancies" do
let(:lettings_log_id5) { "893ufj2s-lq77-42m4-rty6-ej09gh585uy1" }
let(:lettings_log_id6) { "5ybz29dj-l33t-k1l0-hj86-n4k4ma77xkcd" }
let(:lettings_log_file) { open_file(fixture_directory, lettings_log_id5) }
let(:lettings_log_xml) { Nokogiri::XML(lettings_log_file) }
before do
allow(storage_service).to receive(:get_file_io)
.with("#{remote_folder}/#{lettings_log_id5}.xml")
.and_return(open_file(fixture_directory, lettings_log_id5), open_file(fixture_directory, lettings_log_id5))
allow(storage_service).to receive(:get_file_io)
.with("#{remote_folder}/#{lettings_log_id6}.xml")
.and_return(open_file(fixture_directory, lettings_log_id6), open_file(fixture_directory, lettings_log_id6))
end
it "the logger logs a warning with the lettings log's old id/filename" do
expect(logger).to receive(:warn).with(/is not completed/).once
expect(logger).to receive(:warn).with(/lettings log with old id:#{lettings_log_id5} is incomplete but status should be complete/).once
lettings_log_service.send(:create_log, lettings_log_xml)
end
it "on completion the ids of all logs with status discrepancies are logged in a warning" do
allow(storage_service).to receive(:list_files)
.and_return(%W[#{remote_folder}/#{lettings_log_id5}.xml #{remote_folder}/#{lettings_log_id6}.xml])
expect(logger).to receive(:warn).with(/is not completed/).twice
expect(logger).to receive(:warn).with(/is incomplete but status should be complete/).twice
expect(logger).to receive(:warn).with(/The following lettings logs had status discrepancies: \[893ufj2s-lq77-42m4-rty6-ej09gh585uy1, 5ybz29dj-l33t-k1l0-hj86-n4k4ma77xkcd\]/)
lettings_log_service.create_logs(remote_folder)
end
end
end end
context "when importing a specific log" do context "when importing a specific log" do
@ -171,9 +137,6 @@ RSpec.describe Imports::LettingsLogsImportService do
before { lettings_log_xml.at_xpath("//xmlns:VYEAR").content = 2023 } before { lettings_log_xml.at_xpath("//xmlns:VYEAR").content = 2023 }
it "does not import the voiddate" do it "does not import the voiddate" do
expect(logger).to receive(:warn).with(/is not completed/)
expect(logger).to receive(:warn).with(/lettings log with old id:#{lettings_log_id} is incomplete but status should be complete/)
lettings_log_service.send(:create_log, lettings_log_xml) lettings_log_service.send(:create_log, lettings_log_xml)
lettings_log = LettingsLog.where(old_id: lettings_log_id).first lettings_log = LettingsLog.where(old_id: lettings_log_id).first
@ -198,7 +161,6 @@ RSpec.describe Imports::LettingsLogsImportService do
it "sets the economic status to child under 16" do it "sets the economic status to child under 16" do
# The update is done when calculating derived variables # The update is done when calculating derived variables
expect(logger).to receive(:warn).with(/Differences found when saving log/)
lettings_log_service.send(:create_log, lettings_log_xml) lettings_log_service.send(:create_log, lettings_log_xml)
lettings_log = LettingsLog.where(old_id: lettings_log_id).first lettings_log = LettingsLog.where(old_id: lettings_log_id).first
@ -225,9 +187,6 @@ RSpec.describe Imports::LettingsLogsImportService do
end end
it "intercepts the relevant validation error" do it "intercepts the relevant validation error" do
expect(logger).to receive(:warn).with(/Removing field age2 from log triggering validation: Answer cannot be over 16/)
expect(logger).to receive(:warn).with(/Removing field age2 from log triggering validation: outside_the_range/)
expect(logger).to receive(:warn).with(/Removing field ecstat2 from log triggering validation: Answer cannot be ‘child under 16’/)
expect { lettings_log_service.send(:create_log, lettings_log_xml) } expect { lettings_log_service.send(:create_log, lettings_log_xml) }
.not_to raise_error .not_to raise_error
end end
@ -251,8 +210,6 @@ RSpec.describe Imports::LettingsLogsImportService do
end end
it "intercepts the relevant validation error" do it "intercepts the relevant validation error" do
expect(logger).to receive(:warn).with(/Removing earnings with error: Net income cannot be less than £10.00 per week given the tenant’s working situation/)
expect(logger).to receive(:warn).with(/Removing incfreq with error: Net income cannot be less than £10.00 per week given the tenant’s working situation/)
expect { lettings_log_service.send(:create_log, lettings_log_xml) } expect { lettings_log_service.send(:create_log, lettings_log_xml) }
.not_to raise_error .not_to raise_error
end end
@ -278,8 +235,6 @@ RSpec.describe Imports::LettingsLogsImportService do
end end
it "intercepts the relevant validation error" do it "intercepts the relevant validation error" do
expect(logger).to receive(:warn).with(/Removing tenancylength with error: Enter a tenancy length between 2 and 99 years for a tenancy of this type/)
expect(logger).to receive(:warn).with(/Removing tenancy with error: Enter a tenancy length between 2 and 99 years for a tenancy of this type/)
expect { lettings_log_service.send(:create_log, lettings_log_xml) } expect { lettings_log_service.send(:create_log, lettings_log_xml) }
.not_to raise_error .not_to raise_error
end end
@ -304,8 +259,6 @@ RSpec.describe Imports::LettingsLogsImportService do
end end
it "intercepts the relevant validation error" do it "intercepts the relevant validation error" do
expect(logger).to receive(:warn).with(/Removing prevten with error: Answer cannot be a children’s home or foster care as the lead tenant is 26 or older/)
expect(logger).to receive(:warn).with(/Removing age1 with error: Answer cannot be a children’s home or foster care as the lead tenant is 26 or older/)
expect { lettings_log_service.send(:create_log, lettings_log_xml) } expect { lettings_log_service.send(:create_log, lettings_log_xml) }
.not_to raise_error .not_to raise_error
end end
@ -333,8 +286,6 @@ RSpec.describe Imports::LettingsLogsImportService do
end end
it "intercepts the relevant validation error" do it "intercepts the relevant validation error" do
allow(logger).to receive(:warn)
expect { lettings_log_service.send(:create_log, lettings_log_xml) } expect { lettings_log_service.send(:create_log, lettings_log_xml) }
.not_to raise_error .not_to raise_error
end end
@ -361,8 +312,6 @@ RSpec.describe Imports::LettingsLogsImportService do
end end
it "intercepts the relevant validation error" do it "intercepts the relevant validation error" do
allow(logger).to receive(:warn)
expect { lettings_log_service.send(:create_log, lettings_log_xml) } expect { lettings_log_service.send(:create_log, lettings_log_xml) }
.not_to raise_error .not_to raise_error
end end
@ -386,7 +335,6 @@ RSpec.describe Imports::LettingsLogsImportService do
end end
it "intercepts the relevant validation error" do it "intercepts the relevant validation error" do
expect(logger).to receive(:warn).with(/Removing referral with error: Answer cannot be internal transfer as the household situation immediately before this letting was Residential care home/)
expect { lettings_log_service.send(:create_log, lettings_log_xml) } expect { lettings_log_service.send(:create_log, lettings_log_xml) }
.not_to raise_error .not_to raise_error
end end
@ -408,7 +356,6 @@ RSpec.describe Imports::LettingsLogsImportService do
end end
it "intercepts the relevant validation error" do it "intercepts the relevant validation error" do
expect(logger).to receive(:warn).with(/Removing referral with error: Answer cannot be internal transfer as it’s the same landlord on the tenancy agreement and the household had either a fixed-term or lifetime local authority general needs tenancy immediately before this letting/)
expect { lettings_log_service.send(:create_log, lettings_log_xml) } expect { lettings_log_service.send(:create_log, lettings_log_xml) }
.not_to raise_error .not_to raise_error
end end
@ -438,8 +385,6 @@ RSpec.describe Imports::LettingsLogsImportService do
end end
it "intercepts the relevant validation error" do it "intercepts the relevant validation error" do
expect(logger).to receive(:warn).with(/Removing prevten with error: Answer cannot be non-temporary accommodation as this is a re-let to a tenant who occupied the same property as temporary accommodation/)
expect(logger).to receive(:warn).with(/Removing rsnvac with error: Answer cannot be non-temporary accommodation as this is a re-let to a tenant who occupied the same property as temporary accommodation/)
expect { lettings_log_service.send(:create_log, lettings_log_xml) } expect { lettings_log_service.send(:create_log, lettings_log_xml) }
.not_to raise_error .not_to raise_error
end end
@ -462,7 +407,6 @@ RSpec.describe Imports::LettingsLogsImportService do
end end
it "intercepts the relevant validation error" do it "intercepts the relevant validation error" do
expect(logger).to receive(:warn).with(/Removing offered with error: Times previously offered since becoming available must be between 0 and 150/)
expect { lettings_log_service.send(:create_log, lettings_log_xml) } expect { lettings_log_service.send(:create_log, lettings_log_xml) }
.not_to raise_error .not_to raise_error
end end
@ -507,7 +451,6 @@ RSpec.describe Imports::LettingsLogsImportService do
end end
it "intercepts the relevant validation error" do it "intercepts the relevant validation error" do
expect(logger).to receive(:warn).with(/Removing ecstat1 with error: Net income cannot be greater than £890.00 per week given the tenant’s working situation/)
expect { lettings_log_service.send(:create_log, lettings_log_xml) } expect { lettings_log_service.send(:create_log, lettings_log_xml) }
.not_to raise_error .not_to raise_error
end end
@ -531,8 +474,6 @@ RSpec.describe Imports::LettingsLogsImportService do
end end
it "intercepts the relevant validation error" do it "intercepts the relevant validation error" do
expect(logger).to receive(:warn).with(/Removing age2 with error: Person 2’s age must be between 0 and 120/)
expect(logger).to receive(:warn).with(/Removing age2_known with error: Person 2’s age must be between 0 and 120/)
expect { lettings_log_service.send(:create_log, lettings_log_xml) } expect { lettings_log_service.send(:create_log, lettings_log_xml) }
.not_to raise_error .not_to raise_error
end end
@ -557,8 +498,6 @@ RSpec.describe Imports::LettingsLogsImportService do
end end
it "intercepts the relevant validation error" do it "intercepts the relevant validation error" do
expect(logger).to receive(:warn).with(/Removing age3 with error: Person 3’s age must be between 0 and 120/)
expect(logger).to receive(:warn).with(/Removing age3_known with error: Person 3’s age must be between 0 and 120/)
expect { lettings_log_service.send(:create_log, lettings_log_xml) } expect { lettings_log_service.send(:create_log, lettings_log_xml) }
.not_to raise_error .not_to raise_error
end end
@ -581,7 +520,6 @@ RSpec.describe Imports::LettingsLogsImportService do
end end
it "intercepts the relevant validation error" do it "intercepts the relevant validation error" do
expect(logger).to receive(:warn).with(/Removing beds with error: Number of bedrooms must be between 1 and 12/)
expect { lettings_log_service.send(:create_log, lettings_log_xml) } expect { lettings_log_service.send(:create_log, lettings_log_xml) }
.not_to raise_error .not_to raise_error
end end
@ -611,11 +549,6 @@ RSpec.describe Imports::LettingsLogsImportService do
end end
it "intercepts the relevant validation error" do it "intercepts the relevant validation error" do
expect(logger).to receive(:warn).with("Log 0b4a68df-30cc-474a-93c0-a56ce8fdad3b: Removing brent with error: Answer either the ‘household rent and charges’ question or ‘is this accommodation a care home‘, or select ‘no’ for ‘does the household pay rent or charges for the accommodation?’, Enter a total charge that is at least £10.00 per week")
expect(logger).to receive(:warn).with("Log 0b4a68df-30cc-474a-93c0-a56ce8fdad3b: Removing scharge with error: Answer either the ‘household rent and charges’ question or ‘is this accommodation a care home‘, or select ‘no’ for ‘does the household pay rent or charges for the accommodation?’, Enter a total charge that is at least £10.00 per week")
expect(logger).to receive(:warn).with("Log 0b4a68df-30cc-474a-93c0-a56ce8fdad3b: Removing pscharge with error: Answer either the ‘household rent and charges’ question or ‘is this accommodation a care home‘, or select ‘no’ for ‘does the household pay rent or charges for the accommodation?’, Enter a total charge that is at least £10.00 per week")
expect(logger).to receive(:warn).with("Log 0b4a68df-30cc-474a-93c0-a56ce8fdad3b: Removing supcharg with error: Answer either the ‘household rent and charges’ question or ‘is this accommodation a care home‘, or select ‘no’ for ‘does the household pay rent or charges for the accommodation?’, Enter a total charge that is at least £10.00 per week")
expect(logger).to receive(:warn).with("Log 0b4a68df-30cc-474a-93c0-a56ce8fdad3b: Removing tcharge with error: Answer either the ‘household rent and charges’ question or ‘is this accommodation a care home‘, or select ‘no’ for ‘does the household pay rent or charges for the accommodation?’, Enter a total charge that is at least £10.00 per week")
expect { lettings_log_service.send(:create_log, lettings_log_xml) } expect { lettings_log_service.send(:create_log, lettings_log_xml) }
.not_to raise_error .not_to raise_error
end end
@ -639,11 +572,6 @@ RSpec.describe Imports::LettingsLogsImportService do
end end
it "intercepts the relevant validation error" do it "intercepts the relevant validation error" do
expect(logger).to receive(:warn).with(/Removing brent with error: Enter a value for the service charge between £0 and £480 per week if the landlord is a private registered provider and it is a supported housing letting, Enter an amount above 0, Service charge must be at least £0 every week/)
expect(logger).to receive(:warn).with(/Removing scharge with error: Enter a value for the service charge between £0 and £480 per week if the landlord is a private registered provider and it is a supported housing letting, Enter an amount above 0, Service charge must be at least £0 every week/)
expect(logger).to receive(:warn).with(/Removing pscharge with error: Enter a value for the service charge between £0 and £480 per week if the landlord is a private registered provider and it is a supported housing letting, Enter an amount above 0, Service charge must be at least £0 every week/)
expect(logger).to receive(:warn).with(/Removing supcharg with error: Enter a value for the service charge between £0 and £480 per week if the landlord is a private registered provider and it is a supported housing letting, Enter an amount above 0, Service charge must be at least £0 every week/)
expect(logger).to receive(:warn).with(/Removing tcharge with error: Enter a value for the service charge between £0 and £480 per week if the landlord is a private registered provider and it is a supported housing letting, Enter an amount above 0, Service charge must be at least £0 every week/)
expect { lettings_log_service.send(:create_log, lettings_log_xml) } expect { lettings_log_service.send(:create_log, lettings_log_xml) }
.not_to raise_error .not_to raise_error
end end
@ -673,8 +601,6 @@ RSpec.describe Imports::LettingsLogsImportService do
end end
it "intercepts the relevant validation error" do it "intercepts the relevant validation error" do
expect(logger).to receive(:warn).with(/Removing tshortfall with error: Enter a value over £0.01 as you told us there is an outstanding amount/)
expect(logger).to receive(:warn).with(/Removing tshortfall_known with error: Enter a value over £0.01 as you told us there is an outstanding amount/)
expect { lettings_log_service.send(:create_log, lettings_log_xml) } expect { lettings_log_service.send(:create_log, lettings_log_xml) }
.not_to raise_error .not_to raise_error
end end
@ -698,7 +624,6 @@ RSpec.describe Imports::LettingsLogsImportService do
end end
it "intercepts the relevant validation error" do it "intercepts the relevant validation error" do
expect(logger).to receive(:warn).with(/Removing referral with error: Answer cannot be this source of referral as this is a re-let to tenant who occupied the same property as temporary accommodation/)
expect { lettings_log_service.send(:create_log, lettings_log_xml) } expect { lettings_log_service.send(:create_log, lettings_log_xml) }
.not_to raise_error .not_to raise_error
end end
@ -721,11 +646,6 @@ RSpec.describe Imports::LettingsLogsImportService do
end end
it "intercepts the relevant validation error" do it "intercepts the relevant validation error" do
expect(logger).to receive(:warn).with(/Removing brent with error: Enter a value for the personal service charge between £0 and £30 per week if the landlord is a private registered provider and it is a general needs letting/)
expect(logger).to receive(:warn).with(/Removing scharge with error: Enter a value for the personal service charge between £0 and £30 per week if the landlord is a private registered provider and it is a general needs letting/)
expect(logger).to receive(:warn).with(/Removing pscharge with error: Enter a value for the personal service charge between £0 and £30 per week if the landlord is a private registered provider and it is a general needs letting/)
expect(logger).to receive(:warn).with(/Removing supcharg with error: Enter a value for the personal service charge between £0 and £30 per week if the landlord is a private registered provider and it is a general needs letting/)
expect(logger).to receive(:warn).with(/Removing tcharge with error: Enter a value for the personal service charge between £0 and £30 per week if the landlord is a private registered provider and it is a general needs letting/)
expect { lettings_log_service.send(:create_log, lettings_log_xml) } expect { lettings_log_service.send(:create_log, lettings_log_xml) }
.not_to raise_error .not_to raise_error
end end
@ -749,11 +669,6 @@ RSpec.describe Imports::LettingsLogsImportService do
end end
it "intercepts the relevant validation error" do it "intercepts the relevant validation error" do
expect(logger).to receive(:warn).with(/Removing brent with error: Enter a value for the support charge between £0 and £40 per week if the landlord is a private registered provider and it is a general needs letting/)
expect(logger).to receive(:warn).with(/Removing scharge with error: Enter a value for the support charge between £0 and £40 per week if the landlord is a private registered provider and it is a general needs letting/)
expect(logger).to receive(:warn).with(/Removing pscharge with error: Enter a value for the support charge between £0 and £40 per week if the landlord is a private registered provider and it is a general needs letting/)
expect(logger).to receive(:warn).with(/Removing supcharg with error: Enter a value for the support charge between £0 and £40 per week if the landlord is a private registered provider and it is a general needs letting/)
expect(logger).to receive(:warn).with(/Removing tcharge with error: Enter a value for the support charge between £0 and £40 per week if the landlord is a private registered provider and it is a general needs letting/)
expect { lettings_log_service.send(:create_log, lettings_log_xml) } expect { lettings_log_service.send(:create_log, lettings_log_xml) }
.not_to raise_error .not_to raise_error
end end
@ -777,11 +692,6 @@ RSpec.describe Imports::LettingsLogsImportService do
end end
it "intercepts the relevant validation error" do it "intercepts the relevant validation error" do
expect(logger).to receive(:warn).with(/Removing brent with error: Enter a value for the service charge between £0 and £155 per week if the landlord is a private registered provider and it is a general needs letting/)
expect(logger).to receive(:warn).with(/Removing scharge with error: Enter a value for the service charge between £0 and £155 per week if the landlord is a private registered provider and it is a general needs letting/)
expect(logger).to receive(:warn).with(/Removing pscharge with error: Enter a value for the service charge between £0 and £155 per week if the landlord is a private registered provider and it is a general needs letting/)
expect(logger).to receive(:warn).with(/Removing supcharg with error: Enter a value for the service charge between £0 and £155 per week if the landlord is a private registered provider and it is a general needs letting/)
expect(logger).to receive(:warn).with(/Removing tcharge with error: Enter a value for the service charge between £0 and £155 per week if the landlord is a private registered provider and it is a general needs letting/)
expect { lettings_log_service.send(:create_log, lettings_log_xml) } expect { lettings_log_service.send(:create_log, lettings_log_xml) }
.not_to raise_error .not_to raise_error
end end
@ -808,11 +718,6 @@ RSpec.describe Imports::LettingsLogsImportService do
end end
it "intercepts the relevant validation error" do it "intercepts the relevant validation error" do
expect(logger).to receive(:warn).with("Log 0ead17cb-1668-442d-898c-0d52879ff592: Removing brent with error: Enter a total charge that is at least £10.00 per week")
expect(logger).to receive(:warn).with("Log 0ead17cb-1668-442d-898c-0d52879ff592: Removing scharge with error: Enter a total charge that is at least £10.00 per week")
expect(logger).to receive(:warn).with("Log 0ead17cb-1668-442d-898c-0d52879ff592: Removing pscharge with error: Enter a total charge that is at least £10.00 per week")
expect(logger).to receive(:warn).with("Log 0ead17cb-1668-442d-898c-0d52879ff592: Removing supcharg with error: Enter a total charge that is at least £10.00 per week")
expect(logger).to receive(:warn).with("Log 0ead17cb-1668-442d-898c-0d52879ff592: Removing tcharge with error: Enter a total charge that is at least £10.00 per week")
expect { lettings_log_service.send(:create_log, lettings_log_xml) } expect { lettings_log_service.send(:create_log, lettings_log_xml) }
.not_to raise_error .not_to raise_error
end end
@ -850,11 +755,6 @@ RSpec.describe Imports::LettingsLogsImportService do
end end
it "intercepts the relevant validation error" do it "intercepts the relevant validation error" do
expect(logger).to receive(:warn).with("Log 0ead17cb-1668-442d-898c-0d52879ff592: Removing brent with error: Rent is higher than the absolute maximum expected for a property of this type. Please check the rent, rent period, local authority and (if general needs) number of bedrooms")
expect(logger).to receive(:warn).with("Log 0ead17cb-1668-442d-898c-0d52879ff592: Removing scharge with error: Rent is higher than the absolute maximum expected for a property of this type. Please check the rent, rent period, local authority and (if general needs) number of bedrooms")
expect(logger).to receive(:warn).with("Log 0ead17cb-1668-442d-898c-0d52879ff592: Removing pscharge with error: Rent is higher than the absolute maximum expected for a property of this type. Please check the rent, rent period, local authority and (if general needs) number of bedrooms")
expect(logger).to receive(:warn).with("Log 0ead17cb-1668-442d-898c-0d52879ff592: Removing supcharg with error: Rent is higher than the absolute maximum expected for a property of this type. Please check the rent, rent period, local authority and (if general needs) number of bedrooms")
expect(logger).to receive(:warn).with("Log 0ead17cb-1668-442d-898c-0d52879ff592: Removing tcharge with error: Rent is higher than the absolute maximum expected for a property of this type. Please check the rent, rent period, local authority and (if general needs) number of bedrooms")
expect { lettings_log_service.send(:create_log, lettings_log_xml) } expect { lettings_log_service.send(:create_log, lettings_log_xml) }
.not_to raise_error .not_to raise_error
end end
@ -879,9 +779,6 @@ RSpec.describe Imports::LettingsLogsImportService do
end end
it "intercepts the relevant validation error" do it "intercepts the relevant validation error" do
expect(logger).to receive(:warn).with(/Differences found when saving log/)
expect(logger).to receive(:warn).with(/Removing location_id with error: The location LS16 6FT was deactivated on 10 October 2021 and was not available on the day you entered./)
expect(logger).to receive(:warn).with(/Removing scheme_id with error: The location LS16 6FT was deactivated on 10 October 2021 and was not available on the day you entered./)
expect { lettings_log_service.send(:create_log, lettings_log_xml) } expect { lettings_log_service.send(:create_log, lettings_log_xml) }
.not_to raise_error .not_to raise_error
end end
@ -907,9 +804,6 @@ RSpec.describe Imports::LettingsLogsImportService do
end end
it "intercepts the relevant validation error" do it "intercepts the relevant validation error" do
expect(logger).to receive(:warn).with(/Differences found when saving log/)
expect(logger).to receive(:warn).with(/Removing scheme_id with error: This scheme cannot be chosen as it has no completed locations/)
expect(logger).to receive(:warn).with(/Removing location_id with error: This scheme cannot be chosen as it has no completed locations/)
expect { lettings_log_service.send(:create_log, lettings_log_xml) } expect { lettings_log_service.send(:create_log, lettings_log_xml) }
.not_to raise_error .not_to raise_error
end end
@ -941,7 +835,6 @@ RSpec.describe Imports::LettingsLogsImportService do
end end
it "intercepts the relevant validation error" do it "intercepts the relevant validation error" do
expect(logger).to receive(:warn).with(/Removing chcharge with error: Household rent and other charges must be between £10.00 and £5,000.00 if paying weekly for 52 weeks/)
expect { lettings_log_service.send(:create_log, lettings_log_xml) } expect { lettings_log_service.send(:create_log, lettings_log_xml) }
.not_to raise_error .not_to raise_error
end end
@ -1179,7 +1072,6 @@ RSpec.describe Imports::LettingsLogsImportService do
it "only updates existing lettings logs" do it "only updates existing lettings logs" do
expect(logger).not_to receive(:error) expect(logger).not_to receive(:error)
expect(logger).not_to receive(:warn) expect(logger).not_to receive(:warn)
expect(logger).to receive(:info).with(/Updating lettings log/).once
start_time = Time.current start_time = Time.current
@ -1220,7 +1112,6 @@ RSpec.describe Imports::LettingsLogsImportService do
end end
it "intercepts the relevant validation error" do it "intercepts the relevant validation error" do
expect(logger).to receive(:warn).with(/Removing joint with error: This cannot be a joint tenancy as you've told us there's only one person in the household/)
expect { lettings_log_service.send(:create_log, lettings_log_xml) } expect { lettings_log_service.send(:create_log, lettings_log_xml) }
.not_to raise_error .not_to raise_error
end end
@ -1263,8 +1154,6 @@ RSpec.describe Imports::LettingsLogsImportService do
end end
it "intercepts the relevant validation error" do it "intercepts the relevant validation error" do
expect(logger).to receive(:warn).with(/Removing tshortfall with error: You cannot answer the outstanding amount question if you don’t have outstanding rent or charges/)
expect(logger).to receive(:warn).with(/Removing hbrentshortfall with error: You cannot answer the outstanding amount question if you don’t have outstanding rent or charges/)
expect { lettings_log_service.send(:create_log, lettings_log_xml) } expect { lettings_log_service.send(:create_log, lettings_log_xml) }
.not_to raise_error .not_to raise_error
end end
@ -1295,7 +1184,6 @@ RSpec.describe Imports::LettingsLogsImportService do
end end
it "intercepts the relevant validation error" do it "intercepts the relevant validation error" do
expect(logger).to receive(:warn).with("Log 00d2343e-d5fa-4c89-8400-ec3854b0f2b4: Removing field tcharge from log triggering validation: under_10")
lettings_log_service.send(:create_log, lettings_log_xml) lettings_log_service.send(:create_log, lettings_log_xml)
end end
@ -1346,7 +1234,6 @@ RSpec.describe Imports::LettingsLogsImportService do
end end
it "intercepts the relevant validation error" do it "intercepts the relevant validation error" do
expect(logger).to receive(:warn).with("Log 0b4a68df-30cc-474a-93c0-a56ce8fdad3b: Removing period with error: DLUHC does not charge rent weekly for 52 weeks")
expect { lettings_log_service.send(:create_log, lettings_log_xml) } expect { lettings_log_service.send(:create_log, lettings_log_xml) }
.not_to raise_error .not_to raise_error
end end
@ -1387,7 +1274,6 @@ RSpec.describe Imports::LettingsLogsImportService do
end end
it "intercepts the relevant validation error" do it "intercepts the relevant validation error" do
expect(logger).to receive(:warn).with(/Removing layear with error: The household cannot have just moved to the local authority area if this letting is a renewal/)
expect { lettings_log_service.send(:create_log, lettings_log_xml) } expect { lettings_log_service.send(:create_log, lettings_log_xml) }
.not_to raise_error .not_to raise_error
end end
@ -1422,9 +1308,6 @@ RSpec.describe Imports::LettingsLogsImportService do
end end
it "intercepts the relevant validation error" do it "intercepts the relevant validation error" do
expect(logger).to receive(:warn).with(/Removing voiddate with error: Void date must be before the major repairs date if provided/)
expect(logger).to receive(:warn).with(/Removing mrcdate with error: Void date must be before the major repairs date if provided/)
expect(logger).to receive(:warn).with(/Removing majorrepairs with error: Void date must be before the major repairs date if provided/)
expect { lettings_log_service.send(:create_log, lettings_log_xml) } expect { lettings_log_service.send(:create_log, lettings_log_xml) }
.not_to raise_error .not_to raise_error
end end
@ -1460,8 +1343,6 @@ RSpec.describe Imports::LettingsLogsImportService do
end end
it "intercepts the relevant validation error" do it "intercepts the relevant validation error" do
expect(logger).to receive(:warn).with(/Removing tshortfall with error: Enter a value less less than the basic rent amount/)
expect(logger).to receive(:warn).with(/Removing tshortfall_known with error: Enter a value less less than the basic rent amount/)
expect { lettings_log_service.send(:create_log, lettings_log_xml) } expect { lettings_log_service.send(:create_log, lettings_log_xml) }
.not_to raise_error .not_to raise_error
end end

53
spec/services/imports/sales_logs_import_service_spec.rb

@ -87,7 +87,6 @@ RSpec.describe Imports::SalesLogsImportService do
it "only updates existing sales logs" do it "only updates existing sales logs" do
expect(logger).not_to receive(:error) expect(logger).not_to receive(:error)
allow(logger).to receive(:warn) allow(logger).to receive(:warn)
expect(logger).to receive(:info).with(/Updating sales log/).exactly(4).times
start_time = Time.current start_time = Time.current
@ -100,37 +99,6 @@ RSpec.describe Imports::SalesLogsImportService do
expect(updated_logs).to eq(4) expect(updated_logs).to eq(4)
end end
end end
context "when there are status discrepancies" do
let(:sales_log_file) { open_file(fixture_directory, "shared_ownership_sales_log3") }
let(:sales_log_xml) { Nokogiri::XML(sales_log_file) }
before do
allow(storage_service).to receive(:get_file_io)
.with("#{remote_folder}/shared_ownership_sales_log3.xml")
.and_return(open_file(fixture_directory, "shared_ownership_sales_log3"), open_file(fixture_directory, "shared_ownership_sales_log3"))
allow(storage_service).to receive(:get_file_io)
.with("#{remote_folder}/shared_ownership_sales_log4.xml")
.and_return(open_file(fixture_directory, "shared_ownership_sales_log4"), open_file(fixture_directory, "shared_ownership_sales_log4"))
end
it "the logger logs a warning with the sales log's old id/filename" do
expect(logger).to receive(:warn).with(/is not completed/).once
expect(logger).to receive(:warn).with(/sales log with old id:shared_ownership_sales_log3 is incomplete but status should be complete/).once
sales_log_service.send(:create_log, sales_log_xml)
end
it "on completion the ids of all logs with status discrepancies are logged in a warning" do
allow(storage_service).to receive(:list_files)
.and_return(%W[#{remote_folder}/shared_ownership_sales_log3.xml #{remote_folder}/shared_ownership_sales_log4.xml])
expect(logger).to receive(:warn).with(/is not completed/).twice
expect(logger).to receive(:warn).with(/is incomplete but status should be complete/).twice
expect(logger).to receive(:warn).with(/The following sales logs had status discrepancies: \[shared_ownership_sales_log3, shared_ownership_sales_log4\]/)
sales_log_service.create_logs(remote_folder)
end
end
end end
context "when importing a specific log" do context "when importing a specific log" do
@ -537,8 +505,6 @@ RSpec.describe Imports::SalesLogsImportService do
end end
it "intercepts the relevant validation error" do it "intercepts the relevant validation error" do
expect(logger).to receive(:warn).with(/Log discounted_ownership_sales_log: Removing field ecstat2 from log triggering validation: Answer cannot be ‘child under 16’ as you told us the person 2 is older than 16/)
expect(logger).to receive(:warn).with(/Log discounted_ownership_sales_log: Removing field age2 from log triggering validation: Answer cannot be over 16 as person’s 2 working situation is ‘child under 16‘/)
expect { sales_log_service.send(:create_log, sales_log_xml) } expect { sales_log_service.send(:create_log, sales_log_xml) }
.not_to raise_error .not_to raise_error
end end
@ -563,7 +529,6 @@ RSpec.describe Imports::SalesLogsImportService do
end end
it "intercepts the relevant validation error" do it "intercepts the relevant validation error" do
expect(logger).to receive(:warn).with(/Removing equity with error: The maximum initial equity stake is 75%/)
expect { sales_log_service.send(:create_log, sales_log_xml) } expect { sales_log_service.send(:create_log, sales_log_xml) }
.not_to raise_error .not_to raise_error
end end
@ -587,7 +552,6 @@ RSpec.describe Imports::SalesLogsImportService do
end end
it "intercepts the relevant validation error" do it "intercepts the relevant validation error" do
expect(logger).to receive(:warn).with(/Removing equity with error: The minimum initial equity stake for this type of shared ownership sale is 25%/)
expect { sales_log_service.send(:create_log, sales_log_xml) } expect { sales_log_service.send(:create_log, sales_log_xml) }
.not_to raise_error .not_to raise_error
end end
@ -612,7 +576,6 @@ RSpec.describe Imports::SalesLogsImportService do
end end
it "intercepts the relevant validation error" do it "intercepts the relevant validation error" do
expect(logger).to receive(:warn).with(/Log shared_ownership_sales_log: Removing postcode as the postcode is invalid/)
expect { sales_log_service.send(:create_log, sales_log_xml) } expect { sales_log_service.send(:create_log, sales_log_xml) }
.not_to raise_error .not_to raise_error
end end
@ -639,7 +602,6 @@ RSpec.describe Imports::SalesLogsImportService do
end end
it "intercepts the relevant validation error" do it "intercepts the relevant validation error" do
expect(logger).to receive(:warn).with(/Log shared_ownership_sales_log: Removing previous postcode as the postcode is invalid/)
expect { sales_log_service.send(:create_log, sales_log_xml) } expect { sales_log_service.send(:create_log, sales_log_xml) }
.not_to raise_error .not_to raise_error
end end
@ -675,7 +637,6 @@ RSpec.describe Imports::SalesLogsImportService do
end end
it "intercepts the relevant validation error but does not clear setup fields" do it "intercepts the relevant validation error but does not clear setup fields" do
expect(logger).to receive(:warn).with(/Log shared_ownership_sales_log: Removing field stairbought from log triggering validation: The minimum increase in equity while staircasing is 10%/)
expect { sales_log_service.send(:create_log, sales_log_xml) } expect { sales_log_service.send(:create_log, sales_log_xml) }
.not_to raise_error .not_to raise_error
sales_log = SalesLog.find_by(old_id: sales_log_id) sales_log = SalesLog.find_by(old_id: sales_log_id)
@ -693,8 +654,6 @@ RSpec.describe Imports::SalesLogsImportService do
end end
it "intercepts the relevant validation error" do it "intercepts the relevant validation error" do
expect(logger).to receive(:warn).with(/Removing ppcodenk with error: Buyer's last accommodation and discounted ownership postcodes must match, Last settled accommodation and discounted ownership property postcodes must match/)
expect(logger).to receive(:warn).with(/Removing ppostcode_full with error: Buyer's last accommodation and discounted ownership postcodes must match, Last settled accommodation and discounted ownership property postcodes must match/)
expect { sales_log_service.send(:create_log, sales_log_xml) } expect { sales_log_service.send(:create_log, sales_log_xml) }
.not_to raise_error .not_to raise_error
end end
@ -720,7 +679,6 @@ RSpec.describe Imports::SalesLogsImportService do
end end
it "intercepts the relevant validation error" do it "intercepts the relevant validation error" do
expect(logger).to receive(:warn).with(/Removing field postcode_full from log triggering validation: wrong_format/)
expect { sales_log_service.send(:create_log, sales_log_xml) } expect { sales_log_service.send(:create_log, sales_log_xml) }
.not_to raise_error .not_to raise_error
end end
@ -764,7 +722,6 @@ RSpec.describe Imports::SalesLogsImportService do
end end
it "intercepts the relevant validation error" do it "intercepts the relevant validation error" do
expect(logger).to receive(:warn).with(/Removing exdate with error: Contract exchange date must be less than 1 year before sale completion date/)
expect { sales_log_service.send(:create_log, sales_log_xml) } expect { sales_log_service.send(:create_log, sales_log_xml) }
.not_to raise_error .not_to raise_error
end end
@ -789,7 +746,6 @@ RSpec.describe Imports::SalesLogsImportService do
end end
it "intercepts the relevant validation error" do it "intercepts the relevant validation error" do
expect(logger).to receive(:warn).with(/Removing mortgage with error: Mortgage amount must be at least £1, Mortgage value cannot be £0 if a mortgage was used for the purchase of this property/)
expect { sales_log_service.send(:create_log, sales_log_xml) } expect { sales_log_service.send(:create_log, sales_log_xml) }
.not_to raise_error .not_to raise_error
end end
@ -814,7 +770,6 @@ RSpec.describe Imports::SalesLogsImportService do
end end
it "intercepts the relevant validation error" do it "intercepts the relevant validation error" do
expect(logger).to receive(:warn).with(/Removing income1 with error: Income must be £80,000 or lower for properties outside London local authority/)
expect { sales_log_service.send(:create_log, sales_log_xml) } expect { sales_log_service.send(:create_log, sales_log_xml) }
.not_to raise_error .not_to raise_error
end end
@ -841,7 +796,6 @@ RSpec.describe Imports::SalesLogsImportService do
end end
it "intercepts the relevant validation error" do it "intercepts the relevant validation error" do
expect(logger).to receive(:warn).with(/Removing income2 with error: Combined income must be £80,000 or lower for properties outside London local authorities, Income must be £80,000 or lower for properties outside London local authority/)
expect { sales_log_service.send(:create_log, sales_log_xml) } expect { sales_log_service.send(:create_log, sales_log_xml) }
.not_to raise_error .not_to raise_error
end end
@ -866,7 +820,6 @@ RSpec.describe Imports::SalesLogsImportService do
end end
it "intercepts the relevant validation error" do it "intercepts the relevant validation error" do
expect(logger).to receive(:warn).with(/Removing income1 with error: Income must be £90,000 or lower for properties within a London local authority/)
expect { sales_log_service.send(:create_log, sales_log_xml) } expect { sales_log_service.send(:create_log, sales_log_xml) }
.not_to raise_error .not_to raise_error
end end
@ -893,7 +846,6 @@ RSpec.describe Imports::SalesLogsImportService do
end end
it "intercepts the relevant validation error" do it "intercepts the relevant validation error" do
expect(logger).to receive(:warn).with(/Removing income2 with error: Combined income must be £90,000 or lower for properties within a London local authority, Income must be £90,000 or lower for properties within a London local authority/)
expect { sales_log_service.send(:create_log, sales_log_xml) } expect { sales_log_service.send(:create_log, sales_log_xml) }
.not_to raise_error .not_to raise_error
end end
@ -917,8 +869,6 @@ RSpec.describe Imports::SalesLogsImportService do
end end
it "intercepts the relevant validation error" do it "intercepts the relevant validation error" do
expect(logger).to receive(:warn).with(/Removing mscharge with error: Monthly leasehold charges must be at least £1/)
expect(logger).to receive(:warn).with(/Removing has_mscharge with error: Monthly leasehold charges must be at least £1/)
expect { sales_log_service.send(:create_log, sales_log_xml) } expect { sales_log_service.send(:create_log, sales_log_xml) }
.not_to raise_error .not_to raise_error
end end
@ -943,7 +893,6 @@ RSpec.describe Imports::SalesLogsImportService do
end end
it "intercepts the relevant validation error" do it "intercepts the relevant validation error" do
expect(logger).to receive(:warn).with(/Removing frombeds with error: Number of bedrooms in previous property must be between 1 and 6/)
expect { sales_log_service.send(:create_log, sales_log_xml) } expect { sales_log_service.send(:create_log, sales_log_xml) }
.not_to raise_error .not_to raise_error
end end
@ -967,8 +916,6 @@ RSpec.describe Imports::SalesLogsImportService do
end end
it "intercepts the relevant validation error" do it "intercepts the relevant validation error" do
expect(logger).to receive(:warn).with(/Removing age1 with error: Lead buyer’s age must be between 16 and 110/)
expect(logger).to receive(:warn).with(/Removing age1_known with error: Lead buyer’s age must be between 16 and 110/)
expect { sales_log_service.send(:create_log, sales_log_xml) } expect { sales_log_service.send(:create_log, sales_log_xml) }
.not_to raise_error .not_to raise_error
end end

Loading…
Cancel
Save