fix: destroy bulk service (#5921)

This commit is contained in:
Tejaswini Chile
2022-11-25 22:46:50 +05:30
committed by GitHub
parent b05d06a28a
commit fc9fc5a661
6 changed files with 65 additions and 51 deletions

View File

@@ -26,7 +26,9 @@ describe ::NotificationBuilder do
end
it 'will not throw error if notification setting is not present' do
user.account_users.destroy_all
perform_enqueued_jobs do
user.account_users.destroy_all
end
expect(
described_class.new(
notification_type: 'conversation_creation',

View File

@@ -1,7 +1,9 @@
require 'rails_helper'
describe Agents::DestroyService do
let(:account) { create(:account) }
RSpec.describe Agents::DestroyJob, type: :job do
subject(:job) { described_class.perform_later(account, user) }
let!(:account) { create(:account) }
let(:user) { create(:user, account: account) }
let(:team1) { create(:team, account: account) }
let!(:inbox) { create(:inbox, account: account) }
@@ -12,9 +14,16 @@ describe Agents::DestroyService do
create(:conversation, account: account, assignee: user, inbox: inbox)
end
it 'enqueues the job' do
expect { job }.to have_enqueued_job(described_class)
.with(account, user)
.on_queue('default')
end
describe '#perform' do
it 'remove inboxes, teams, and conversations when removed from account' do
described_class.new(account: account, user: user).perform
described_class.perform_now(account, user)
user.reload
expect(user.teams.length).to eq 0
expect(user.inboxes.length).to eq 0

View File

@@ -3,13 +3,10 @@
require 'rails_helper'
RSpec.describe User do
let!(:account_user) { create(:account_user) }
let(:agent_destroy_service) { double }
include ActiveJob::TestHelper
before do
allow(Agents::DestroyService).to receive(:new).and_return(agent_destroy_service)
allow(agent_destroy_service).to receive(:perform).and_return(agent_destroy_service)
end
let!(:account_user) { create(:account_user) }
let!(:inbox) { create(:inbox, account: account_user.account) }
describe 'notification_settings' do
it 'gets created with the right default settings' do
@@ -22,12 +19,16 @@ RSpec.describe User do
describe 'destroy call agent::destroy service' do
it 'gets created with the right default settings' do
create(:conversation, account: account_user.account, assignee: account_user.user, inbox: inbox)
user = account_user.user
account = account_user.account
account_user.destroy!
expect(Agents::DestroyService).to have_received(:new).with({
user: user, account: account
})
expect(user.assigned_conversations.count).to eq(1)
perform_enqueued_jobs do
account_user.destroy!
end
expect(user.assigned_conversations.count).to eq(0)
end
end
end