salesforce_node_pdf_api/test-no-whitespace-pdf.js
2025-09-03 23:52:13 +05:30

81 lines
2.6 KiB
JavaScript

#!/usr/bin/env node
/**
* Test script for NO-WHITESPACE PDF generation
* Tests the refined PDF generator to ensure no white spaces
*/
const axios = require('axios');
// Test HTML content with potential whitespace issues
const testHTML = `
<div class="container">
<h1> Property Brochure Test </h1>
<p> This is a test paragraph with extra spaces. </p>
<ul>
<li> Item 1 with spaces </li>
<li> Item 2 with spaces </li>
</ul>
<table>
<tr>
<td> Cell 1 </td>
<td> Cell 2 </td>
</tr>
</table>
<div class="spacing-issue">
<p> Another paragraph </p>
</div>
</div>
`;
async function testNoWhitespacePDF() {
try {
console.log("🧪 Testing NO-WHITESPACE PDF generation...");
const response = await axios.post('http://localhost:8002/generate-no-whitespace-pdf', {
input: testHTML,
output: 'test_no_whitespace',
return_download_link: true
}, {
headers: {
'Content-Type': 'application/json'
},
timeout: 60000 // 60 second timeout
});
if (response.data.success) {
console.log("✅ NO-WHITESPACE PDF generated successfully!");
console.log(`📄 Filename: ${response.data.filename}`);
console.log(`📊 File size: ${response.data.file_size_mb} MB`);
console.log(`🔗 Download URL: ${response.data.download_url}`);
console.log(`🚫 Features: ${response.data.features.join(', ')}`);
// Test health endpoint
const healthResponse = await axios.get('http://localhost:8002/health');
console.log("🏥 Health check:", healthResponse.data.status);
console.log("🔧 Features:", healthResponse.data.features.join(', '));
} else {
console.error("❌ PDF generation failed:", response.data);
}
} catch (error) {
if (error.code === 'ECONNREFUSED') {
console.error("❌ Connection refused. Make sure the server is running on port 8002");
console.log("💡 Start the server with: node refined-pdf-generation.js");
} else {
console.error("❌ Test error:", error.message);
if (error.response) {
console.error("📄 Response data:", error.response.data);
}
}
}
}
// Run the test
testNoWhitespacePDF();