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/backups/lavocat.quebec/backup-20250730-021618/scripts/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/gositeme/backups/lavocat.quebec/backup-20250730-021618/scripts/test-admin-case-edit.js
const { PrismaClient } = require('@prisma/client');

const prisma = new PrismaClient();

async function testAdminCaseEdit() {
  console.log('šŸ” Testing Admin Case Edit Functionality...\n');

  try {
    // 1. Find a test case
    console.log('1. Finding a test case...');
    const testCase = await prisma.legalCase.findFirst({
      include: {
        leadLawyer: {
          select: {
            id: true,
            name: true,
            email: true,
            role: true
          }
        }
      }
    });

    if (!testCase) {
      console.log('āŒ No test case found. Creating one...');
      // Create a test case if none exists
      const testCase = await prisma.legalCase.create({
        data: {
          title: 'Test Case for Edit',
          description: 'This is a test case for editing functionality',
          caseNumber: '2024QCCS9999',
          caseType: 'CLASS_ACTION',
          jurisdiction: 'Quebec',
          court: 'QUEBEC_SUPERIOR',
          leadLawyerId: 'test-lawyer-id', // You'll need to replace with actual lawyer ID
          priority: 'medium',
          status: 'pending',
          isAcceptingApplications: true,
          createdBy: 'test-admin-id' // You'll need to replace with actual admin ID
        }
      });
      console.log('āœ… Test case created:', testCase.id);
    } else {
      console.log('āœ… Found test case:', testCase.id);
      console.log('   Title:', testCase.title);
      console.log('   Lead Lawyer:', testCase.leadLawyer?.name || 'None');
    }

    // 2. Check API endpoint structure
    console.log('\n2. Checking API endpoint structure...');
    console.log('   Expected fields for PUT /api/admin/cases/[id]:');
    console.log('   - title (string)');
    console.log('   - description (string)');
    console.log('   - caseNumber (string) - SINGULAR');
    console.log('   - caseType (string) - SINGULAR');
    console.log('   - jurisdiction (string) - SINGULAR');
    console.log('   - court (string) - SINGULAR');
    console.log('   - leadLawyerId (string)');
    console.log('   - priority (string)');
    console.log('   - budget (number or null)');
    console.log('   - status (string)');
    console.log('   - applicationDeadline (date string or null)');
    console.log('   - isAcceptingApplications (boolean)');

    // 3. Check frontend form structure
    console.log('\n3. Frontend form structure issues:');
    console.log('   āŒ Frontend sends: caseNumbers (array)');
    console.log('   āœ… API expects: caseNumber (string)');
    console.log('   āŒ Frontend sends: caseTypes (array)');
    console.log('   āœ… API expects: caseType (string)');
    console.log('   āŒ Frontend sends: jurisdictions (array)');
    console.log('   āœ… API expects: jurisdiction (string)');
    console.log('   āŒ Frontend sends: courts (array)');
    console.log('   āœ… API expects: court (string)');

    // 4. Test API call simulation
    console.log('\n4. Simulating API call with correct data structure...');
    const testUpdateData = {
      title: 'Updated Test Case',
      description: 'This is an updated test case description',
      caseNumber: '2024QCCS9999', // SINGULAR
      caseType: 'CLASS_ACTION', // SINGULAR
      jurisdiction: 'Quebec', // SINGULAR
      court: 'QUEBEC_SUPERIOR', // SINGULAR
      leadLawyerId: testCase.leadLawyerId,
      priority: 'high',
      budget: 50000,
      status: 'active',
      applicationDeadline: '2024-12-31',
      isAcceptingApplications: true
    };

    console.log('   Test update data:', JSON.stringify(testUpdateData, null, 2));

    // 5. Check database schema
    console.log('\n5. Checking database schema...');
    const caseFields = await prisma.$queryRaw`
      SELECT column_name, data_type, is_nullable
      FROM information_schema.columns 
      WHERE table_name = 'LegalCase' 
      ORDER BY ordinal_position
    `;
    
    console.log('   LegalCase table fields:');
    caseFields.forEach(field => {
      console.log(`   - ${field.column_name}: ${field.data_type} (nullable: ${field.is_nullable})`);
    });

    // 6. Recommendations
    console.log('\n6. šŸ”§ RECOMMENDATIONS TO FIX:');
    console.log('   a) Update frontend form to send singular fields:');
    console.log('      - caseNumbers[0] → caseNumber');
    console.log('      - caseTypes[0] → caseType');
    console.log('      - jurisdictions[0] → jurisdiction');
    console.log('      - courts[0] → court');
    console.log('   b) Or update API to handle arrays and convert to singular');
    console.log('   c) Add proper error handling for missing required fields');
    console.log('   d) Add validation for case number format');
    console.log('   e) Add logging to track API requests and responses');

    console.log('\nāœ… Test completed successfully!');

  } catch (error) {
    console.error('āŒ Test failed:', error);
  } finally {
    await prisma.$disconnect();
  }
}

// Run the test
testAdminCaseEdit(); 

CasperSecurity Mini