Browse Source

Add mailer methods

pull/1953/head
Kat 3 years ago
parent
commit
2fd259ce74
  1. 18
      app/mailers/csv_download_mailer.rb
  2. 36
      spec/mailers/csv_download_mailer_spec.rb

18
app/mailers/csv_download_mailer.rb

@ -1,5 +1,7 @@
class CsvDownloadMailer < NotifyMailer class CsvDownloadMailer < NotifyMailer
CSV_DOWNLOAD_TEMPLATE_ID = "7890e3b9-8c0d-4d08-bafe-427fd7cd95bf".freeze CSV_DOWNLOAD_TEMPLATE_ID = "7890e3b9-8c0d-4d08-bafe-427fd7cd95bf".freeze
CSV_MISSING_LETTINGS_ADDRESSES_DOWNLOAD_TEMPLATE_ID = "xx".freeze
CSV_MISSING_SALES_ADDRESSES_DOWNLOAD_TEMPLATE_ID = "xx".freeze
def send_csv_download_mail(user, link, duration) def send_csv_download_mail(user, link, duration)
send_email( send_email(
@ -9,7 +11,19 @@ class CsvDownloadMailer < NotifyMailer
) )
end end
def send_missing_lettings_addresses_csv_download_mail(user, link); end def send_missing_lettings_addresses_csv_download_mail(user, link)
send_email(
user.email,
CSV_MISSING_LETTINGS_ADDRESSES_DOWNLOAD_TEMPLATE_ID,
{ name: user.name, link: },
)
end
def send_missing_sales_addresses_csv_download_mail(user, link); end def send_missing_sales_addresses_csv_download_mail(user, link)
send_email(
user.email,
CSV_MISSING_SALES_ADDRESSES_DOWNLOAD_TEMPLATE_ID,
{ name: user.name, link: },
)
end
end end

36
spec/mailers/csv_download_mailer_spec.rb

@ -1,7 +1,6 @@
require "rails_helper" require "rails_helper"
RSpec.describe CsvDownloadMailer do RSpec.describe CsvDownloadMailer do
describe "#send_csv_download_mail" do
let(:notify_client) { instance_double(Notifications::Client) } let(:notify_client) { instance_double(Notifications::Client) }
let(:user) { FactoryBot.create(:user, email: "user@example.com") } let(:user) { FactoryBot.create(:user, email: "user@example.com") }
@ -10,6 +9,7 @@ RSpec.describe CsvDownloadMailer do
allow(notify_client).to receive(:send_email).and_return(true) allow(notify_client).to receive(:send_email).and_return(true)
end end
describe "#send_csv_download_mail" do
it "sends a CSV download E-mail via notify" do it "sends a CSV download E-mail via notify" do
link = :link link = :link
duration = 20.minutes.to_i duration = 20.minutes.to_i
@ -27,4 +27,38 @@ RSpec.describe CsvDownloadMailer do
described_class.new.send_csv_download_mail(user, link, duration) described_class.new.send_csv_download_mail(user, link, duration)
end end
end end
describe "#send_missing_lettings_addresses_csv_download_mail" do
it "sends a CSV download E-mail via notify" do
link = :link
expect(notify_client).to receive(:send_email).with(
email_address: user.email,
template_id: described_class::CSV_MISSING_LETTINGS_ADDRESSES_DOWNLOAD_TEMPLATE_ID,
personalisation: {
name: user.name,
link:,
},
)
described_class.new.send_missing_lettings_addresses_csv_download_mail(user, link)
end
end
describe "#send_missing_sales_addresses_csv_download_mail" do
it "sends a CSV download E-mail via notify" do
link = :link
expect(notify_client).to receive(:send_email).with(
email_address: user.email,
template_id: described_class::CSV_MISSING_SALES_ADDRESSES_DOWNLOAD_TEMPLATE_ID,
personalisation: {
name: user.name,
link:,
},
)
described_class.new.send_missing_sales_addresses_csv_download_mail(user, link)
end
end
end end

Loading…
Cancel
Save