66 lines
2.3 KiB
JavaScript
66 lines
2.3 KiB
JavaScript
const axios = require('axios');
|
|
const FormData = require('form-data');
|
|
|
|
const API_URL = 'http://localhost:4000/api/v1';
|
|
|
|
async function loginAndTestEmail() {
|
|
try {
|
|
// 1. Login
|
|
console.log('🔐 Connexion...');
|
|
const loginResponse = await axios.post(`${API_URL}/auth/login`, {
|
|
email: 'admin@xpeditis.com',
|
|
password: 'Admin123!@#'
|
|
});
|
|
|
|
const token = loginResponse.data.accessToken;
|
|
console.log('✅ Connecté avec succès\n');
|
|
|
|
// 2. Créer un CSV booking pour tester l'envoi d'email
|
|
console.log('📧 Création d\'une CSV booking pour tester l\'envoi d\'email...');
|
|
|
|
const form = new FormData();
|
|
const testFile = Buffer.from('Test document PDF content');
|
|
form.append('documents', testFile, { filename: 'test-doc.pdf', contentType: 'application/pdf' });
|
|
|
|
form.append('carrierName', 'Test Carrier');
|
|
form.append('carrierEmail', 'testcarrier@example.com');
|
|
form.append('origin', 'NLRTM');
|
|
form.append('destination', 'USNYC');
|
|
form.append('volumeCBM', '25.5');
|
|
form.append('weightKG', '3500');
|
|
form.append('palletCount', '10');
|
|
form.append('priceUSD', '1850.50');
|
|
form.append('priceEUR', '1665.45');
|
|
form.append('primaryCurrency', 'USD');
|
|
form.append('transitDays', '28');
|
|
form.append('containerType', 'LCL');
|
|
form.append('notes', 'Test email');
|
|
|
|
const bookingResponse = await axios.post(`${API_URL}/csv-bookings`, form, {
|
|
headers: {
|
|
...form.getHeaders(),
|
|
'Authorization': `Bearer ${token}`
|
|
}
|
|
});
|
|
|
|
console.log('✅ CSV Booking créé:', bookingResponse.data.id);
|
|
console.log('\n📋 VÉRIFICATIONS À FAIRE:');
|
|
console.log('1. Vérifier les logs du backend ci-dessus');
|
|
console.log(' Chercher: "Email sent to carrier: testcarrier@example.com"');
|
|
console.log('2. Vérifier Mailtrap inbox: https://mailtrap.io/inboxes');
|
|
console.log('3. Email devrait être envoyé à: testcarrier@example.com');
|
|
console.log('\n⏳ Attendez quelques secondes puis vérifiez les logs du backend...');
|
|
|
|
} catch (error) {
|
|
console.error('❌ ERREUR:');
|
|
if (error.response) {
|
|
console.error('Status:', error.response.status);
|
|
console.error('Data:', JSON.stringify(error.response.data, null, 2));
|
|
} else {
|
|
console.error(error.message);
|
|
}
|
|
}
|
|
}
|
|
|
|
loginAndTestEmail();
|