Browse Source

Add mailer methods

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

18
app/mailers/csv_download_mailer.rb

@ -1,5 +1,7 @@
class CsvDownloadMailer < NotifyMailer
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)
send_email(
@ -9,7 +11,19 @@ class CsvDownloadMailer < NotifyMailer
)
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

48
spec/mailers/csv_download_mailer_spec.rb

@ -1,15 +1,15 @@
require "rails_helper"
RSpec.describe CsvDownloadMailer do
describe "#send_csv_download_mail" do
let(:notify_client) { instance_double(Notifications::Client) }
let(:user) { FactoryBot.create(:user, email: "user@example.com") }
let(:notify_client) { instance_double(Notifications::Client) }
let(:user) { FactoryBot.create(:user, email: "user@example.com") }
before do
allow(Notifications::Client).to receive(:new).and_return(notify_client)
allow(notify_client).to receive(:send_email).and_return(true)
end
before do
allow(Notifications::Client).to receive(:new).and_return(notify_client)
allow(notify_client).to receive(:send_email).and_return(true)
end
describe "#send_csv_download_mail" do
it "sends a CSV download E-mail via notify" do
link = :link
duration = 20.minutes.to_i
@ -27,4 +27,38 @@ RSpec.describe CsvDownloadMailer do
described_class.new.send_csv_download_mail(user, link, duration)
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

Loading…
Cancel
Save