Browse Source

Confirm the soft validations

pull/1615/head
Kat 3 years ago
parent
commit
3afe3002b5
  1. 14
      app/services/bulk_upload/lettings/log_creator.rb
  2. 2
      app/services/bulk_upload/lettings/validator.rb
  3. 5
      app/services/bulk_upload/processor.rb
  4. 3
      app/services/bulk_upload/sales/log_creator.rb
  5. 61
      spec/services/bulk_upload/lettings/log_creator_spec.rb
  6. 20
      spec/services/bulk_upload/processor_spec.rb

14
app/services/bulk_upload/lettings/log_creator.rb

@ -1,9 +1,10 @@
class BulkUpload::Lettings::LogCreator
attr_reader :bulk_upload, :path
def initialize(bulk_upload:, path:)
def initialize(bulk_upload:, path:, confirm_soft_validations: false)
@bulk_upload = bulk_upload
@path = path
@confirm_soft_validations = confirm_soft_validations
end
def call
@ -18,6 +19,17 @@ class BulkUpload::Lettings::LogCreator
row_parser.log.status = "pending"
row_parser.log.status_cache = row_parser.log.calculate_status
# confirm soft validations
if @confirm_soft_validations
row_parser.log.retirement_value_check = 0
row_parser.log.pregnancy_value_check = 0
row_parser.log.major_repairs_date_value_check = 0
row_parser.log.void_date_value_check = 0
row_parser.log.rent_value_check = 0
row_parser.log.net_income_value_check = 0
row_parser.log.carehome_charges_value_check = 0
end
begin
row_parser.log.save!
rescue StandardError => e

2
app/services/bulk_upload/lettings/validator.rb

@ -65,7 +65,7 @@ class BulkUpload::Lettings::Validator
def soft_validation_errors_only?
errors = bulk_upload.bulk_upload_errors
errors.count == errors.where(category: "soft_validation").count
errors.count == errors.where(category: "soft_validation").count && errors.count.positive?
end
def over_column_error_threshold?

5
app/services/bulk_upload/processor.rb

@ -17,7 +17,7 @@ class BulkUpload::Processor
elsif validator.create_logs?
create_logs
if validator.soft_validation_errors_only?
send_check_soft_validations_mail
elsif created_logs_but_incompleted?
@ -90,10 +90,11 @@ private
bulk_upload.user
end
def create_logs
def create_logs(confirm_soft_validations: false)
log_creator_class.new(
bulk_upload:,
path: downloader.path,
confirm_soft_validations:,
).call
end

3
app/services/bulk_upload/sales/log_creator.rb

@ -1,9 +1,10 @@
class BulkUpload::Sales::LogCreator
attr_reader :bulk_upload, :path
def initialize(bulk_upload:, path:)
def initialize(bulk_upload:, path:, confirm_soft_validations: false)
@bulk_upload = bulk_upload
@path = path
@confirm_soft_validations = confirm_soft_validations
end
def call

61
spec/services/bulk_upload/lettings/log_creator_spec.rb

@ -129,6 +129,67 @@ RSpec.describe BulkUpload::Lettings::LogCreator do
end
end
context "with a valid csv and soft validations" do
let(:file) { Tempfile.new }
let(:path) { file.path }
let(:log) do
build(
:lettings_log,
:completed,
renttype: 3,
age1: 22,
age1_known: 0,
ecstat1: 5,
owning_organisation: owning_org,
managing_organisation: owning_org,
created_by: user,
national: 18,
waityear: 9,
joint: 2,
tenancy: 9,
ppcodenk: 0,
)
end
before do
file.write(BulkUpload::LettingsLogToCsv.new(log:, col_offset: 0).to_2022_csv_row)
file.rewind
end
it "creates a new log" do
expect { service.call }.to change(LettingsLog, :count)
end
it "creates a log with pending status" do
service.call
expect(LettingsLog.last.status).to eql("pending")
end
context "when confirming soft validations" do
subject(:service) { described_class.new(bulk_upload:, path:, confirm_soft_validations: true) }
it "sets unanswered soft validations to yes" do
service.call
log = LettingsLog.last
expect(log.age1).to be(22)
expect(log.ecstat1).to be(5)
expect(log.retirement_value_check).to be(0)
end
end
context "when not confirming soft validations" do
it "does not set unanswered soft validations" do
service.call
log = LettingsLog.last
expect(log.age1).to be(22)
expect(log.ecstat1).to be(5)
expect(log.retirement_value_check).to be(nil)
end
end
end
context "when valid csv with existing log" do
xit "what should happen?"
end

20
spec/services/bulk_upload/processor_spec.rb

@ -234,6 +234,16 @@ RSpec.describe BulkUpload::Processor do
expect(BulkUploadMailer).to have_received(:send_how_fix_upload_mail)
expect(mail_double).to have_received(:deliver_later)
end
it "calls log creator without the confirm_soft_validations option" do
log_creator_double = instance_double(BulkUpload::Lettings::LogCreator, call: nil)
allow(BulkUpload::Lettings::LogCreator).to receive(:new).and_return(log_creator_double)
processor.call
expect(BulkUpload::Lettings::LogCreator).to have_received(:new).with(bulk_upload:, path:, confirm_soft_validations: false)
end
end
context "when a bulk upload has logs with only soft validations triggered" do
@ -302,6 +312,16 @@ RSpec.describe BulkUpload::Processor do
expect(BulkUploadMailer).not_to have_received(:send_how_fix_upload_mail)
expect(mail_double).to have_received(:deliver_later)
end
it "calls log creator with the confirm_soft_validations option" do
log_creator_double = instance_double(BulkUpload::Lettings::LogCreator, call: nil)
allow(BulkUpload::Lettings::LogCreator).to receive(:new).and_return(log_creator_double)
processor.call
expect(BulkUpload::Lettings::LogCreator).to have_received(:new).with(bulk_upload:, path:, confirm_soft_validations: true)
end
end
context "when upload has no setup errors something blocks log creation" do

Loading…
Cancel
Save