Browse Source

Bugfix - handle empty file

pull/1795/head
Jack S 3 years ago
parent
commit
9aceb9e01f
  1. 2
      app/services/bulk_upload/lettings/validator.rb
  2. 2
      config/locales/en.yml
  3. 41
      spec/services/bulk_upload/processor_spec.rb

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

@ -145,7 +145,7 @@ private
def validate_file_not_empty
if File.size(path).zero?
errors.add(:file, :blank)
errors.add(:base, :blank_file)
halt_validations!
end

2
config/locales/en.yml

@ -55,12 +55,14 @@ en:
bulk_upload/lettings/validator:
attributes:
base:
blank_file: Template is blank - The template must be filled in for us to create the logs and check if data is correct.
wrong_field_numbers_count: "Incorrect number of fields, please ensure you have used the correct template"
over_max_column_count: "Too many columns, please ensure you have used the correct template"
wrong_template: "Incorrect start dates, please ensure you have used the correct template"
bulk_upload/sales/validator:
attributes:
base:
blank_file: Template is blank - The template must be filled in for us to create the logs and check if data is correct.
wrong_field_numbers_count: "Incorrect number of fields, please ensure you have used the correct template"
over_max_column_count: "Too many columns, please ensure you have used the correct template"
wrong_template: "Incorrect sale dates, please ensure you have used the correct template"

41
spec/services/bulk_upload/processor_spec.rb

@ -207,6 +207,47 @@ RSpec.describe BulkUpload::Processor do
end
end
context "when processing an empty file" do
let(:mock_downloader) do
instance_double(
BulkUpload::Downloader,
call: nil,
path:,
delete_local_file!: nil,
)
end
let(:file) { Tempfile.new }
let(:path) { file.path }
let(:log) do
build(
:lettings_log,
:completed,
renttype: 3,
age1: 20,
)
end
before do
allow(BulkUpload::Downloader).to receive(:new).with(bulk_upload:).and_return(mock_downloader)
end
it "sends failure email" do
mail_double = instance_double("ActionMailer::MessageDelivery", deliver_later: nil)
allow(BulkUploadMailer).to receive(:send_bulk_upload_failed_service_error_mail).and_return(mail_double)
processor.call
expect(BulkUploadMailer).to have_received(:send_bulk_upload_failed_service_error_mail).with(
bulk_upload:,
errors: ["Template is blank - The template must be filled in for us to create the logs and check if data is correct."],
)
expect(mail_double).to have_received(:deliver_later)
end
end
context "when a bulk upload has an in progress log" do
let(:mock_downloader) do
instance_double(

Loading…
Cancel
Save