From 02d1c664ef3554182b7bcd56b5009134746e1449 Mon Sep 17 00:00:00 2001 From: Manny Dinssa <44172848+Dinssa@users.noreply.github.com> Date: Mon, 6 Jan 2025 17:15:20 +0000 Subject: [PATCH] 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 --- app/helpers/tag_helper.rb | 2 ++ app/models/bulk_upload.rb | 3 ++- app/services/bulk_upload/processor.rb | 3 +++ spec/services/bulk_upload/processor_spec.rb | 5 +++++ 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/app/helpers/tag_helper.rb b/app/helpers/tag_helper.rb index 398f897cf..3ecea6d25 100644 --- a/app/helpers/tag_helper.rb +++ b/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", diff --git a/app/models/bulk_upload.rb b/app/models/bulk_upload.rb index 3a3d41540..6616285b0 100644 --- a/app/models/bulk_upload.rb +++ b/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? diff --git a/app/services/bulk_upload/processor.rb b/app/services/bulk_upload/processor.rb index c54032fda..f6ce5eaea 100644 --- a/app/services/bulk_upload/processor.rb +++ b/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) diff --git a/spec/services/bulk_upload/processor_spec.rb b/spec/services/bulk_upload/processor_spec.rb index 468d5fef8..27f1aebed 100644 --- a/spec/services/bulk_upload/processor_spec.rb +++ b/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)