-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-endpoints.js
77 lines (63 loc) · 2.16 KB
/
test-endpoints.js
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
// Simple script to test the ChimeraX integration endpoints
const http = require('http');
const https = require('https');
const BASE_URL = 'http://localhost:4000';
// Helper function to make HTTP requests
async function request(url, method = 'GET', data = null) {
return new Promise((resolve, reject) => {
const options = {
method,
headers: data ? { 'Content-Type': 'application/json' } : {}
};
const req = http.request(url, options, (res) => {
let body = '';
res.on('data', (chunk) => {
body += chunk;
});
res.on('end', () => {
try {
const result = JSON.parse(body);
console.log(`\n${method} ${url} - Status: ${res.statusCode}`);
console.log(JSON.stringify(result, null, 2));
resolve(result);
} catch (error) {
console.error('Error parsing response:', error);
reject(error);
}
});
});
req.on('error', (error) => {
console.error('Request error:', error);
reject(error);
});
if (data) {
req.write(JSON.stringify(data));
}
req.end();
});
}
async function runTests() {
console.log('TESTING CHIMERAX INTEGRATION ENDPOINTS\n');
try {
// Test 1: Check ChimeraX status
console.log('Test 1: Checking ChimeraX status...');
await request(`${BASE_URL}/api/chimerax/status`);
// Test 2: Start ChimeraX
console.log('\nTest 2: Starting ChimeraX...');
await request(`${BASE_URL}/api/chimerax/start`, 'POST');
// Test 3: Check status again
console.log('\nTest 3: Checking ChimeraX status after starting...');
await request(`${BASE_URL}/api/chimerax/status`);
// Test 4: Send command to ChimeraX
console.log('\nTest 4: Sending command to ChimeraX...');
await request(`${BASE_URL}/api/chimerax/command`, 'POST', { command: 'open 1abc' });
// Test 5: Stop ChimeraX
console.log('\nTest 5: Stopping ChimeraX...');
await request(`${BASE_URL}/api/chimerax/stop`, 'POST');
console.log('\nAll tests completed successfully.');
} catch (error) {
console.error('Test failed:', error);
}
}
// Run the tests
runTests();