-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-api.js
More file actions
53 lines (43 loc) · 1.52 KB
/
test-api.js
File metadata and controls
53 lines (43 loc) · 1.52 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
const request = require('supertest');
const { app } = require('./src/index');
// Simple test to verify the API works
async function testLocalApi() {
console.log('🚀 Testing Contact Form API locally...\n');
try {
// Test health endpoint
console.log('1. Testing health endpoint...');
const healthResponse = await request(app)
.get('/health')
.expect(200);
console.log('✅ Health check passed:', healthResponse.body);
// Test contact form with valid data
console.log('\n2. Testing contact form with valid data...');
const contactResponse = await request(app)
.post('/contact')
.send({
name: 'Test User',
email: 'test@example.com',
message: 'This is a test message to verify the contact form API is working correctly.',
subject: 'API Test'
})
.expect(200);
console.log('✅ Contact form submission passed:', contactResponse.body);
// Test validation with invalid data
console.log('\n3. Testing validation with invalid data...');
const validationResponse = await request(app)
.post('/contact')
.send({
name: '',
email: 'invalid-email',
message: 'Short'
})
.expect(400);
console.log('✅ Validation test passed:', validationResponse.body);
console.log('\n🎉 All API tests passed! The contact form API is working correctly.');
} catch (error) {
console.error('❌ API test failed:', error.message);
process.exit(1);
}
}
// Run the test
testLocalApi();