-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-live-api.js
More file actions
72 lines (61 loc) · 1.87 KB
/
test-live-api.js
File metadata and controls
72 lines (61 loc) · 1.87 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
const https = require('https');
function makeRequest(url, options = {}) {
return new Promise((resolve, reject) => {
const req = https.request(url, options, (res) => {
let data = '';
res.on('data', (chunk) => data += chunk);
res.on('end', () => {
try {
resolve({
status: res.statusCode,
data: JSON.parse(data)
});
} catch (e) {
resolve({
status: res.statusCode,
data: data
});
}
});
});
req.on('error', reject);
if (options.body) {
req.write(options.body);
}
req.end();
});
}
async function testLiveAPI() {
const apiUrl = 'https://us-central1-serverless-462906.cloudfunctions.net/contact-form-api';
console.log('🚀 Testing Live Serverless Contact Form API\n');
// Test 1: Health Check
console.log('1. Testing Health Endpoint...');
try {
const healthResponse = await makeRequest(`${apiUrl}/health`);
console.log('✅ Health Check:', healthResponse.data);
} catch (error) {
console.log('❌ Health Check Error:', error.message);
}
// Test 2: Contact Form Submission
console.log('\n2. Testing Contact Form Submission...');
try {
const contactData = {
name: 'Test User',
email: 'test@example.com',
subject: 'Live API Test',
message: 'This is a test of the live serverless contact form API!'
};
const contactResponse = await makeRequest(`${apiUrl}/contact`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Content-Length': Buffer.byteLength(JSON.stringify(contactData))
},
body: JSON.stringify(contactData)
});
console.log('✅ Contact Form Response:', contactResponse.data);
} catch (error) {
console.log('❌ Contact Form Error:', error.message);
}
}
testLiveAPI();