Browse Source

Add mailer

pull/1710/head
Jack S 3 years ago
parent
commit
e0f547d9cf
  1. 15
      app/mailers/data_protection_confirmation_mailer.rb
  2. 27
      spec/mailers/data_protection_confirmation_mailer_spec.rb

15
app/mailers/data_protection_confirmation_mailer.rb

@ -0,0 +1,15 @@
class DataProtectionConfirmationMailer < NotifyMailer
include Rails.application.routes.url_helpers
EMAIL_TEMPLATE_ID = "3dbf78fe-a2c8-4d65-aa19-e4d62695d4a9".freeze
def send_confirmation_email(user)
send_email(
user.email,
EMAIL_TEMPLATE_ID,
{
organisation_name: user.organisation.name,
link: data_sharing_agreement_organisation_url(user.organisation),
},
)
end
end

27
spec/mailers/data_protection_confirmation_mailer_spec.rb

@ -0,0 +1,27 @@
require "rails_helper"
RSpec.describe DataProtectionConfirmationMailer do
describe "#send_csv_download_mail" do
let(:notify_client) { instance_double(Notifications::Client) }
let(:user) { create(:user, email: "user@example.com") }
let(:organisation) { user.organisation }
before do
allow(Notifications::Client).to receive(:new).and_return(notify_client)
allow(notify_client).to receive(:send_email).and_return(true)
end
it "sends confirmation email to user" do
expect(notify_client).to receive(:send_email).with(
email_address: user.email,
template_id: "3dbf78fe-a2c8-4d65-aa19-e4d62695d4a9",
personalisation: {
organisation_name: organisation.name,
link: "#{ENV['APP_HOST']}/organisations/#{organisation.id}/data-sharing-agreement",
},
)
described_class.new.send_confirmation_email(user)
end
end
end
Loading…
Cancel
Save