forked from seejux/waha-whatsapp-mcp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_sleep.js
More file actions
89 lines (77 loc) Β· 2.88 KB
/
test_sleep.js
File metadata and controls
89 lines (77 loc) Β· 2.88 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
#!/usr/bin/env node
/**
* Test script for sleep/wait utility tools
*/
import { handleSleep, handleWait } from "./dist/tools/new-handlers.js";
async function testSleepTools() {
console.log("π§ͺ Testing Sleep/Wait Utility Tools\n");
console.log("=" .repeat(50));
// Mock WAHAClient (not needed for sleep)
const mockClient = null;
try {
// Test 1: Sleep with milliseconds
console.log("\nπ Test 1: Sleep with duration (milliseconds)");
console.log("Sleeping for 2000ms (2 seconds)...");
const start1 = Date.now();
const result1 = await handleSleep(mockClient, {
duration: 2000,
message: "Testing sleep with milliseconds",
});
const end1 = Date.now();
console.log(`β
Completed in ${end1 - start1}ms`);
console.log("Response:", result1.content[0].text);
// Test 2: Sleep with seconds
console.log("\nπ Test 2: Sleep with seconds");
console.log("Sleeping for 1.5 seconds...");
const start2 = Date.now();
const result2 = await handleSleep(mockClient, {
seconds: 1.5,
message: "Testing sleep with seconds",
});
const end2 = Date.now();
console.log(`β
Completed in ${end2 - start2}ms`);
console.log("Response:", result2.content[0].text);
// Test 3: Wait (alias for sleep)
console.log("\nπ Test 3: Wait function");
console.log("Waiting for 1 second...");
const start3 = Date.now();
const result3 = await handleWait(mockClient, {
seconds: 1,
message: "Waiting between operations",
});
const end3 = Date.now();
console.log(`β
Completed in ${end3 - start3}ms`);
console.log("Response:", result3.content[0].text);
// Test 4: Default sleep (no parameters)
console.log("\nπ Test 4: Default sleep (1 second)");
console.log("Sleeping with default parameters...");
const start4 = Date.now();
const result4 = await handleSleep(mockClient, {});
const end4 = Date.now();
console.log(`β
Completed in ${end4 - start4}ms`);
console.log("Response:", result4.content[0].text);
// Test 5: Test max duration validation
console.log("\nπ Test 5: Max duration validation");
try {
console.log("Trying to sleep for 400 seconds (should fail)...");
await handleSleep(mockClient, {
seconds: 400, // Exceeds 300 second max
});
console.log("β Should have thrown an error!");
} catch (error) {
console.log("β
Correctly rejected:", error.message);
}
console.log("\n" + "=".repeat(50));
console.log("β
All tests passed!\n");
console.log("π Summary:");
console.log(" - sleep tool: β
Working");
console.log(" - wait tool: β
Working");
console.log(" - Duration validation: β
Working");
console.log(" - Custom messages: β
Working");
} catch (error) {
console.error("\nβ Test failed:", error.message);
process.exit(1);
}
}
// Run tests
testSleepTools();