Browse Source

add how to fix bulk upload mailer

bulk-upload-resume
Phil Lee 2 years ago
parent
commit
e13e75b638
  1. 39
      app/mailers/bulk_upload_mailer.rb
  2. 10
      spec/mailers/bulk_upload_mailer_spec.rb

39
app/mailers/bulk_upload_mailer.rb

@ -1,11 +1,30 @@
class BulkUploadMailer < NotifyMailer
include ActionView::Helpers::TextHelper
BULK_UPLOAD_COMPLETE_TEMPLATE_ID = "83279578-c890-4168-838b-33c9cf0dc9f0".freeze
BULK_UPLOAD_FAILED_CSV_ERRORS_TEMPLATE_ID = "e27abcd4-5295-48c2-b127-e9ee4b781b75".freeze
BULK_UPLOAD_FAILED_FILE_SETUP_ERROR_TEMPLATE_ID = "24c9f4c7-96ad-470a-ba31-eb51b7cbafd9".freeze
BULK_UPLOAD_FAILED_SERVICE_ERROR_TEMPLATE_ID = "c3f6288c-7a74-4e77-99ee-6c4a0f6e125a".freeze
BULK_UPLOAD_WITH_ERRORS_TEMPLATE_ID = "eb539005-6234-404e-812d-167728cf4274".freeze
COMPLETE_TEMPLATE_ID = "83279578-c890-4168-838b-33c9cf0dc9f0".freeze
FAILED_CSV_ERRORS_TEMPLATE_ID = "e27abcd4-5295-48c2-b127-e9ee4b781b75".freeze
FAILED_FILE_SETUP_ERROR_TEMPLATE_ID = "24c9f4c7-96ad-470a-ba31-eb51b7cbafd9".freeze
FAILED_SERVICE_ERROR_TEMPLATE_ID = "c3f6288c-7a74-4e77-99ee-6c4a0f6e125a".freeze
WITH_ERRORS_TEMPLATE_ID = "eb539005-6234-404e-812d-167728cf4274".freeze
HOW_FIX_UPLOAD_TEMPLATE_ID = "21a07b26-f625-4846-9f4d-39e30937aa24".freeze
def send_how_fix_upload_mail(bulk_upload:)
title = "We found #{pluralize(bulk_upload.bulk_upload_errors.count, 'error')} in your bulk upload"
description = "There was a problem with your #{bulk_upload.year_combo} #{bulk_upload.log_type} data. Check the error report below to fix these errors."
cta_link = start_bulk_upload_lettings_resume_url(bulk_upload)
send_email(
bulk_upload.user.email,
HOW_FIX_UPLOAD_TEMPLATE_ID,
{
title:,
filename: bulk_upload.filename,
upload_timestamp: bulk_upload.created_at.to_fs(:govuk_date_and_time),
description:,
cta_link:,
},
)
end
def send_bulk_upload_complete_mail(user:, bulk_upload:)
url = if bulk_upload.lettings?
@ -22,7 +41,7 @@ class BulkUploadMailer < NotifyMailer
send_email(
user.email,
BULK_UPLOAD_COMPLETE_TEMPLATE_ID,
COMPLETE_TEMPLATE_ID,
{
title:,
filename: bulk_upload.filename,
@ -42,7 +61,7 @@ class BulkUploadMailer < NotifyMailer
send_email(
bulk_upload.user.email,
BULK_UPLOAD_FAILED_CSV_ERRORS_TEMPLATE_ID,
FAILED_CSV_ERRORS_TEMPLATE_ID,
{
filename: bulk_upload.filename,
upload_timestamp: bulk_upload.created_at.to_fs(:govuk_date_and_time),
@ -75,7 +94,7 @@ class BulkUploadMailer < NotifyMailer
send_email(
bulk_upload.user.email,
BULK_UPLOAD_FAILED_FILE_SETUP_ERROR_TEMPLATE_ID,
FAILED_FILE_SETUP_ERROR_TEMPLATE_ID,
{
filename: bulk_upload.filename,
upload_timestamp: bulk_upload.created_at.to_fs(:govuk_date_and_time),
@ -96,7 +115,7 @@ class BulkUploadMailer < NotifyMailer
send_email(
bulk_upload.user.email,
BULK_UPLOAD_FAILED_SERVICE_ERROR_TEMPLATE_ID,
FAILED_SERVICE_ERROR_TEMPLATE_ID,
{
filename: bulk_upload.filename,
upload_timestamp: bulk_upload.created_at.to_fs(:govuk_date_and_time),
@ -119,7 +138,7 @@ class BulkUploadMailer < NotifyMailer
send_email(
bulk_upload.user.email,
BULK_UPLOAD_WITH_ERRORS_TEMPLATE_ID,
WITH_ERRORS_TEMPLATE_ID,
{
title:,
filename: bulk_upload.filename,

10
spec/mailers/bulk_upload_mailer_spec.rb

@ -29,7 +29,7 @@ RSpec.describe BulkUploadMailer 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,
template_id: described_class::FAILED_FILE_SETUP_ERROR_TEMPLATE_ID,
personalisation: {
filename: bulk_upload.filename,
upload_timestamp: bulk_upload.created_at.to_fs(:govuk_date_and_time),
@ -48,7 +48,7 @@ RSpec.describe BulkUploadMailer do
it "sends correctly formed email" do
expect(notify_client).to receive(:send_email).with(
email_address: user.email,
template_id: described_class::BULK_UPLOAD_COMPLETE_TEMPLATE_ID,
template_id: described_class::COMPLETE_TEMPLATE_ID,
personalisation: {
title: "You’ve successfully uploaded 0 logs",
filename: bulk_upload.filename,
@ -66,7 +66,7 @@ RSpec.describe BulkUploadMailer do
it "sends correctly formed email" do
expect(notify_client).to receive(:send_email).with(
email_address: user.email,
template_id: described_class::BULK_UPLOAD_FAILED_SERVICE_ERROR_TEMPLATE_ID,
template_id: described_class::FAILED_SERVICE_ERROR_TEMPLATE_ID,
personalisation: {
filename: bulk_upload.filename,
upload_timestamp: bulk_upload.created_at.to_fs(:govuk_date_and_time),
@ -94,7 +94,7 @@ RSpec.describe BulkUploadMailer 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_WITH_ERRORS_TEMPLATE_ID,
template_id: described_class::WITH_ERRORS_TEMPLATE_ID,
personalisation: {
title: "We found 1 log with errors",
filename: bulk_upload.filename,
@ -119,7 +119,7 @@ RSpec.describe BulkUploadMailer do
it "sends correctly formed email" do
expect(notify_client).to receive(:send_email).with(
email_address: user.email,
template_id: described_class::BULK_UPLOAD_FAILED_CSV_ERRORS_TEMPLATE_ID,
template_id: described_class::FAILED_CSV_ERRORS_TEMPLATE_ID,
personalisation: {
filename: bulk_upload.filename,
upload_timestamp: bulk_upload.created_at.to_fs(:govuk_date_and_time),

Loading…
Cancel
Save