Browse Source

populate bulk upload mailer with errors

pull/1358/head
Phil Lee 3 years ago
parent
commit
0efb7f4aad
  1. 19
      app/mailers/bulk_upload_mailer.rb
  2. 15
      spec/mailers/bulk_upload_mailer_spec.rb

19
app/mailers/bulk_upload_mailer.rb

@ -73,6 +73,23 @@ class BulkUploadMailer < NotifyMailer
start_bulk_upload_sales_logs_url
end
validator_class = if bulk_upload.lettings?
BulkUpload::Lettings::Validator
else
BulkUpload::Sales::Validator
end
errors = bulk_upload
.bulk_upload_errors
.where(category: "setup")
.group(:col, :field)
.count
.keys
.sort_by { |_col, field| field }
.map do |col, field|
"- Column #{col} (#{validator_class.question_for_field(field.to_sym)})"
end
send_email(
bulk_upload.user.email,
BULK_UPLOAD_FAILED_FILE_SETUP_ERROR_TEMPLATE_ID,
@ -81,7 +98,7 @@ class BulkUploadMailer < NotifyMailer
upload_timestamp: bulk_upload.created_at.to_fs(:govuk_date_and_time),
lettings_or_sales: bulk_upload.log_type,
year_combo: bulk_upload.year_combo,
errors_list: [].join("\n"),
errors_list: errors.join("\n"),
bulk_upload_link:,
},
)

15
spec/mailers/bulk_upload_mailer_spec.rb

@ -13,6 +13,19 @@ RSpec.describe BulkUploadMailer do
end
describe "#send_bulk_upload_failed_file_setup_error_mail" do
before do
create(:bulk_upload_error, bulk_upload:, col: "A", field: "field_1", category: "setup")
create(:bulk_upload_error, bulk_upload:, col: "E", field: "field_4", category: "setup")
create(:bulk_upload_error, bulk_upload:, col: "F", field: "field_5")
end
let(:expected_errors) do
[
"- Column A (What is the letting type?)",
"- Column E (Management group code)",
]
end
it "sends correctly formed email" do
expect(notify_client).to receive(:send_email).with(
email_address: bulk_upload.user.email,
@ -22,7 +35,7 @@ RSpec.describe BulkUploadMailer do
upload_timestamp: bulk_upload.created_at.to_fs(:govuk_date_and_time),
lettings_or_sales: bulk_upload.log_type,
year_combo: bulk_upload.year_combo,
errors_list: [].join("\n"),
errors_list: expected_errors.join("\n"),
bulk_upload_link: start_bulk_upload_lettings_logs_url,
},
)

Loading…
Cancel
Save