2021-02-15 08:02:52 +00:00
|
|
|
require 'rails_helper'
|
|
|
|
|
2022-11-25 17:16:50 +00:00
|
|
|
RSpec.describe Agents::DestroyJob, type: :job do
|
|
|
|
subject(:job) { described_class.perform_later(account, user) }
|
|
|
|
|
|
|
|
let!(:account) { create(:account) }
|
2021-02-15 08:02:52 +00:00
|
|
|
let(:user) { create(:user, account: account) }
|
|
|
|
let(:team1) { create(:team, account: account) }
|
|
|
|
let!(:inbox) { create(:inbox, account: account) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
create(:team_member, team: team1, user: user)
|
|
|
|
create(:inbox_member, inbox: inbox, user: user)
|
2022-09-20 01:14:55 +00:00
|
|
|
create(:conversation, account: account, assignee: user, inbox: inbox)
|
2021-02-15 08:02:52 +00:00
|
|
|
end
|
|
|
|
|
2022-11-25 17:16:50 +00:00
|
|
|
it 'enqueues the job' do
|
|
|
|
expect { job }.to have_enqueued_job(described_class)
|
|
|
|
.with(account, user)
|
|
|
|
.on_queue('default')
|
|
|
|
end
|
|
|
|
|
2021-02-15 08:02:52 +00:00
|
|
|
describe '#perform' do
|
2022-09-20 01:14:55 +00:00
|
|
|
it 'remove inboxes, teams, and conversations when removed from account' do
|
2022-11-25 17:16:50 +00:00
|
|
|
described_class.perform_now(account, user)
|
|
|
|
|
2021-02-15 08:02:52 +00:00
|
|
|
user.reload
|
|
|
|
expect(user.teams.length).to eq 0
|
|
|
|
expect(user.inboxes.length).to eq 0
|
|
|
|
expect(user.notification_settings.length).to eq 0
|
2022-09-20 01:14:55 +00:00
|
|
|
expect(user.assigned_conversations.where(account: account).length).to eq 0
|
2021-02-15 08:02:52 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|