fix user duplication issue for assignment user list
This commit is contained in:
+2
-2
@@ -4,8 +4,8 @@ class Api::V1::Accounts::AgentCapacityPolicies::UsersController < Api::V1::Accou
|
||||
before_action :fetch_user, only: [:destroy]
|
||||
|
||||
def index
|
||||
@users = Current.account.users.joins(:account_users)
|
||||
.where(account_users: { agent_capacity_policy_id: @agent_capacity_policy.id })
|
||||
@users = User.joins(:account_users)
|
||||
.where(account_users: { account_id: Current.account.id, agent_capacity_policy_id: @agent_capacity_policy.id })
|
||||
end
|
||||
|
||||
def create
|
||||
|
||||
+20
@@ -19,6 +19,26 @@ RSpec.describe 'Agent Capacity Policy Users API', type: :request do
|
||||
expect(response).to have_http_status(:success)
|
||||
expect(response.parsed_body.first['id']).to eq(user.id)
|
||||
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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user