File size: 3,943 Bytes
bbfde3f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | const fs = require('fs');
const FormData = require('form-data');
const fetch = require('node-fetch');
async function testBatchProcessing() {
console.log('π¬ Testing Batch Processing System...\n');
const API_BASE = 'http://localhost:3000'; // Adjust as needed
// 1. Test batch upload with multiple files
console.log('1. Testing batch upload...');
const testFiles = [
'tests/fixtures/test_problematic.docx',
'tests/fixtures/test_remediated.docx',
'tests/fixtures/test_advanced_remediated.docx'
];
const form = new FormData();
testFiles.forEach((filePath, index) => {
if (fs.existsSync(filePath)) {
const fileStream = fs.createReadStream(filePath);
form.append(`file${index}`, fileStream, {
filename: `test-file-${index + 1}.docx`
});
console.log(` β Added ${filePath}`);
} else {
console.log(` β οΈ File not found: ${filePath}`);
}
});
try {
console.log('\nπ€ Uploading batch...');
const uploadResponse = await fetch(`${API_BASE}/api/batch-upload`, {
method: 'POST',
body: form
});
if (!uploadResponse.ok) {
console.log('β Upload failed:', uploadResponse.status, uploadResponse.statusText);
return;
}
const uploadResult = await uploadResponse.json();
console.log('β
Batch upload successful!');
console.log(` Batch ID: ${uploadResult.batchId}`);
console.log(` Total files: ${uploadResult.summary.totalFiles}`);
console.log(` Successful: ${uploadResult.summary.successful}`);
console.log(` Failed: ${uploadResult.summary.failed}`);
const batchId = uploadResult.batchId;
// 2. Test batch listing
console.log('\n2. Testing batch listing...');
const listResponse = await fetch(`${API_BASE}/api/reports?action=batches`);
if (listResponse.ok) {
const listResult = await listResponse.json();
console.log(`β
Found ${listResult.totalBatches} batches`);
if (listResult.batches.length > 0) {
const latestBatch = listResult.batches[0];
console.log(` Latest batch: ${latestBatch.batchId} (${latestBatch.totalFiles} files)`);
}
} else {
console.log('β Failed to list batches');
}
// 3. Test batch download
console.log('\n3. Testing batch download...');
const downloadResponse = await fetch(`${API_BASE}/api/batch-download?batchId=${batchId}`);
if (downloadResponse.ok) {
const zipBuffer = await downloadResponse.buffer();
const outputPath = `batch-${batchId}-test-download.zip`;
fs.writeFileSync(outputPath, zipBuffer);
console.log(`β
Batch downloaded: ${outputPath} (${zipBuffer.length} bytes)`);
} else {
console.log('β Failed to download batch');
}
// 4. Test individual report listing
console.log('\n4. Testing report listing...');
const reportsResponse = await fetch(`${API_BASE}/api/reports?action=list&limit=5`);
if (reportsResponse.ok) {
const reportsResult = await reportsResponse.json();
console.log(`β
Found ${reportsResult.totalReports} recent reports`);
reportsResult.reports.forEach((report, index) => {
console.log(` ${index + 1}. ${report.filename} (${report.reportId})`);
});
} else {
console.log('β Failed to list reports');
}
console.log('\nπ Batch processing test completed!');
console.log('\nNext steps:');
console.log('- Open docs/batch-processing.html in your browser');
console.log('- Test with your own DOCX files');
console.log('- Check the reports/ directory for stored results');
} catch (error) {
console.error('β Test error:', error);
}
}
// Add CLI support
if (require.main === module) {
testBatchProcessing();
}
module.exports = testBatchProcessing; |