Files
chatwoot/spec/enterprise/models/agent_capacity_policy_spec.rb
Tanmay Deep Sharma ad90deb709 feat: Add agent capacity controllers (#12200)
## Linear reference:
https://linear.app/chatwoot/issue/CW-4649/re-imagine-assignments

## Description
This PR introduces the foundation for Assignment V2 system by
implementing agent_capacity and their association with inboxes and
users.

## Type of change

- [ ] New feature (non-breaking change which adds functionality)

## How Has This Been Tested?

Test Coverage:
-  Controller specs for assignment policies CRUD operations
-  Enterprise-specific specs for balanced assignment order
-  Model specs for community/enterprise separation

## 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: Pranav <pranav@chatwoot.com>
2025-08-26 19:12:58 -07:00

30 lines
952 B
Ruby

require 'rails_helper'
RSpec.describe AgentCapacityPolicy, type: :model do
let(:account) { create(:account) }
describe 'validations' do
it { is_expected.to validate_presence_of(:name) }
it { is_expected.to validate_length_of(:name).is_at_most(255) }
end
describe 'destruction' do
let(:policy) { create(:agent_capacity_policy, account: account) }
let(:user) { create(:user, account: account) }
let(:inbox) { create(:inbox, account: account) }
it 'destroys associated inbox capacity limits' do
create(:inbox_capacity_limit, agent_capacity_policy: policy, inbox: inbox)
expect { policy.destroy }.to change(InboxCapacityLimit, :count).by(-1)
end
it 'nullifies associated account users' do
account_user = user.account_users.first
account_user.update!(agent_capacity_policy: policy)
policy.destroy
expect(account_user.reload.agent_capacity_policy).to be_nil
end
end
end