File size: 1,997 Bytes
fcf8749 | 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 | const axios = require('axios');
/**
* Test script for e-Way Bill Absorption
* Run this after fixing the database connection: `node scripts/testAbsorption.js`
*/
const BASE_URL = 'http://localhost:3000/api/eway-bill';
const TOKEN = 'YOUR_JWT_TOKEN_HERE'; // Replace with a valid dispatcher token
async function testAbsorption() {
try {
console.log('--- Testing e-Way Bill Absorption Endpoint ---');
const payload = {
exporterPhone: "9876543210",
importerPhone: "1234567890",
exporterTruckPlate: "KA-01-AB-1234",
importerTruckPlate: "KA-02-CD-5678",
exchangedGoods: ["delivery-id-1", "delivery-id-2"] // Replace with actual IDs
};
const response = await axios.post(`${BASE_URL}/absorption`, payload, {
headers: {
'Authorization': `Bearer ${TOKEN}`,
'Content-Type': 'application/json'
},
responseType: 'arraybuffer' // Expecting a zip file
});
console.log('✅ Success: Received zip file');
console.log('Response Status:', response.status);
console.log('Content-Type:', response.headers['content-type']);
// In a real test, you would save this to a file
// fs.writeFileSync('test_output.zip', response.data);
} catch (error) {
console.error('❌ Test Failed:', error.response ? error.response.statusText : error.message);
if (error.response && error.response.data) {
try {
const errorData = JSON.parse(Buffer.from(error.response.data).toString());
console.error('Error Details:', errorData);
} catch (e) {
console.error('Error response could not be parsed as JSON');
}
}
}
}
// Note: Ensure the server is running before executing this
// testAbsorption();
console.log('Script loaded. To test, ensure your local server is running and database is connected.');
|