review changes
This commit is contained in:
@@ -2,6 +2,7 @@ require 'rails_helper'
|
||||
|
||||
RSpec.describe Enterprise::AutoAssignment::AssignmentService, type: :service do
|
||||
let(:account) { create(:account) }
|
||||
let(:assignment_policy) { create(:assignment_policy, account: account, enabled: true) }
|
||||
let(:inbox) { create(:inbox, account: account) }
|
||||
let(:agent1) { create(:user, account: account, name: 'Agent 1') }
|
||||
let(:agent2) { create(:user, account: account, name: 'Agent 2') }
|
||||
@@ -12,6 +13,9 @@ RSpec.describe Enterprise::AutoAssignment::AssignmentService, type: :service do
|
||||
create(:inbox_member, inbox: inbox, user: agent1)
|
||||
create(:inbox_member, inbox: inbox, user: agent2)
|
||||
|
||||
# Link inbox to assignment policy
|
||||
create(:inbox_assignment_policy, inbox: inbox, assignment_policy: assignment_policy)
|
||||
|
||||
allow(account).to receive(:feature_enabled?).and_return(false)
|
||||
allow(account).to receive(:feature_enabled?).with('assignment_v2').and_return(true)
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ require 'rails_helper'
|
||||
|
||||
RSpec.describe AutoAssignment::AssignmentService do
|
||||
let(:account) { create(:account) }
|
||||
let(:assignment_policy) { create(:assignment_policy, account: account, enabled: true) }
|
||||
let(:inbox) { create(:inbox, account: account, enable_auto_assignment: true) }
|
||||
let(:service) { described_class.new(inbox: inbox) }
|
||||
let(:agent) { create(:user, account: account, role: :agent, availability: :online) }
|
||||
@@ -9,6 +10,10 @@ RSpec.describe AutoAssignment::AssignmentService do
|
||||
let(:conversation) { create(:conversation, inbox: inbox, assignee: nil) }
|
||||
|
||||
before do
|
||||
# Enable assignment_v2 feature for the account
|
||||
allow(account).to receive(:feature_enabled?).with('assignment_v2').and_return(true)
|
||||
# Link inbox to assignment policy
|
||||
create(:inbox_assignment_policy, inbox: inbox, assignment_policy: assignment_policy)
|
||||
create(:inbox_member, inbox: inbox, user: agent)
|
||||
end
|
||||
|
||||
@@ -105,7 +110,7 @@ RSpec.describe AutoAssignment::AssignmentService do
|
||||
end
|
||||
|
||||
context 'when auto assignment is disabled' do
|
||||
before { inbox.update!(enable_auto_assignment: false) }
|
||||
before { assignment_policy.update!(enabled: false) }
|
||||
|
||||
it 'returns 0 without processing' do
|
||||
assigned_count = service.perform_bulk_assignment(limit: 10)
|
||||
|
||||
@@ -59,7 +59,7 @@ RSpec.describe AutoAssignment::RateLimiter do
|
||||
end
|
||||
|
||||
it 'creates a Redis key with correct expiry' do
|
||||
expected_key = "assignment:#{inbox.id}:agent:#{agent.id}:conversation:#{conversation.id}"
|
||||
expected_key = format(Redis::RedisKeys::ASSIGNMENT_KEY, inbox_id: inbox.id, agent_id: agent.id, conversation_id: conversation.id)
|
||||
expect(Redis::Alfred).to receive(:set).with(
|
||||
expected_key,
|
||||
conversation.id.to_s,
|
||||
@@ -90,7 +90,7 @@ RSpec.describe AutoAssignment::RateLimiter do
|
||||
end
|
||||
|
||||
it 'counts matching Redis keys' do
|
||||
pattern = "assignment:#{inbox.id}:agent:#{agent.id}:*"
|
||||
pattern = format(Redis::RedisKeys::ASSIGNMENT_KEY_PATTERN, inbox_id: inbox.id, agent_id: agent.id)
|
||||
allow(Redis::Alfred).to receive(:keys_count).with(pattern).and_return(3)
|
||||
|
||||
expect(rate_limiter.current_count).to eq(3)
|
||||
@@ -108,7 +108,7 @@ RSpec.describe AutoAssignment::RateLimiter do
|
||||
end
|
||||
|
||||
it 'uses the custom window value' do
|
||||
expected_key = "assignment:#{inbox.id}:agent:#{agent.id}:conversation:#{conversation.id}"
|
||||
expected_key = format(Redis::RedisKeys::ASSIGNMENT_KEY, inbox_id: inbox.id, agent_id: agent.id, conversation_id: conversation.id)
|
||||
expect(Redis::Alfred).to receive(:set).with(
|
||||
expected_key,
|
||||
conversation.id.to_s,
|
||||
@@ -126,7 +126,7 @@ RSpec.describe AutoAssignment::RateLimiter do
|
||||
end
|
||||
|
||||
it 'uses the default window value of 3600' do
|
||||
expected_key = "assignment:#{inbox.id}:agent:#{agent.id}:conversation:#{conversation.id}"
|
||||
expected_key = format(Redis::RedisKeys::ASSIGNMENT_KEY, inbox_id: inbox.id, agent_id: agent.id, conversation_id: conversation.id)
|
||||
expect(Redis::Alfred).to receive(:set).with(
|
||||
expected_key,
|
||||
conversation.id.to_s,
|
||||
|
||||
Reference in New Issue
Block a user