fix: Assignment V2 controller fix (#12415)
This commit is contained in:
committed by
GitHub
parent
052b328a1f
commit
e5b8dc251f
@@ -4,8 +4,8 @@ class Api::V1::Accounts::AgentCapacityPolicies::UsersController < Api::V1::Accou
|
|||||||
before_action :fetch_user, only: [:destroy]
|
before_action :fetch_user, only: [:destroy]
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@users = Current.account.users.joins(:account_users)
|
@users = User.joins(:account_users)
|
||||||
.where(account_users: { agent_capacity_policy_id: @agent_capacity_policy.id })
|
.where(account_users: { account_id: Current.account.id, agent_capacity_policy_id: @agent_capacity_policy.id })
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ class Api::V1::Accounts::AgentCapacityPoliciesController < Api::V1::Accounts::En
|
|||||||
params.require(:agent_capacity_policy).permit(
|
params.require(:agent_capacity_policy).permit(
|
||||||
:name,
|
:name,
|
||||||
:description,
|
:description,
|
||||||
exclusion_rules: [:overall_capacity, { hours: [], days: [] }]
|
exclusion_rules: [:exclude_older_than_hours, { excluded_labels: [] }]
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,26 @@ RSpec.describe 'Agent Capacity Policy Users API', type: :request do
|
|||||||
expect(response).to have_http_status(:success)
|
expect(response).to have_http_status(:success)
|
||||||
expect(response.parsed_body.first['id']).to eq(user.id)
|
expect(response.parsed_body.first['id']).to eq(user.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'returns each user only once without duplicates' do
|
||||||
|
# Assign multiple users to the same policy
|
||||||
|
user.account_users.first.update!(agent_capacity_policy: agent_capacity_policy)
|
||||||
|
agent.account_users.first.update!(agent_capacity_policy: agent_capacity_policy)
|
||||||
|
|
||||||
|
get "/api/v1/accounts/#{account.id}/agent_capacity_policies/#{agent_capacity_policy.id}/users",
|
||||||
|
headers: administrator.create_new_auth_token,
|
||||||
|
as: :json
|
||||||
|
|
||||||
|
expect(response).to have_http_status(:success)
|
||||||
|
|
||||||
|
# Check that we have exactly 2 users
|
||||||
|
expect(response.parsed_body.length).to eq(2)
|
||||||
|
|
||||||
|
# Check that each user appears only once
|
||||||
|
user_ids = response.parsed_body.map { |u| u['id'] }
|
||||||
|
expect(user_ids).to contain_exactly(user.id, agent.id)
|
||||||
|
expect(user_ids.uniq).to eq(user_ids) # No duplicates
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -103,7 +103,10 @@ RSpec.describe 'Agent Capacity Policies API', type: :request do
|
|||||||
agent_capacity_policy: {
|
agent_capacity_policy: {
|
||||||
name: 'Test Policy',
|
name: 'Test Policy',
|
||||||
description: 'Test Description',
|
description: 'Test Description',
|
||||||
exclusion_rules: { overall_capacity: 10 }
|
exclusion_rules: {
|
||||||
|
excluded_labels: %w[urgent spam],
|
||||||
|
exclude_older_than_hours: 24
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -115,6 +118,10 @@ RSpec.describe 'Agent Capacity Policies API', type: :request do
|
|||||||
expect(response).to have_http_status(:success)
|
expect(response).to have_http_status(:success)
|
||||||
expect(response.parsed_body['name']).to eq('Test Policy')
|
expect(response.parsed_body['name']).to eq('Test Policy')
|
||||||
expect(response.parsed_body['description']).to eq('Test Description')
|
expect(response.parsed_body['description']).to eq('Test Description')
|
||||||
|
expect(response.parsed_body['exclusion_rules']).to eq({
|
||||||
|
'excluded_labels' => %w[urgent spam],
|
||||||
|
'exclude_older_than_hours' => 24
|
||||||
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns validation errors for invalid data' do
|
it 'returns validation errors for invalid data' do
|
||||||
@@ -165,6 +172,28 @@ RSpec.describe 'Agent Capacity Policies API', type: :request do
|
|||||||
expect(response).to have_http_status(:success)
|
expect(response).to have_http_status(:success)
|
||||||
expect(response.parsed_body['name']).to eq('Updated Policy')
|
expect(response.parsed_body['name']).to eq('Updated Policy')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'updates exclusion rules when administrator' do
|
||||||
|
params = {
|
||||||
|
agent_capacity_policy: {
|
||||||
|
exclusion_rules: {
|
||||||
|
excluded_labels: %w[vip priority],
|
||||||
|
exclude_older_than_hours: 48
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
put "/api/v1/accounts/#{account.id}/agent_capacity_policies/#{agent_capacity_policy.id}",
|
||||||
|
params: params,
|
||||||
|
headers: administrator.create_new_auth_token,
|
||||||
|
as: :json
|
||||||
|
|
||||||
|
expect(response).to have_http_status(:success)
|
||||||
|
expect(response.parsed_body['exclusion_rules']).to eq({
|
||||||
|
'excluded_labels' => %w[vip priority],
|
||||||
|
'exclude_older_than_hours' => 48
|
||||||
|
})
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user