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
|
||||
Reference in New Issue
Block a user