![]() 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.ca/private_html/scripts/ |
const { PrismaClient } = require('@prisma/client');
const prisma = new PrismaClient();
async function testChatHealth() {
console.log('š„ Testing chat system health...\n');
try {
// Test 1: Database connectivity
console.log('1ļøā£ Testing database connection...');
await prisma.$connect();
console.log(' ā
Database connected successfully');
// Test 2: Check users exist
console.log('\n2ļøā£ Checking users...');
const users = await prisma.user.findMany({
select: { id: true, name: true, email: true, role: true }
});
console.log(` ā
Found ${users.length} users:`);
users.forEach(user => {
console.log(` - ${user.name} (${user.email}) [${user.role}]`);
});
if (users.length === 0) {
console.log(' ā ļø No users found - chat won\'t work without users');
return;
}
// Test 3: Check chat rooms exist
console.log('\n3ļøā£ Checking chat rooms...');
const rooms = await prisma.chatRoom.findMany({
include: {
participants: {
include: { user: { select: { name: true } } }
},
_count: { select: { messages: true } }
}
});
console.log(` ā
Found ${rooms.length} chat rooms:`);
rooms.forEach(room => {
console.log(` - ${room.name} (${room.participants.length} participants, ${room._count.messages} messages)`);
});
if (rooms.length === 0) {
console.log(' ā ļø No chat rooms found - creating default rooms...');
// Run the setup script
require('./setup-chat-rooms.js');
return;
}
// Test 4: Check chat participants
console.log('\n4ļøā£ Checking chat participants...');
const participants = await prisma.chatParticipant.findMany({
include: {
user: { select: { name: true, email: true } },
chatRoom: { select: { name: true } }
}
});
console.log(` ā
Found ${participants.length} total participants`);
// Test 5: Check for orphaned data
console.log('\n5ļøā£ Checking for data issues...');
// Check for users not in any room
const usersWithoutRooms = await prisma.user.findMany({
where: {
chatParticipants: {
none: {}
}
},
select: { name: true, email: true }
});
if (usersWithoutRooms.length > 0) {
console.log(` ā ļø ${usersWithoutRooms.length} users not in any chat room:`);
usersWithoutRooms.forEach(user => {
console.log(` - ${user.name} (${user.email})`);
});
} else {
console.log(' ā
All users are in at least one chat room');
}
// Test 6: API endpoint test
console.log('\n6ļøā£ API endpoints status:');
console.log(' š” Testing these endpoints manually:');
console.log(' GET /api/chat/rooms');
console.log(' GET /api/chat/group/messages?chatRoomId=<room_id>');
console.log(' POST /api/chat/group/messages');
console.log(' WS /_ws (WebSocket connection)');
// Test 7: Summary and recommendations
console.log('\nš SUMMARY:');
console.log(` š„ Users: ${users.length}`);
console.log(` š¬ Chat Rooms: ${rooms.length}`);
console.log(` š Participants: ${participants.length}`);
console.log(` ā ļø Users without rooms: ${usersWithoutRooms.length}`);
console.log('\nšÆ RECOMMENDATIONS:');
if (users.length < 2) {
console.log(' - Create more users to test chat functionality');
}
if (rooms.length === 0) {
console.log(' - Run: node scripts/setup-chat-rooms.js');
}
if (usersWithoutRooms.length > 0) {
console.log(' - Add users to chat rooms');
}
console.log('\nš± TO TEST GROUP CHAT:');
console.log(' 1. Start the dev server: npm run dev');
console.log(' 2. Login as a user');
console.log(' 3. Navigate to: /group-chat');
console.log(' 4. Check WebSocket connection (should show green dot)');
console.log(' 5. Select a chat room and try sending a message');
console.log('\nš§ TROUBLESHOOTING:');
console.log(' - If WebSocket won\'t connect: Check browser console for errors');
console.log(' - If no rooms show: Check browser Network tab for API errors');
console.log(' - If messages don\'t send: Check session authentication');
console.log(' - If stuck loading: Try logout/login to refresh session');
} catch (error) {
console.error('ā Chat health check failed:', error);
if (error.code === 'P1001') {
console.log('\nš” Database connection failed. Make sure:');
console.log(' - Database is running');
console.log(' - Environment variables are set correctly');
console.log(' - Run: npx prisma db push');
}
} finally {
await prisma.$disconnect();
}
}
testChatHealth();