![]() Server : Apache/2 System : Linux server-15-235-50-60 5.15.0-164-generic #174-Ubuntu SMP Fri Nov 14 20:25:16 UTC 2025 x86_64 User : gositeme ( 1004) PHP Version : 8.2.29 Disable Function : exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname Directory : /home/gositeme/domains/lavocat.quebec/public_html/scripts/ |
const { PrismaClient } = require('@prisma/client');
const prisma = new PrismaClient();
async function testLawyerDropdown() {
console.log('š Testing Lawyer Dropdown Functionality...\n');
try {
// 1. Test the exact API call the frontend makes
console.log('1. Testing frontend API call simulation...');
// Simulate the exact API call: fetch('/api/admin/users?role=LAWYER,ADMIN')
const lawyers = await prisma.user.findMany({
where: {
role: {
in: ['LAWYER', 'ADMIN', 'SUPERADMIN']
}
},
select: {
id: true,
email: true,
name: true,
role: true,
title: true,
specialization: true,
lawFirmId: true,
lawFirm: {
select: {
name: true,
shortName: true
}
},
createdAt: true,
updatedAt: true,
},
orderBy: {
name: 'asc',
},
});
console.log(`ā
API call successful - found ${lawyers.length} lawyers`);
// 2. Test the response format
console.log('\n2. Testing response format...');
const apiResponse = { users: lawyers };
console.log(' API response structure:', {
hasUsers: !!apiResponse.users,
usersIsArray: Array.isArray(apiResponse.users),
usersLength: apiResponse.users.length
});
// 3. Test frontend processing
console.log('\n3. Testing frontend processing...');
const lawyersData = apiResponse;
const lawyersArray = Array.isArray(lawyersData) ? lawyersData : (lawyersData.users || []);
console.log(' Frontend processing result:', {
isArray: Array.isArray(lawyersArray),
length: lawyersArray.length,
firstLawyer: lawyersArray[0] ? {
id: lawyersArray[0].id,
name: lawyersArray[0].name,
role: lawyersArray[0].role
} : null
});
// 4. Test dropdown options generation
console.log('\n4. Testing dropdown options generation...');
const dropdownOptions = lawyersArray.map(lawyer => ({
value: lawyer.id,
label: `${lawyer.name} ${lawyer.title ? `(${lawyer.title})` : ''} ${lawyer.specialization ? `- ${lawyer.specialization}` : ''}`
}));
console.log(' Dropdown options generated:', dropdownOptions.length);
console.log(' Sample options:');
dropdownOptions.slice(0, 3).forEach((option, index) => {
console.log(` ${index + 1}. "${option.label}" (value: "${option.value}")`);
});
// 5. Test current case data
console.log('\n5. Testing current case data...');
const caseId = 'cmcpzyax8000avjz0ao7zkw1g';
const currentCase = await prisma.legalCase.findUnique({
where: { id: caseId },
select: {
id: true,
title: true,
leadLawyerId: true,
leadLawyer: {
select: {
id: true,
name: true,
role: true
}
}
}
});
if (currentCase) {
console.log(' Current case data:');
console.log(` - Title: ${currentCase.title}`);
console.log(` - Lead Lawyer ID: "${currentCase.leadLawyerId}"`);
console.log(` - Lead Lawyer: ${currentCase.leadLawyer?.name || 'None'}`);
// Check if current lawyer is in dropdown
const isInDropdown = lawyersArray.some(l => l.id === currentCase.leadLawyerId);
console.log(` - Current lawyer in dropdown: ${isInDropdown ? 'ā
Yes' : 'ā No'}`);
}
// 6. Test form data structure
console.log('\n6. Testing form data structure...');
const formData = {
leadLawyerId: currentCase?.leadLawyerId || '',
lawyers: lawyersArray
};
console.log(' Form data:');
console.log(` - leadLawyerId: "${formData.leadLawyerId}"`);
console.log(` - lawyers count: ${formData.lawyers.length}`);
console.log(` - lawyers with names: ${formData.lawyers.filter(l => l.name && l.name.trim()).length}`);
// 7. Test potential issues
console.log('\n7. Testing potential issues...');
// Check for empty or null names
const invalidNames = lawyersArray.filter(l => !l.name || l.name.trim() === '');
if (invalidNames.length > 0) {
console.log(` ā ļø Found ${invalidNames.length} lawyers with invalid names`);
invalidNames.forEach(l => console.log(` - ID: ${l.id}, Name: "${l.name}"`));
} else {
console.log(' ā
All lawyers have valid names');
}
// Check for missing IDs
const missingIds = lawyersArray.filter(l => !l.id);
if (missingIds.length > 0) {
console.log(` ā ļø Found ${missingIds.length} lawyers with missing IDs`);
} else {
console.log(' ā
All lawyers have IDs');
}
// Check for duplicate IDs
const ids = lawyersArray.map(l => l.id);
const uniqueIds = new Set(ids);
if (ids.length !== uniqueIds.size) {
console.log(' ā ļø Found duplicate IDs');
} else {
console.log(' ā
All IDs are unique');
}
// 8. Test the actual dropdown HTML generation
console.log('\n8. Testing dropdown HTML generation...');
const dropdownHTML = `
<select value="${formData.leadLawyerId}">
<option value="">Select a lawyer</option>
${lawyersArray.map(lawyer => `
<option key="${lawyer.id}" value="${lawyer.id}">
${lawyer.name} ${lawyer.title ? `(${lawyer.title})` : ''} ${lawyer.specialization ? `- ${lawyer.specialization}` : ''}
</option>
`).join('')}
</select>
`;
console.log(' Dropdown HTML generated successfully');
console.log(` - Options count: ${lawyersArray.length + 1} (including "Select a lawyer")`);
console.log(` - Current value: "${formData.leadLawyerId}"`);
// 9. Summary and recommendations
console.log('\n9. š SUMMARY & RECOMMENDATIONS:');
console.log(` ā
API returns ${lawyersArray.length} lawyers`);
console.log(` ā
All lawyers have valid data`);
console.log(` ā
Dropdown should render ${lawyersArray.length + 1} options`);
console.log(` ā
Current selection: "${formData.leadLawyerId}"`);
if (lawyersArray.length > 0) {
console.log('\nš The lawyer dropdown should work correctly!');
console.log('\nš§ If you still can\'t select a lawyer, try these steps:');
console.log(' 1. Open browser DevTools (F12)');
console.log(' 2. Check Console tab for JavaScript errors');
console.log(' 3. Check Network tab for failed API requests');
console.log(' 4. Verify you\'re logged in as an admin');
console.log(' 5. Try refreshing the page');
console.log(' 6. Check if the dropdown is disabled or has CSS issues');
} else {
console.log('\nā No lawyers found - this needs investigation!');
}
} catch (error) {
console.error('ā Test failed:', error);
} finally {
await prisma.$disconnect();
}
}
// Run the test
testLawyerDropdown();