chore: Destroy account inboxes asynchronously

This commit is contained in:
Tejaswini 2021-11-08 15:55:54 +05:30
parent 26f36548c2
commit 10a13c3f5c
2 changed files with 19 additions and 2 deletions

View file

@ -38,7 +38,7 @@ class Account < ApplicationRecord
has_many :csat_survey_responses, dependent: :destroy
has_many :data_imports, dependent: :destroy
has_many :users, through: :account_users
has_many :inboxes, dependent: :destroy
has_many :inboxes, dependent: :destroy_async
has_many :notes, dependent: :destroy
has_many :campaigns, dependent: :destroy
has_many :conversations, dependent: :destroy

View file

@ -8,7 +8,7 @@ RSpec.describe Account do
it { is_expected.to have_many(:users).through(:account_users) }
it { is_expected.to have_many(:account_users) }
it { is_expected.to have_many(:inboxes).dependent(:destroy) }
it { is_expected.to have_many(:inboxes).dependent(:destroy_async) }
it { is_expected.to have_many(:conversations).dependent(:destroy) }
it { is_expected.to have_many(:contacts).dependent(:destroy) }
it { is_expected.to have_many(:telegram_bots).dependent(:destroy) }
@ -21,4 +21,21 @@ RSpec.describe Account do
it { is_expected.to have_many(:kbase_portals).dependent(:destroy) }
it { is_expected.to have_many(:kbase_categories).dependent(:destroy) }
it { is_expected.to have_many(:teams).dependent(:destroy) }
context 'when destroy async' do
include ActiveJob::TestHelper
it 'Associated inboxes' do
account = FactoryBot.create(:account)
FactoryBot.create(:inbox, account: account)
expect(account.inboxes.count).to be(1)
account.destroy
assert_enqueued_jobs 2
expect(account.inboxes.count).to be(0)
end
end
end