feat: Ability to delete account for administrators (#1874)

## Description

Add account delete option in the user account settings.

Fixes #1555 

## Type of change

- [ ] New feature (non-breaking change which adds functionality)


![image](https://user-images.githubusercontent.com/40784971/110349673-edcc5200-8058-11eb-8ded-a31d15aa0759.png)

![image](https://user-images.githubusercontent.com/40784971/110349778-0c324d80-8059-11eb-9291-abfbffedde5e.png)


## Checklist:

- [ ] My code follows the style guidelines of this project
- [ ] I have performed a self-review of my own code
- [ ] I have commented on my code, particularly in hard-to-understand
areas
- [ ] I have made corresponding changes to the documentation
- [ ] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [ ] New and existing unit tests pass locally with my changes
- [ ] Any dependent changes have been merged and published in downstream
modules

---------

Co-authored-by: Sojan Jose <sojan@pepalo.com>
Co-authored-by: Sojan Jose <sojan.official@gmail.com>
Co-authored-by: Muhsin Keloth <muhsinkeramam@gmail.com>
This commit is contained in:
Pranjal Kushwaha
2025-04-03 10:41:39 +05:30
committed by GitHub
parent 8bf2081aff
commit 0dc2af3c78
37 changed files with 1030 additions and 311 deletions

View File

@@ -2,9 +2,9 @@ require 'rails_helper'
shared_examples_for 'reauthorizable' do
let(:model) { described_class } # the class that includes the concern
let(:obj) { FactoryBot.create(model.to_s.underscore.tr('/', '_').to_sym) }
it 'authorization_error!' do
obj = FactoryBot.create(model.to_s.underscore.tr('/', '_').to_sym)
expect(obj.authorization_error_count).to eq 0
obj.authorization_error!
@@ -13,7 +13,6 @@ shared_examples_for 'reauthorizable' do
end
it 'prompts reauthorization when error threshold is passed' do
obj = FactoryBot.create(model.to_s.underscore.tr('/', '_').to_sym)
expect(obj.reauthorization_required?).to be false
obj.class::AUTHORIZATION_ERROR_THRESHOLD.times do
@@ -23,25 +22,70 @@ shared_examples_for 'reauthorizable' do
expect(obj.reauthorization_required?).to be true
end
it 'prompt_reauthorization!' do
obj = FactoryBot.create(model.to_s.underscore.tr('/', '_').to_sym)
mailer = double
mailer_method = double
allow(AdministratorNotifications::ChannelNotificationsMailer).to receive(:with).and_return(mailer)
# allow mailer to receive any methods and return mailer
allow(mailer).to receive(:method_missing).and_return(mailer_method)
allow(mailer_method).to receive(:deliver_later)
# Helper methods to set up mailer mocks
def setup_automation_rule_mailer(_obj)
account_mailer = instance_double(AdministratorNotifications::AccountNotificationMailer)
automation_mailer_response = instance_double(ActionMailer::MessageDelivery, deliver_later: true)
allow(AdministratorNotifications::AccountNotificationMailer).to receive(:with).and_return(account_mailer)
allow(account_mailer).to receive(:automation_rule_disabled).and_return(automation_mailer_response)
end
expect(obj.reauthorization_required?).to be false
def setup_integrations_hook_mailer(obj)
integrations_mailer = instance_double(AdministratorNotifications::IntegrationsNotificationMailer)
slack_mailer_response = instance_double(ActionMailer::MessageDelivery, deliver_later: true)
dialogflow_mailer_response = instance_double(ActionMailer::MessageDelivery, deliver_later: true)
allow(AdministratorNotifications::IntegrationsNotificationMailer).to receive(:with).and_return(integrations_mailer)
allow(integrations_mailer).to receive(:slack_disconnect).and_return(slack_mailer_response)
allow(integrations_mailer).to receive(:dialogflow_disconnect).and_return(dialogflow_mailer_response)
obj.prompt_reauthorization!
expect(obj.reauthorization_required?).to be true
expect(AdministratorNotifications::ChannelNotificationsMailer).to have_received(:with).with(account: obj.account)
expect(mailer_method).to have_received(:deliver_later)
# Allow the model to respond to slack? and dialogflow? methods
allow(obj).to receive(:slack?).and_return(true)
allow(obj).to receive(:dialogflow?).and_return(false)
end
def setup_channel_mailer(_obj)
channel_mailer = instance_double(AdministratorNotifications::ChannelNotificationsMailer)
facebook_mailer_response = instance_double(ActionMailer::MessageDelivery, deliver_later: true)
whatsapp_mailer_response = instance_double(ActionMailer::MessageDelivery, deliver_later: true)
email_mailer_response = instance_double(ActionMailer::MessageDelivery, deliver_later: true)
allow(AdministratorNotifications::ChannelNotificationsMailer).to receive(:with).and_return(channel_mailer)
allow(channel_mailer).to receive(:facebook_disconnect).and_return(facebook_mailer_response)
allow(channel_mailer).to receive(:whatsapp_disconnect).and_return(whatsapp_mailer_response)
allow(channel_mailer).to receive(:email_disconnect).and_return(email_mailer_response)
end
describe 'prompt_reauthorization!' do
before do
# Setup mailer mocks based on model type
if model.to_s == 'AutomationRule'
setup_automation_rule_mailer(obj)
elsif model.to_s == 'Integrations::Hook'
setup_integrations_hook_mailer(obj)
else
setup_channel_mailer(obj)
end
end
it 'sets reauthorization required flag' do
expect(obj.reauthorization_required?).to be false
obj.prompt_reauthorization!
expect(obj.reauthorization_required?).to be true
end
it 'calls the correct mailer based on model type' do
obj.prompt_reauthorization!
if model.to_s == 'AutomationRule'
expect(AdministratorNotifications::AccountNotificationMailer).to have_received(:with).with(account: obj.account)
elsif model.to_s == 'Integrations::Hook'
expect(AdministratorNotifications::IntegrationsNotificationMailer).to have_received(:with).with(account: obj.account)
else
expect(AdministratorNotifications::ChannelNotificationsMailer).to have_received(:with).with(account: obj.account)
end
end
end
it 'reauthorized!' do
obj = FactoryBot.create(model.to_s.underscore.tr('/', '_').to_sym)
# setting up the object with the errors to validate its cleared on action
obj.authorization_error!
obj.prompt_reauthorization!