Browse Source

remove column errors from bulk upload email

pull/1451/head
Phil Lee 3 years ago
parent
commit
df98dc9b64
  1. 13
      app/mailers/bulk_upload_mailer.rb
  2. 8
      app/models/bulk_upload.rb
  3. 31
      spec/mailers/bulk_upload_mailer_spec.rb

13
app/mailers/bulk_upload_mailer.rb

@ -33,19 +33,7 @@ class BulkUploadMailer < NotifyMailer
) )
end end
def columns_with_errors(bulk_upload:)
array = bulk_upload.columns_with_errors
if array.size > 3
"#{array.take(3).join(', ')} and more"
else
array.join(", ")
end
end
def send_correct_and_upload_again_mail(bulk_upload:) def send_correct_and_upload_again_mail(bulk_upload:)
error_description = "We noticed that you have a lot of similar errors in column #{columns_with_errors(bulk_upload:)}. Please correct your data export and upload again."
summary_report_link = if BulkUploadErrorSummaryTableComponent.new(bulk_upload:).errors? summary_report_link = if BulkUploadErrorSummaryTableComponent.new(bulk_upload:).errors?
summary_bulk_upload_lettings_result_url(bulk_upload) summary_bulk_upload_lettings_result_url(bulk_upload)
else else
@ -60,7 +48,6 @@ class BulkUploadMailer < NotifyMailer
upload_timestamp: bulk_upload.created_at.to_fs(:govuk_date_and_time), upload_timestamp: bulk_upload.created_at.to_fs(:govuk_date_and_time),
year_combo: bulk_upload.year_combo, year_combo: bulk_upload.year_combo,
lettings_or_sales: bulk_upload.log_type, lettings_or_sales: bulk_upload.log_type,
error_description:,
summary_report_link:, summary_report_link:,
}, },
) )

8
app/models/bulk_upload.rb

@ -30,14 +30,6 @@ class BulkUpload < ApplicationRecord
end end
end end
def columns_with_errors
bulk_upload_errors
.select(:col)
.distinct(:col)
.pluck(:col)
.sort_by { |col| col.rjust(2, "0") }
end
def general_needs? def general_needs?
needstype == 1 needstype == 1
end end

31
spec/mailers/bulk_upload_mailer_spec.rb

@ -116,7 +116,7 @@ RSpec.describe BulkUploadMailer do
create(:bulk_upload_error, bulk_upload:, col: "B") create(:bulk_upload_error, bulk_upload:, col: "B")
end end
it "sends correctly formed email with A, B" do it "sends correctly formed email" do
expect(notify_client).to receive(:send_email).with( expect(notify_client).to receive(:send_email).with(
email_address: user.email, email_address: user.email,
template_id: described_class::BULK_UPLOAD_FAILED_CSV_ERRORS_TEMPLATE_ID, template_id: described_class::BULK_UPLOAD_FAILED_CSV_ERRORS_TEMPLATE_ID,
@ -125,7 +125,6 @@ RSpec.describe BulkUploadMailer do
upload_timestamp: bulk_upload.created_at.to_fs(:govuk_date_and_time), upload_timestamp: bulk_upload.created_at.to_fs(:govuk_date_and_time),
year_combo: bulk_upload.year_combo, year_combo: bulk_upload.year_combo,
lettings_or_sales: bulk_upload.log_type, lettings_or_sales: bulk_upload.log_type,
error_description: "We noticed that you have a lot of similar errors in column A, B. Please correct your data export and upload again.",
summary_report_link: "http://localhost:3000/lettings-logs/bulk-upload-results/#{bulk_upload.id}", summary_report_link: "http://localhost:3000/lettings-logs/bulk-upload-results/#{bulk_upload.id}",
}, },
) )
@ -133,33 +132,5 @@ RSpec.describe BulkUploadMailer do
mailer.send_correct_and_upload_again_mail(bulk_upload:) mailer.send_correct_and_upload_again_mail(bulk_upload:)
end end
end end
context "when 4 columns with errors" do
before do
stub_const("BulkUploadErrorSummaryTableComponent::DISPLAY_THRESHOLD", 0)
create(:bulk_upload_error, bulk_upload:, col: "A")
create(:bulk_upload_error, bulk_upload:, col: "B")
create(:bulk_upload_error, bulk_upload:, col: "C")
create(:bulk_upload_error, bulk_upload:, col: "D")
end
it "sends correctly formed email with A, B, C and more" do
expect(notify_client).to receive(:send_email).with(
email_address: user.email,
template_id: described_class::BULK_UPLOAD_FAILED_CSV_ERRORS_TEMPLATE_ID,
personalisation: {
filename: bulk_upload.filename,
upload_timestamp: bulk_upload.created_at.to_fs(:govuk_date_and_time),
year_combo: bulk_upload.year_combo,
lettings_or_sales: bulk_upload.log_type,
error_description: "We noticed that you have a lot of similar errors in column A, B, C and more. Please correct your data export and upload again.",
summary_report_link: "http://localhost:3000/lettings-logs/bulk-upload-results/#{bulk_upload.id}/summary",
},
)
mailer.send_correct_and_upload_again_mail(bulk_upload:)
end
end
end end
end end

Loading…
Cancel
Save