-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest-api.js
More file actions
97 lines (80 loc) · 2.25 KB
/
Copy pathtest-api.js
File metadata and controls
97 lines (80 loc) · 2.25 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/env node
// Test script for the API endpoints
import chalk from 'chalk';
const API_BASE = 'http://localhost:3000/api/v1';
async function testEndpoint(name, endpoint, options = {}) {
console.log(chalk.blue(`\nTesting ${name}...`));
try {
const response = await fetch(`${API_BASE}${endpoint}`, {
method: options.method || 'GET',
headers: {
'Content-Type': 'application/json',
...options.headers
},
body: options.body ? JSON.stringify(options.body) : undefined
});
const data = await response.json();
if (response.ok) {
console.log(chalk.green('✓ Success'));
console.log(chalk.gray(JSON.stringify(data, null, 2)));
} else {
console.log(chalk.red('✗ Failed'));
console.log(chalk.red(JSON.stringify(data, null, 2)));
}
} catch (error) {
console.log(chalk.red('✗ Error:', error.message));
}
}
async function runTests() {
console.log(chalk.yellow('HelpTheWeb API Test Suite'));
console.log(chalk.gray('Make sure the API server is running on port 3000\n'));
// Test health endpoint
await testEndpoint('Health Check', '../../health');
// Test API info
await testEndpoint('API Info', '');
// Test rules listing
await testEndpoint('List Rules', '/rules');
// Test specific rule
await testEndpoint('Get Rule Details', '/rules/img-alt');
// Test single URL scan
await testEndpoint('Single URL Scan', '/scan', {
method: 'POST',
body: {
url: 'https://example.com',
options: {
maxElements: 100
}
}
});
// Test batch scan
await testEndpoint('Batch URL Scan', '/scan/batch', {
method: 'POST',
body: {
urls: [
'https://example.com',
'https://example.com/404'
],
options: {
maxElements: 100
}
}
});
// Test sitemap scan
await testEndpoint('Sitemap Scan', '/scan/sitemap', {
method: 'POST',
body: {
sitemapUrl: 'https://example.com/sitemap.xml',
options: {
maxUrls: 5
}
}
});
// Test error handling
await testEndpoint('Error Handling - No URL', '/scan', {
method: 'POST',
body: {}
});
console.log(chalk.yellow('\n✨ Test suite complete!'));
}
// Run tests
runTests().catch(console.error);