chore: Update account deletion email copy (#12317)
Update the email copies for account deletion emails ## Manual Deletion <img width="1378" height="678" alt="Screenshot 2025-08-29 at 2 41 40 PM" src="https://github.com/user-attachments/assets/63d7ad97-ad51-4a8b-9ef3-d427fa467f8a" /> ## Inactive Deletion <img width="2946" height="1808" alt="image" src="https://github.com/user-attachments/assets/bb50d08c-8701-4f93-af29-0b1d948a4009" /> --------- Co-authored-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: Sojan Jose <sojan@pepalo.com>
This commit is contained in:
@@ -229,18 +229,27 @@ RSpec.describe Account, type: :model do
|
||||
describe '#mark_for_deletion' do
|
||||
it 'sets the marked_for_deletion_at and marked_for_deletion_reason attributes' do
|
||||
expect do
|
||||
account.mark_for_deletion('test_reason')
|
||||
account.mark_for_deletion('inactivity')
|
||||
end.to change { account.reload.custom_attributes['marked_for_deletion_at'] }.from(nil).to(be_present)
|
||||
.and change { account.reload.custom_attributes['marked_for_deletion_reason'] }.from(nil).to('test_reason')
|
||||
.and change { account.reload.custom_attributes['marked_for_deletion_reason'] }.from(nil).to('inactivity')
|
||||
end
|
||||
|
||||
it 'sends a notification email to admin users' do
|
||||
it 'sends a user-initiated deletion email when reason is manual_deletion' do
|
||||
mailer = double
|
||||
expect(AdministratorNotifications::AccountNotificationMailer).to receive(:with).with(account: account).and_return(mailer)
|
||||
expect(mailer).to receive(:account_deletion).with(account, 'test_reason').and_return(mailer)
|
||||
expect(mailer).to receive(:account_deletion_user_initiated).with(account, 'manual_deletion').and_return(mailer)
|
||||
expect(mailer).to receive(:deliver_later)
|
||||
|
||||
account.mark_for_deletion('test_reason')
|
||||
account.mark_for_deletion('manual_deletion')
|
||||
end
|
||||
|
||||
it 'sends a system-initiated deletion email when reason is not manual_deletion' do
|
||||
mailer = double
|
||||
expect(AdministratorNotifications::AccountNotificationMailer).to receive(:with).with(account: account).and_return(mailer)
|
||||
expect(mailer).to receive(:account_deletion_for_inactivity).with(account, 'inactivity').and_return(mailer)
|
||||
expect(mailer).to receive(:deliver_later)
|
||||
|
||||
account.mark_for_deletion('inactivity')
|
||||
end
|
||||
|
||||
it 'returns true when successful' do
|
||||
|
||||
@@ -1,116 +1,46 @@
|
||||
require 'rails_helper'
|
||||
require Rails.root.join 'spec/mailers/administrator_notifications/shared/smtp_config_shared.rb'
|
||||
|
||||
RSpec.describe AdministratorNotifications::AccountNotificationMailer do
|
||||
include_context 'with smtp config'
|
||||
let(:account) { create(:account, name: 'Test Account') }
|
||||
let(:mailer) { described_class.with(account: account) }
|
||||
let(:class_instance) { described_class.new }
|
||||
|
||||
let!(:account) { create(:account) }
|
||||
let!(:admin) { create(:user, account: account, role: :administrator) }
|
||||
before do
|
||||
allow(described_class).to receive(:new).and_return(class_instance)
|
||||
allow(class_instance).to receive(:smtp_config_set_or_development?).and_return(true)
|
||||
account.custom_attributes['marked_for_deletion_at'] = 7.days.from_now.iso8601
|
||||
account.save!
|
||||
end
|
||||
|
||||
describe 'account_deletion' do
|
||||
let(:reason) { 'manual_deletion' }
|
||||
let(:mail) { described_class.with(account: account).account_deletion(account, reason) }
|
||||
let(:deletion_date) { 7.days.from_now.iso8601 }
|
||||
|
||||
before do
|
||||
account.update!(custom_attributes: {
|
||||
'marked_for_deletion_at' => deletion_date,
|
||||
'marked_for_deletion_reason' => reason
|
||||
})
|
||||
end
|
||||
|
||||
it 'renders the subject' do
|
||||
expect(mail.subject).to eq('Your account has been marked for deletion')
|
||||
end
|
||||
|
||||
it 'renders the receiver email' do
|
||||
expect(mail.to).to eq([admin.email])
|
||||
end
|
||||
|
||||
it 'includes the account name in the email body' do
|
||||
expect(mail.body.encoded).to include(account.name)
|
||||
end
|
||||
|
||||
it 'includes the deletion date in the email body' do
|
||||
expect(mail.body.encoded).to include(deletion_date)
|
||||
end
|
||||
|
||||
it 'includes a link to cancel the deletion' do
|
||||
expect(mail.body.encoded).to include('Cancel Account Deletion')
|
||||
end
|
||||
|
||||
context 'when reason is manual_deletion' do
|
||||
it 'includes the administrator message' do
|
||||
expect(mail.body.encoded).to include('This action was requested by one of the administrators of your account')
|
||||
end
|
||||
end
|
||||
|
||||
context 'when reason is not manual_deletion' do
|
||||
let(:reason) { 'inactivity' }
|
||||
|
||||
it 'includes the reason directly' do
|
||||
expect(mail.body.encoded).to include('Reason for deletion: inactivity')
|
||||
end
|
||||
describe '#account_deletion_user_initiated' do
|
||||
it 'sets the correct subject for user-initiated deletion' do
|
||||
mail = mailer.account_deletion_user_initiated(account, 'manual_deletion')
|
||||
expect(mail.subject).to eq('Your Chatwoot account deletion has been scheduled')
|
||||
end
|
||||
end
|
||||
|
||||
describe 'contact_import_complete' do
|
||||
let!(:data_import) { build(:data_import, total_records: 10, processed_records: 8) }
|
||||
let(:mail) { described_class.with(account: account).contact_import_complete(data_import).deliver_now }
|
||||
|
||||
it 'renders the subject' do
|
||||
expect(mail.subject).to eq('Contact Import Completed')
|
||||
end
|
||||
|
||||
it 'renders the processed records' do
|
||||
expect(mail.body.encoded).to include('Number of records imported: 8')
|
||||
expect(mail.body.encoded).to include('Number of records failed: 2')
|
||||
end
|
||||
|
||||
it 'renders the receiver email' do
|
||||
expect(mail.to).to eq([admin.email])
|
||||
describe '#account_deletion_for_inactivity' do
|
||||
it 'sets the correct subject for system-initiated deletion' do
|
||||
mail = mailer.account_deletion_for_inactivity(account, 'Account Inactive')
|
||||
expect(mail.subject).to eq('Your Chatwoot account is scheduled for deletion due to inactivity')
|
||||
end
|
||||
end
|
||||
|
||||
describe 'contact_import_failed' do
|
||||
let(:mail) { described_class.with(account: account).contact_import_failed.deliver_now }
|
||||
|
||||
it 'renders the subject' do
|
||||
expect(mail.subject).to eq('Contact Import Failed')
|
||||
describe '#format_deletion_date' do
|
||||
it 'formats a valid date string' do
|
||||
date_str = '2024-12-31T23:59:59Z'
|
||||
formatted = described_class.new.send(:format_deletion_date, date_str)
|
||||
expect(formatted).to eq('December 31, 2024')
|
||||
end
|
||||
|
||||
it 'renders the receiver email' do
|
||||
expect(mail.to).to eq([admin.email])
|
||||
end
|
||||
end
|
||||
|
||||
describe 'contact_export_complete' do
|
||||
let!(:file_url) { 'http://test.com/test' }
|
||||
let(:mail) { described_class.with(account: account).contact_export_complete(file_url, admin.email).deliver_now }
|
||||
|
||||
it 'renders the subject' do
|
||||
expect(mail.subject).to eq("Your contact's export file is available to download.")
|
||||
it 'handles blank dates' do
|
||||
formatted = described_class.new.send(:format_deletion_date, nil)
|
||||
expect(formatted).to eq('Unknown')
|
||||
end
|
||||
|
||||
it 'renders the receiver email' do
|
||||
expect(mail.to).to eq([admin.email])
|
||||
end
|
||||
end
|
||||
|
||||
describe 'automation_rule_disabled' do
|
||||
let(:rule) { instance_double(AutomationRule, name: 'Test Rule') }
|
||||
let(:mail) { described_class.with(account: account).automation_rule_disabled(rule).deliver_now }
|
||||
|
||||
it 'renders the subject' do
|
||||
expect(mail.subject).to eq('Automation rule disabled due to validation errors.')
|
||||
end
|
||||
|
||||
it 'renders the receiver email' do
|
||||
expect(mail.to).to eq([admin.email])
|
||||
end
|
||||
|
||||
it 'includes the rule name in the email body' do
|
||||
expect(mail.body.encoded).to include('Test Rule')
|
||||
it 'handles invalid dates' do
|
||||
formatted = described_class.new.send(:format_deletion_date, 'invalid-date')
|
||||
expect(formatted).to eq('Unknown')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user