66 lines
2.6 KiB
JavaScript
66 lines
2.6 KiB
JavaScript
/**
|
||
* Test l'envoi d'email via le service backend
|
||
*/
|
||
const axios = require('axios');
|
||
|
||
const API_URL = 'http://localhost:4000/api/v1';
|
||
|
||
// Token d'authentification (admin@xpeditis.com)
|
||
const AUTH_TOKEN = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI5MTI3Y2M0Zi04Yzg4LTRjNGUtYmU1ZC1hNmY1ZTE2MWZlNDMiLCJlbWFpbCI6ImFkbWluQHhwZWRpdGlzLmNvbSIsInJvbGUiOiJBRE1JTiIsIm9yZ2FuaXphdGlvbklkIjoiMWZhOWE1NjUtZjNjOC00ZTExLTliMzAtMTIwZDEwNTJjZWYwIiwidHlwZSI6ImFjY2VzcyIsImlhdCI6MTc2NDg3NDQ2MSwiZXhwIjoxNzY0ODc1MzYxfQ.l_-97_rikGj-DP8aA14CK-Ab-0Usy722MRe1lqi0u9I';
|
||
|
||
async function testCsvBookingEmail() {
|
||
console.log('🧪 Test envoi email via CSV booking...\n');
|
||
|
||
try {
|
||
// Créer un FormData pour simuler l'upload de fichiers
|
||
const FormData = require('form-data');
|
||
const fs = require('fs');
|
||
const form = new FormData();
|
||
|
||
// Créer un fichier de test temporaire
|
||
const testFile = Buffer.from('Test document content');
|
||
form.append('documents', testFile, { filename: 'test-document.pdf', contentType: 'application/pdf' });
|
||
|
||
// Ajouter les champs du formulaire
|
||
form.append('carrierName', 'Test Carrier Email');
|
||
form.append('carrierEmail', 'test-carrier@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 sending');
|
||
|
||
console.log('📤 Envoi de la requête de création de CSV booking...');
|
||
|
||
const response = await axios.post(`${API_URL}/csv-bookings`, form, {
|
||
headers: {
|
||
...form.getHeaders(),
|
||
'Authorization': `Bearer ${AUTH_TOKEN}`
|
||
}
|
||
});
|
||
|
||
console.log('✅ Réponse reçue:', response.status);
|
||
console.log('📋 Booking créé:', response.data.id);
|
||
console.log('\n⚠️ Vérifiez maintenant:');
|
||
console.log('1. Les logs du backend pour voir "Email sent to carrier:"');
|
||
console.log('2. Votre inbox Mailtrap: https://mailtrap.io/inboxes');
|
||
console.log('3. Email destinataire: test-carrier@example.com');
|
||
|
||
} catch (error) {
|
||
console.error('❌ Erreur:', error.response?.data || error.message);
|
||
if (error.response?.status === 401) {
|
||
console.error('\n⚠️ Token expiré. Connectez-vous d\'abord avec:');
|
||
console.error('POST /api/v1/auth/login');
|
||
console.error('{ "email": "admin@xpeditis.com", "password": "..." }');
|
||
}
|
||
}
|
||
}
|
||
|
||
testCsvBookingEmail();
|