Browse Source

add bulk upload mailer test

pull/1267/head
Phil Lee 3 years ago
parent
commit
23ea9c88ae
  1. 22
      app/mailers/bulk_upload_mailer.rb
  2. 28
      spec/mailers/bulk_upload_mailer_spec.rb

22
app/mailers/bulk_upload_mailer.rb

@ -83,16 +83,24 @@ class BulkUploadMailer < NotifyMailer
)
end
def send_bulk_upload_with_errors_mail(user, bulk_upload)
def send_bulk_upload_with_errors_mail(bulk_upload:)
n = bulk_upload.logs.where.not(status: %w[completed]).count
n_logs = pluralize(n, "log")
title = "We found #{n_logs} with errors"
error_description = "We created logs from your #{bulk_upload.year_combo} #{bulk_upload.log_type} data. There was a problem with #{n} of the logs. Click the below link to fix these logs."
send_email(
user.email,
bulk_upload.user.email,
BULK_UPLOAD_WITH_ERRORS_TEMPLATE_ID,
{
title: "[#{bulk_upload} title]",
filename: "[#{bulk_upload} filename]",
upload_timestamp: "[#{bulk_upload} upload_timestamp]",
error_description: "[#{bulk_upload} error_description]",
summary_report_link: "[#{bulk_upload} summary_report_link]",
title:,
filename: bulk_upload.filename,
upload_timestamp: bulk_upload.created_at.to_fs(:govuk_date_and_time),
error_description:,
summary_report_link: summary_bulk_upload_lettings_result_url(bulk_upload),
},
)
end

28
spec/mailers/bulk_upload_mailer_spec.rb

@ -47,4 +47,32 @@ RSpec.describe BulkUploadMailer do
mailer.send_bulk_upload_failed_service_error_mail(bulk_upload:)
end
end
context "when bulk upload has log which is not completed" do
before do
create(:lettings_log, :in_progress, bulk_upload:)
end
describe "#send_bulk_upload_with_errors_mail" do
let(:error_description) do
"We created logs from your 2022/23 lettings data. There was a problem with 1 of the logs. Click the below link to fix these logs."
end
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_WITH_ERRORS_TEMPLATE_ID,
personalisation: {
title: "We found 1 log with errors",
filename: bulk_upload.filename,
upload_timestamp: bulk_upload.created_at.to_fs(:govuk_date_and_time),
error_description:,
summary_report_link: "http://localhost:3000/lettings-logs/bulk-upload-results/#{bulk_upload.id}/summary",
},
)
mailer.send_bulk_upload_with_errors_mail(bulk_upload:)
end
end
end
end

Loading…
Cancel
Save