Browse Source

feat: only send dsa confirm email to new dpo when it isn't already confirmed (#1947)

pull/1945/head
natdeanlewissoftwire 1 year ago committed by GitHub
parent
commit
bff55e37d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      app/models/user.rb
  2. 24
      spec/models/user_spec.rb

1
app/models/user.rb

@ -231,6 +231,7 @@ private
def send_data_protection_confirmation_reminder def send_data_protection_confirmation_reminder
return unless persisted? return unless persisted?
return unless is_dpo? return unless is_dpo?
return if organisation.data_protection_confirmed?
DataProtectionConfirmationMailer.send_confirmation_email(self).deliver_later DataProtectionConfirmationMailer.send_confirmation_email(self).deliver_later
end end

24
spec/models/user_spec.rb

@ -445,13 +445,23 @@ RSpec.describe User, type: :model do
context "when updating to dpo" do context "when updating to dpo" do
let!(:user) { create(:user, is_dpo: false) } let!(:user) { create(:user, is_dpo: false) }
it "sends the email" do context "when data_protection_confirmed? is false" do
expect { user.update!(is_dpo: true) }.to enqueue_job(ActionMailer::MailDeliveryJob).with( it "sends the email" do
"DataProtectionConfirmationMailer", allow(user.organisation).to receive(:data_protection_confirmed?).and_return(false)
"send_confirmation_email", expect { user.update!(is_dpo: true) }.to enqueue_job(ActionMailer::MailDeliveryJob).with(
"deliver_now", "DataProtectionConfirmationMailer",
args: [user], "send_confirmation_email",
) "deliver_now",
args: [user],
)
end
end
context "when data_protection_confirmed? is true" do
it "does not send the email" do
allow(user.organisation).to receive(:data_protection_confirmed?).and_return(true)
expect { user.update!(is_dpo: true) }.not_to enqueue_job(ActionMailer::MailDeliveryJob)
end
end end
end end

Loading…
Cancel
Save