feat (ee): APIs to configure an auto assignment limit for inboxes (#4672)
Co-authored-by: Pranav Raj S <pranav@chatwoot.com>
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe 'Enterprise Inboxes API', type: :request do
|
||||
let(:account) { create(:account) }
|
||||
let(:admin) { create(:user, account: account, role: :administrator) }
|
||||
|
||||
describe 'POST /api/v1/accounts/{account.id}/inboxes' do
|
||||
let(:inbox) { create(:inbox, account: account) }
|
||||
|
||||
context 'when it is an authenticated user' do
|
||||
let(:admin) { create(:user, account: account, role: :administrator) }
|
||||
let(:valid_params) do
|
||||
{ name: 'test', auto_assignment_config: { max_assignment_limit: 10 }, channel: { type: 'web_widget', website_url: 'test.com' } }
|
||||
end
|
||||
|
||||
it 'creates a webwidget inbox with auto assignment config' do
|
||||
post "/api/v1/accounts/#{account.id}/inboxes",
|
||||
headers: admin.create_new_auth_token,
|
||||
params: valid_params,
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
expect(JSON.parse(response.body)['auto_assignment_config']['max_assignment_limit']).to eq 10
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'PATCH /api/v1/accounts/{account.id}/inboxes/:id' do
|
||||
let(:inbox) { create(:inbox, account: account, auto_assignment_config: { max_assignment_limit: 5 }) }
|
||||
|
||||
context 'when it is an authenticated user' do
|
||||
let(:admin) { create(:user, account: account, role: :administrator) }
|
||||
let(:valid_params) { { name: 'new test inbox', auto_assignment_config: { max_assignment_limit: 10 } } }
|
||||
|
||||
it 'updates inbox with auto assignment config' do
|
||||
patch "/api/v1/accounts/#{account.id}/inboxes/#{inbox.id}",
|
||||
headers: admin.create_new_auth_token,
|
||||
params: valid_params,
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
expect(JSON.parse(response.body)['auto_assignment_config']['max_assignment_limit']).to eq 10
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
38
spec/enterprise/models/inbox_spec.rb
Normal file
38
spec/enterprise/models/inbox_spec.rb
Normal file
@@ -0,0 +1,38 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Inbox do
|
||||
describe 'member_ids_with_assignment_capacity' do
|
||||
let!(:inbox) { create(:inbox) }
|
||||
let!(:inbox_member_1) { create(:inbox_member, inbox: inbox) }
|
||||
let!(:inbox_member_2) { create(:inbox_member, inbox: inbox) }
|
||||
let!(:inbox_member_3) { create(:inbox_member, inbox: inbox) }
|
||||
let!(:inbox_member_4) { create(:inbox_member, inbox: inbox) }
|
||||
|
||||
before do
|
||||
create(:conversation, inbox: inbox, assignee: inbox_member_1.user)
|
||||
# to test conversations in other inboxes won't impact
|
||||
create_list(:conversation, 3, assignee: inbox_member_1.user)
|
||||
create_list(:conversation, 2, inbox: inbox, assignee: inbox_member_2.user)
|
||||
create_list(:conversation, 3, inbox: inbox, assignee: inbox_member_3.user)
|
||||
end
|
||||
|
||||
it 'validated max_assignment_limit' do
|
||||
account = create(:account)
|
||||
expect(build(:inbox, account: account, auto_assignment_config: { max_assignment_limit: 0 })).not_to be_valid
|
||||
expect(build(:inbox, account: account, auto_assignment_config: {})).to be_valid
|
||||
expect(build(:inbox, account: account, auto_assignment_config: { max_assignment_limit: 1 })).to be_valid
|
||||
end
|
||||
|
||||
it 'returns member ids with assignment capacity with inbox max_assignment_limit is configured' do
|
||||
# agent 1 has 1 conversations, agent 2 has 2 conversations, agent 3 has 3 conversations and agent 4 with none
|
||||
inbox.update(auto_assignment_config: { max_assignment_limit: 2 })
|
||||
expect(inbox.member_ids_with_assignment_capacity).to contain_exactly(inbox_member_1.user_id, inbox_member_4.user_id)
|
||||
end
|
||||
|
||||
it 'returns all member ids when inbox max_assignment_limit is not configured' do
|
||||
expect(inbox.member_ids_with_assignment_capacity).to eq(inbox.members.ids)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -8,10 +8,14 @@ describe RoundRobin::ManageService do
|
||||
let!(:inbox_members) { create_list(:inbox_member, 5, inbox: inbox) }
|
||||
|
||||
describe '#available_agent' do
|
||||
it 'gets the first available agent and move agent to end of the list' do
|
||||
it 'returns nil if allowed_member_ids is empty' do
|
||||
expect(described_class.new(inbox: inbox, allowed_member_ids: []).available_agent).to eq nil
|
||||
end
|
||||
|
||||
it 'gets the first available agent in allowed_member_ids and move agent to end of the list' do
|
||||
expected_queue = [inbox_members[0].user_id, inbox_members[4].user_id, inbox_members[3].user_id, inbox_members[2].user_id,
|
||||
inbox_members[1].user_id].map(&:to_s)
|
||||
round_robin_manage_service.available_agent
|
||||
described_class.new(inbox: inbox, allowed_member_ids: [inbox_members[0].user_id, inbox_members[4].user_id]).available_agent
|
||||
expect(round_robin_manage_service.send(:queue)).to eq(expected_queue)
|
||||
end
|
||||
|
||||
@@ -19,8 +23,8 @@ describe RoundRobin::ManageService do
|
||||
expected_queue = [inbox_members[2].user_id, inbox_members[4].user_id, inbox_members[3].user_id, inbox_members[1].user_id,
|
||||
inbox_members[0].user_id].map(&:to_s)
|
||||
# prority list will be ids in string, since thats what redis supplies to us
|
||||
expect(round_robin_manage_service.available_agent(priority_list: [inbox_members[3].user_id.to_s,
|
||||
inbox_members[2].user_id.to_s])).to eq inbox_members[2].user
|
||||
expect(described_class.new(inbox: inbox, allowed_member_ids: [inbox_members[2].user_id])
|
||||
.available_agent(priority_list: [inbox_members[3].user_id.to_s, inbox_members[2].user_id.to_s])).to eq inbox_members[2].user
|
||||
expect(round_robin_manage_service.send(:queue)).to eq(expected_queue)
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user