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

83 lines
3.3 KiB
JavaScript

#!/usr/bin/env node
/**
* Test script for the improved PDF generation API
* Tests both A3 and A4 formats with zero whitespace
*/
const fs = require('fs');
const path = require('path');
const axios = require('axios');
const API_BASE_URL = 'http://localhost:8000';
// Test HTML content from preview files
const testHTMLs = {
'grand-oak': fs.readFileSync('/home/ubuntu/salesforce/PDF_Generation_and_Automation/previews/preview-grand-oak.html', 'utf8'),
'vertice': fs.readFileSync('/home/ubuntu/salesforce/PDF_Generation_and_Automation/previews/preview-vertice.html', 'utf8'),
'serenity-house': fs.readFileSync('/home/ubuntu/salesforce/PDF_Generation_and_Automation/previews/preview-serenity-house.html', 'utf8'),
'modern-home': fs.readFileSync('/home/ubuntu/salesforce/PDF_Generation_and_Automation/previews/preview-modern-home.html', 'utf8')
};
async function testPDFGeneration() {
console.log('🧪 Testing ZERO-WHITESPACE PDF Generation API');
console.log('=' .repeat(60));
// Test health endpoint
try {
const healthResponse = await axios.get(`${API_BASE_URL}/health`);
console.log('✅ Health Check:', healthResponse.data);
console.log('📐 Supported Formats:', healthResponse.data.supported_formats);
console.log('');
} catch (error) {
console.error('❌ Health check failed:', error.message);
return;
}
// Test each HTML template with both A3 and A4 formats
for (const [templateName, htmlContent] of Object.entries(testHTMLs)) {
console.log(`\n🏠 Testing Template: ${templateName.toUpperCase()}`);
console.log('-'.repeat(40));
for (const format of ['A4', 'A3']) {
try {
console.log(`\n📄 Generating ${format} PDF...`);
const response = await axios.post(`${API_BASE_URL}/generate-pdf`, {
input: htmlContent,
output: `${templateName}-${format.toLowerCase()}`,
format: format,
return_download_link: true
}, {
headers: {
'Content-Type': 'application/json'
},
timeout: 60000 // 60 seconds timeout
});
if (response.data.success) {
console.log(`${format} 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(', ')}`);
} else {
console.log(`${format} PDF Generation Failed:`, response.data.message);
}
} catch (error) {
console.error(`❌ Error generating ${format} PDF for ${templateName}:`, error.response?.data?.error || error.message);
}
}
}
console.log('\n🎉 PDF Generation Testing Complete!');
console.log('=' .repeat(60));
}
// Run the test
if (require.main === module) {
testPDFGeneration().catch(console.error);
}
module.exports = { testPDFGeneration };