const { Pool } = require('pg'); const fs = require('fs'); const path = require('path'); const pool = new Pool({ connectionString: 'postgresql://postgres:password@localhost:5432/cim_processor' }); async function testUploadProcessing() { try { console.log('๐Ÿงช Testing Upload and Processing Pipeline'); console.log('=========================================='); // Check if we have any documents with 'uploaded' status const uploadedDocs = await pool.query(` SELECT id, original_file_name, status, created_at FROM documents WHERE status = 'uploaded' ORDER BY created_at DESC LIMIT 3 `); console.log(`๐Ÿ“‹ Found ${uploadedDocs.rows.length} documents with 'uploaded' status:`); uploadedDocs.rows.forEach(doc => { console.log(` - ${doc.original_file_name} (${doc.status}) - ${doc.created_at}`); }); if (uploadedDocs.rows.length === 0) { console.log('โŒ No documents with "uploaded" status found'); console.log('๐Ÿ’ก Upload a new document through the frontend to test processing'); return; } // Check processing jobs const processingJobs = await pool.query(` SELECT id, document_id, type, status, progress, created_at FROM processing_jobs WHERE document_id IN (${uploadedDocs.rows.map(d => `'${d.id}'`).join(',')}) ORDER BY created_at DESC `); console.log(`\n๐Ÿ”ง Found ${processingJobs.rows.length} processing jobs:`); processingJobs.rows.forEach(job => { console.log(` - Job ${job.id}: ${job.type} (${job.status}) - ${job.progress}%`); }); // Check if job queue service is running console.log('\n๐Ÿ” Checking if job queue service is active...'); console.log('๐Ÿ’ก The backend should automatically process documents when:'); console.log(' 1. A document is uploaded with processImmediately=true'); console.log(' 2. The job queue service is running'); console.log(' 3. Processing jobs are created in the database'); console.log('\n๐Ÿ“Š Current Status:'); console.log(` - Documents uploaded: ${uploadedDocs.rows.length}`); console.log(` - Processing jobs created: ${processingJobs.rows.length}`); console.log(` - Jobs in pending status: ${processingJobs.rows.filter(j => j.status === 'pending').length}`); console.log(` - Jobs in processing status: ${processingJobs.rows.filter(j => j.status === 'processing').length}`); console.log(` - Jobs completed: ${processingJobs.rows.filter(j => j.status === 'completed').length}`); if (processingJobs.rows.filter(j => j.status === 'pending').length > 0) { console.log('\nโš ๏ธ There are pending jobs that should be processed automatically'); console.log('๐Ÿ’ก This suggests the job queue worker might not be running'); } } catch (error) { console.error('โŒ Error testing pipeline:', error.message); } finally { await pool.end(); } } testUploadProcessing();