-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-email-functionality.js
More file actions
72 lines (61 loc) · 2.41 KB
/
Copy pathtest-email-functionality.js
File metadata and controls
72 lines (61 loc) · 2.41 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Test script for email functionality
const fetch = require('node-fetch');
const API_BASE_URL = 'http://localhost:3001/api';
const FLASK_URL = 'http://localhost:5000';
async function testEmailFunctionality() {
console.log('🧪 Testing Email Functionality...\n');
try {
// Test 1: Direct Flask email endpoint
console.log('1. Testing direct Flask email endpoint...');
const testPerson = {
name: 'Test User',
email: 'test@example.com',
age: 25,
phone: '+1234567890',
interests: 'Technology, AI, Machine Learning',
job: 'Software Engineer'
};
const flaskResponse = await fetch(`${FLASK_URL}/send-email`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ person: testPerson }),
});
if (flaskResponse.ok) {
const flaskResult = await flaskResponse.json();
console.log('✅ Direct Flask email test successful:', flaskResult.message);
} else {
const errorData = await flaskResponse.json();
console.log('❌ Direct Flask email test failed:', errorData.error);
}
// Test 2: Backend chat endpoint with email sending
console.log('\n2. Testing backend chat endpoint with email sending...');
const chatMessage = 'Add John Doe, email: john.doe@test.com, age: 30, interests: Programming, Reading, job: Developer, phone: +1987654321';
const chatResponse = await fetch(`${API_BASE_URL}/chat`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ message: chatMessage }),
});
if (chatResponse.ok) {
const chatResult = await chatResponse.json();
console.log('✅ Backend chat with email test successful');
console.log('📧 Message:', chatResult.message);
console.log('📧 Email sent:', chatResult.emailSent);
console.log('🤖 AI Response:', chatResult.aiResponse);
} else {
const errorData = await chatResponse.json();
console.log('❌ Backend chat test failed:', errorData.error);
}
console.log('\n🎉 Email functionality test completed!');
} catch (error) {
console.error('❌ Test failed:', error.message);
console.log('\n💡 Make sure both servers are running:');
console.log(' - Backend: node server.js (port 3001)');
console.log(' - Flask: python app.py (port 5000)');
}
}
// Run the test
testEmailFunctionality();