diff --git a/app/mailers/bulk_upload_mailer.rb b/app/mailers/bulk_upload_mailer.rb index 94079828f..d07ca696e 100644 --- a/app/mailers/bulk_upload_mailer.rb +++ b/app/mailers/bulk_upload_mailer.rb @@ -66,17 +66,23 @@ class BulkUploadMailer < NotifyMailer ) end - def send_bulk_upload_failed_file_setup_error_mail(user, bulk_upload) + def send_bulk_upload_failed_file_setup_error_mail(bulk_upload:) + bulk_upload_link = if bulk_upload.lettings? + start_bulk_upload_lettings_logs_url + else + start_bulk_upload_sales_logs_url + end + send_email( - user.email, + bulk_upload.user.email, BULK_UPLOAD_FAILED_FILE_SETUP_ERROR_TEMPLATE_ID, { - filename: "[#{bulk_upload} filename]", - upload_timestamp: "[#{bulk_upload} upload_timestamp]", - lettings_or_sales: "[#{bulk_upload} lettings_or_sales]", - year_combo: "[#{bulk_upload} year_combo]", - errors_list: "[#{bulk_upload} errors_list]", - bulk_upload_link: "[#{bulk_upload} bulk_upload_link]", + filename: bulk_upload.filename, + 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"), + bulk_upload_link:, }, ) end diff --git a/spec/mailers/bulk_upload_mailer_spec.rb b/spec/mailers/bulk_upload_mailer_spec.rb index a0042cf69..7d806b2f8 100644 --- a/spec/mailers/bulk_upload_mailer_spec.rb +++ b/spec/mailers/bulk_upload_mailer_spec.rb @@ -12,6 +12,25 @@ RSpec.describe BulkUploadMailer do allow(notify_client).to receive(:send_email).and_return(true) end + describe "#send_bulk_upload_failed_file_setup_error_mail" do + it "sends correctly formed email" do + expect(notify_client).to receive(:send_email).with( + email_address: bulk_upload.user.email, + template_id: described_class::BULK_UPLOAD_FAILED_FILE_SETUP_ERROR_TEMPLATE_ID, + personalisation: { + filename: bulk_upload.filename, + 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"), + bulk_upload_link: start_bulk_upload_lettings_logs_url, + }, + ) + + mailer.send_bulk_upload_failed_file_setup_error_mail(bulk_upload:) + end + end + describe "#send_bulk_upload_complete_mail" do it "sends correctly formed email" do expect(notify_client).to receive(:send_email).with(