Chore: Minor bugfixes and housekeeping tasks (#896)
This commit is contained in:
parent
93d8a25877
commit
dafabac796
21 changed files with 271 additions and 51 deletions
|
@ -17,7 +17,32 @@ RSpec.describe Conversation, type: :model do
|
|||
|
||||
it 'creates a UUID for every conversation automatically' do
|
||||
uuid_pattern = /[0-9a-f]{8}\b-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-\b[0-9a-f]{12}$/i
|
||||
expect(conversation.uuid).to match(uuid_pattern)
|
||||
expect(conversation.uuid).to match(uuid_pattern)
|
||||
end
|
||||
end
|
||||
|
||||
describe '.after_create' do
|
||||
let(:account) { create(:account) }
|
||||
let(:agent) { create(:user, email: 'agent1@example.com', account: account) }
|
||||
let(:inbox) { create(:inbox, account: account) }
|
||||
let(:conversation) do
|
||||
create(
|
||||
:conversation,
|
||||
account: account,
|
||||
contact: create(:contact, account: account),
|
||||
inbox: inbox,
|
||||
assignee: nil
|
||||
)
|
||||
end
|
||||
|
||||
before do
|
||||
allow(Rails.configuration.dispatcher).to receive(:dispatch)
|
||||
end
|
||||
|
||||
it 'runs after_create callbacks' do
|
||||
# send_events
|
||||
expect(Rails.configuration.dispatcher).to have_received(:dispatch)
|
||||
.with(described_class::CONVERSATION_CREATED, kind_of(Time), conversation: conversation)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -68,7 +93,7 @@ RSpec.describe Conversation, type: :model do
|
|||
end
|
||||
end
|
||||
|
||||
describe '.after_create' do
|
||||
describe '#round robin' do
|
||||
let(:account) { create(:account) }
|
||||
let(:agent) { create(:user, email: 'agent1@example.com', account: account) }
|
||||
let(:inbox) { create(:inbox, account: account) }
|
||||
|
@ -83,15 +108,10 @@ RSpec.describe Conversation, type: :model do
|
|||
end
|
||||
|
||||
before do
|
||||
allow(Rails.configuration.dispatcher).to receive(:dispatch)
|
||||
allow(Redis::Alfred).to receive(:rpoplpush).and_return(agent.id)
|
||||
end
|
||||
|
||||
it 'runs after_create callbacks' do
|
||||
# send_events
|
||||
expect(Rails.configuration.dispatcher).to have_received(:dispatch)
|
||||
.with(described_class::CONVERSATION_CREATED, kind_of(Time), conversation: conversation)
|
||||
|
||||
it 'runs round robin on after_save callbacks' do
|
||||
# run_round_robin
|
||||
expect(conversation.reload.assignee).to eq(agent)
|
||||
end
|
||||
|
@ -99,13 +119,36 @@ RSpec.describe Conversation, type: :model do
|
|||
it 'will not auto assign agent if enable_auto_assignment is false' do
|
||||
inbox.update(enable_auto_assignment: false)
|
||||
|
||||
# send_events
|
||||
expect(Rails.configuration.dispatcher).to have_received(:dispatch)
|
||||
.with(described_class::CONVERSATION_CREATED, kind_of(Time), conversation: conversation)
|
||||
# run_round_robin
|
||||
expect(conversation.reload.assignee).to eq(nil)
|
||||
end
|
||||
|
||||
it 'will not auto assign agent if its a bot conversation' do
|
||||
conversation = create(
|
||||
:conversation,
|
||||
account: account,
|
||||
contact: create(:contact, account: account),
|
||||
inbox: inbox,
|
||||
status: 'bot',
|
||||
assignee: nil
|
||||
)
|
||||
|
||||
# run_round_robin
|
||||
expect(conversation.reload.assignee).to eq(nil)
|
||||
end
|
||||
|
||||
it 'gets triggered on update only when status changes to open' do
|
||||
conversation.status = 'resolved'
|
||||
conversation.save!
|
||||
expect(conversation.reload.assignee).to eq(agent)
|
||||
|
||||
# round robin changes assignee in this case since agent doesn't have access to inbox
|
||||
agent2 = create(:user, email: 'agent2@example.com', account: account)
|
||||
allow(Redis::Alfred).to receive(:rpoplpush).and_return(agent2.id)
|
||||
conversation.status = 'open'
|
||||
conversation.save!
|
||||
expect(conversation.reload.assignee).to eq(agent2)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#update_assignee' do
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue