Browse Source

Fix view bulk uploads and add another status label (#2883)

* Add another bulk upload status for invalid uploads

* Add test and update text

* update text missed
pull/2882/merge
Manny Dinssa 6 days ago committed by GitHub
parent
commit
02d1c664ef
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 2
      app/helpers/tag_helper.rb
  2. 3
      app/models/bulk_upload.rb
  3. 3
      app/services/bulk_upload/processor.rb
  4. 5
      spec/services/bulk_upload/processor_spec.rb

2
app/helpers/tag_helper.rb

@ -21,6 +21,7 @@ module TagHelper
processing: "Processing",
blank_template: "Blank template",
wrong_template: "Wrong template used",
processing_error: "Error processing CSV",
important_errors: "Errors on important questions in CSV",
critical_errors: "Critical errors in CSV",
potential_errors: "Potential errors in CSV",
@ -48,6 +49,7 @@ module TagHelper
processing: "yellow",
blank_template: "red",
wrong_template: "red",
processing_error: "red",
important_errors: "red",
critical_errors: "red",
potential_errors: "red",

3
app/models/bulk_upload.rb

@ -1,7 +1,7 @@
class BulkUpload < ApplicationRecord
enum :log_type, { lettings: "lettings", sales: "sales" }
enum :rent_type_fix_status, { not_applied: "not_applied", applied: "applied", not_needed: "not_needed" }
enum :failure_reason, { blank_template: "blank_template", wrong_template: "wrong_template" }
enum :failure_reason, { blank_template: "blank_template", wrong_template: "wrong_template", processing_error: "processing_error" }
belongs_to :user
@ -43,6 +43,7 @@ class BulkUpload < ApplicationRecord
return :processing if processing
return :blank_template if failure_reason == "blank_template"
return :wrong_template if failure_reason == "wrong_template"
return :processing_error if failure_reason == "processing_error"
if logs.visible.exists?
return :errors_fixed_in_service if completed? && bulk_upload_errors.any?

3
app/services/bulk_upload/processor.rb

@ -61,6 +61,7 @@ class BulkUpload::Processor
end
rescue StandardError => e
Sentry.capture_exception(e)
@bulk_upload.update!(failure_reason: "processing_error")
send_failure_mail
ensure
downloader.delete_local_file!
@ -184,6 +185,8 @@ private
@bulk_upload.update!(failure_reason: "blank_template")
elsif wrong_template_errors.any? { |error| validator.errors.full_messages.include?(error) }
@bulk_upload.update!(failure_reason: "wrong_template")
else
@bulk_upload.update!(failure_reason: "processing_error")
end
send_failure_mail(errors: validator.errors.full_messages)

5
spec/services/bulk_upload/processor_spec.rb

@ -101,6 +101,11 @@ RSpec.describe BulkUpload::Processor do
allow(mock_validator).to receive(:call).and_raise(StandardError)
end
it "updates the failure_reason to invalid_upload" do
processor.call
expect(bulk_upload.reload.failure_reason).to eq("processing_error")
end
it "sends failure email" do
mail_double = instance_double("ActionMailer::MessageDelivery", deliver_later: nil)

Loading…
Cancel
Save