- Enable the rubocop Rails/FindEach - Replace the .all.each with .find_each This should let us avoid potential memory usage. Motivation from the speedshop newsletter by Nate Berkopec ref: https://www.rubyinrails.com/2017/11/16/use-find-each-instead-of-all-each-in-rails/ ref: https://linear.app/chatwoot/issue/CW-1480/chore-run-all-sidekiq-jobs-async
70 lines
2.2 KiB
Ruby
70 lines
2.2 KiB
Ruby
require 'rails_helper'
|
|
|
|
RSpec.describe BulkActionsJob, type: :job do
|
|
params = {
|
|
type: 'Conversation',
|
|
fields: { status: 'snoozed' },
|
|
ids: Conversation.first(3).pluck(:display_id)
|
|
}
|
|
|
|
subject(:job) { described_class.perform_later(account: account, params: params, user: agent) }
|
|
|
|
let(:account) { create(:account) }
|
|
let!(:agent) { create(:user, account: account, role: :agent) }
|
|
let!(:conversation_1) { create(:conversation, account_id: account.id, status: :open) }
|
|
let!(:conversation_2) { create(:conversation, account_id: account.id, status: :open) }
|
|
let!(:conversation_3) { create(:conversation, account_id: account.id, status: :open) }
|
|
|
|
before do
|
|
Conversation.all.find_each do |conversation|
|
|
create(:inbox_member, inbox: conversation.inbox, user: agent)
|
|
end
|
|
end
|
|
|
|
it 'enqueues the job' do
|
|
expect { job }.to have_enqueued_job(described_class)
|
|
.with(account: account, params: params, user: agent)
|
|
.on_queue('medium')
|
|
end
|
|
|
|
context 'when job is triggered' do
|
|
let(:bulk_action_job) { double }
|
|
|
|
before do
|
|
allow(bulk_action_job).to receive(:perform)
|
|
end
|
|
|
|
it 'bulk updates the status' do
|
|
params = {
|
|
type: 'Conversation',
|
|
fields: { status: 'snoozed', assignee_id: agent.id },
|
|
ids: Conversation.first(3).pluck(:display_id)
|
|
}
|
|
|
|
expect(Conversation.first.status).to eq('open')
|
|
|
|
described_class.perform_now(account: account, params: params, user: agent)
|
|
|
|
expect(conversation_1.reload.status).to eq('snoozed')
|
|
expect(conversation_2.reload.status).to eq('snoozed')
|
|
expect(conversation_3.reload.status).to eq('snoozed')
|
|
end
|
|
|
|
it 'bulk updates the assignee_id' do
|
|
params = {
|
|
type: 'Conversation',
|
|
fields: { status: 'snoozed', assignee_id: agent.id },
|
|
ids: Conversation.first(3).pluck(:display_id)
|
|
}
|
|
|
|
expect(Conversation.first.assignee_id).to be_nil
|
|
|
|
described_class.perform_now(account: account, params: params, user: agent)
|
|
|
|
expect(Conversation.first.assignee_id).to eq(agent.id)
|
|
expect(Conversation.second.assignee_id).to eq(agent.id)
|
|
expect(Conversation.third.assignee_id).to eq(agent.id)
|
|
end
|
|
end
|
|
end
|