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. 10
      spec/models/user_spec.rb

1
app/models/user.rb

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

10
spec/models/user_spec.rb

@ -445,7 +445,9 @@ RSpec.describe User, type: :model do
context "when updating to dpo" do
let!(:user) { create(:user, is_dpo: false) }
context "when data_protection_confirmed? is false" do
it "sends the email" do
allow(user.organisation).to receive(:data_protection_confirmed?).and_return(false)
expect { user.update!(is_dpo: true) }.to enqueue_job(ActionMailer::MailDeliveryJob).with(
"DataProtectionConfirmationMailer",
"send_confirmation_email",
@ -455,6 +457,14 @@ RSpec.describe User, type: :model do
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
context "when updating to non dpo" do
let!(:user) { create(:user, is_dpo: true) }

Loading…
Cancel
Save