-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest-server.js
More file actions
99 lines (83 loc) · 3.3 KB
/
test-server.js
File metadata and controls
99 lines (83 loc) · 3.3 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
98
99
#!/usr/bin/env node
/**
* Test script for the Gesture Recognition MCP Server
* This script tests all the major functionality
*/
const SERVER_URL = 'http://localhost:3001';
async function testServer() {
console.log('🧪 Testing Gesture Recognition MCP Server...\n');
try {
// Test 1: Get current gesture mappings
console.log('1️⃣ Testing gesture mappings API...');
const mappingsResponse = await fetch(`${SERVER_URL}/api/gestures`);
const mappings = await mappingsResponse.json();
console.log('✅ Gesture mappings loaded:', Object.keys(mappings));
console.log(' Mappings:', JSON.stringify(mappings, null, 2));
// Test 2: Test gesture detection
console.log('\n2️⃣ Testing gesture detection...');
const testGestures = ['wave', 'pinch', 'fist', 'open_palm'];
for (const gesture of testGestures) {
console.log(` Testing ${gesture} gesture...`);
const detectResponse = await fetch(`${SERVER_URL}/api/detect-gesture`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
gesture,
timestamp: new Date().toISOString(),
}),
});
if (detectResponse.ok) {
const result = await detectResponse.json();
console.log(` ✅ ${gesture}: ${result.success ? 'Success' : 'Failed'}`);
} else {
console.log(` ❌ ${gesture}: HTTP ${detectResponse.status}`);
}
// Wait a bit between gestures
await new Promise(resolve => setTimeout(resolve, 1000));
}
// Test 3: Update a gesture mapping
console.log('\n3️⃣ Testing mapping update...');
const updateResponse = await fetch(`${SERVER_URL}/api/gestures`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
gesture: 'thumbs_up',
action: 'notification',
params: { message: 'Thumbs up detected!' },
}),
});
if (updateResponse.ok) {
console.log('✅ Successfully added thumbs_up mapping');
// Test the new mapping
const testResponse = await fetch(`${SERVER_URL}/api/detect-gesture`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
gesture: 'thumbs_up',
timestamp: new Date().toISOString(),
}),
});
if (testResponse.ok) {
console.log('✅ Successfully tested new thumbs_up mapping');
}
} else {
console.log('❌ Failed to update mapping');
}
// Test 4: Check final mappings
console.log('\n4️⃣ Final gesture mappings:');
const finalResponse = await fetch(`${SERVER_URL}/api/gestures`);
const finalMappings = await finalResponse.json();
console.log('✅ Updated mappings:', Object.keys(finalMappings));
console.log('\n🎉 All tests completed successfully!');
console.log('\n📋 Server Summary:');
console.log(` - HTTP API: ${SERVER_URL}`);
console.log(` - WebSocket: ws://localhost:3001/ws`);
console.log(` - Available gestures: ${Object.keys(finalMappings).join(', ')}`);
console.log(` - Total mappings: ${Object.keys(finalMappings).length}`);
} catch (error) {
console.error('❌ Test failed:', error.message);
process.exit(1);
}
}
// Run tests
testServer();