## Linear ticket - https://linear.app/chatwoot/issue/CW-7137/assignment-v2-backlog-flush-overloads-agents ## Description Assignment policies now skip stale unassigned conversations automatically. Each policy carries an age threshold (defaults to 7 days), so auto-assignment only picks up recent backlog instead of draining very old, forgotten conversations. The threshold is configurable per policy and can be cleared to assign conversations regardless of age. Previously this control existed only on Enterprise capacity policies (`exclude_older_than_hours`); it now lives on the assignment policy itself, so every V2 inbox benefits without needing a capacity policy. ## Type of change - [ ] New feature (non-breaking change which adds functionality) ## How Has This Been Tested? - Local UI flows ## Screenshots? <img width="645" height="822" alt="image" src="https://github.com/user-attachments/assets/ec58db86-c1fa-4f9e-be87-2e24ff02e077" /> ## Checklist: - [ ] My code follows the style guidelines of this project - [ ] I have performed a self-review of my code - [ ] I have commented on my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [ ] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] Any dependent changes have been merged and published in downstream modules --------- Co-authored-by: Sony Mathew <sony@chatwoot.com>
70 lines
2.5 KiB
Ruby
70 lines
2.5 KiB
Ruby
require 'rails_helper'
|
|
|
|
RSpec.describe AssignmentPolicy do
|
|
describe 'associations' do
|
|
it { is_expected.to belong_to(:account) }
|
|
it { is_expected.to have_many(:inbox_assignment_policies).dependent(:destroy) }
|
|
it { is_expected.to have_many(:inboxes).through(:inbox_assignment_policies) }
|
|
end
|
|
|
|
describe 'validations' do
|
|
subject { build(:assignment_policy) }
|
|
|
|
it { is_expected.to validate_presence_of(:name) }
|
|
it { is_expected.to validate_uniqueness_of(:name).scoped_to(:account_id) }
|
|
end
|
|
|
|
describe 'fair distribution validations' do
|
|
it 'requires fair_distribution_limit to be greater than 0' do
|
|
policy = build(:assignment_policy, fair_distribution_limit: 0)
|
|
expect(policy).not_to be_valid
|
|
expect(policy.errors[:fair_distribution_limit]).to include('must be greater than 0')
|
|
end
|
|
|
|
it 'requires fair_distribution_window to be greater than 0' do
|
|
policy = build(:assignment_policy, fair_distribution_window: -1)
|
|
expect(policy).not_to be_valid
|
|
expect(policy.errors[:fair_distribution_window]).to include('must be greater than 0')
|
|
end
|
|
end
|
|
|
|
describe 'exclude_older_than_hours validations' do
|
|
it 'requires exclude_older_than_hours to be greater than 0' do
|
|
policy = build(:assignment_policy, exclude_older_than_hours: 0)
|
|
expect(policy).not_to be_valid
|
|
expect(policy.errors[:exclude_older_than_hours]).to include('must be greater than 0')
|
|
end
|
|
|
|
it 'allows exclude_older_than_hours to be nil' do
|
|
policy = build(:assignment_policy, exclude_older_than_hours: nil)
|
|
expect(policy).to be_valid
|
|
end
|
|
end
|
|
|
|
describe 'enum values' do
|
|
let(:assignment_policy) { create(:assignment_policy) }
|
|
|
|
describe 'conversation_priority' do
|
|
it 'can be set to earliest_created' do
|
|
assignment_policy.update!(conversation_priority: :earliest_created)
|
|
expect(assignment_policy.conversation_priority).to eq('earliest_created')
|
|
expect(assignment_policy.earliest_created?).to be true
|
|
end
|
|
|
|
it 'can be set to longest_waiting' do
|
|
assignment_policy.update!(conversation_priority: :longest_waiting)
|
|
expect(assignment_policy.conversation_priority).to eq('longest_waiting')
|
|
expect(assignment_policy.longest_waiting?).to be true
|
|
end
|
|
end
|
|
|
|
describe 'assignment_order' do
|
|
it 'can be set to round_robin' do
|
|
assignment_policy.update!(assignment_order: :round_robin)
|
|
expect(assignment_policy.assignment_order).to eq('round_robin')
|
|
expect(assignment_policy.round_robin?).to be true
|
|
end
|
|
end
|
|
end
|
|
end
|