diff --git a/app/models/user.rb b/app/models/user.rb index 5b7ec3e2f..c6deed8a1 100644 --- a/app/models/user.rb +++ b/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 diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 32ba7bb10..63ea72dca 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -445,13 +445,23 @@ RSpec.describe User, type: :model do context "when updating to dpo" do let!(:user) { create(:user, is_dpo: false) } - it "sends the email" do - expect { user.update!(is_dpo: true) }.to enqueue_job(ActionMailer::MailDeliveryJob).with( - "DataProtectionConfirmationMailer", - "send_confirmation_email", - "deliver_now", - args: [user], - ) + 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", + "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