From e0f547d9cffd23adb78ce28f0726b7ea1a4fb972 Mon Sep 17 00:00:00 2001 From: Jack S Date: Fri, 16 Jun 2023 12:51:42 +0100 Subject: [PATCH] Add mailer --- .../data_protection_confirmation_mailer.rb | 15 +++++++++++ ...ata_protection_confirmation_mailer_spec.rb | 27 +++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 app/mailers/data_protection_confirmation_mailer.rb create mode 100644 spec/mailers/data_protection_confirmation_mailer_spec.rb diff --git a/app/mailers/data_protection_confirmation_mailer.rb b/app/mailers/data_protection_confirmation_mailer.rb new file mode 100644 index 000000000..eaa8fde9a --- /dev/null +++ b/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 diff --git a/spec/mailers/data_protection_confirmation_mailer_spec.rb b/spec/mailers/data_protection_confirmation_mailer_spec.rb new file mode 100644 index 000000000..57e62f361 --- /dev/null +++ b/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