forked from positonic/exponential
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-analytics.js
More file actions
95 lines (84 loc) · 2.93 KB
/
Copy pathtest-analytics.js
File metadata and controls
95 lines (84 loc) · 2.93 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
// Manual test script for WhatsApp Analytics System
// This will test the core functionality without relying on TypeScript compilation
console.log('🧪 Starting WhatsApp Analytics System Test...');
const testEndpoints = [
'/api/webhooks/whatsapp/health',
'/api/workers/whatsapp',
'/api/cron/whatsapp-analytics'
];
async function testHealthEndpoint() {
console.log('\n📊 Testing Health Check Endpoint...');
try {
const response = await fetch('http://localhost:3000/api/webhooks/whatsapp/health');
if (response.ok) {
const data = await response.json();
console.log('✅ Health endpoint working:', data.status);
return true;
} else {
console.log('❌ Health endpoint failed:', response.status);
return false;
}
} catch (error) {
console.log('❌ Health endpoint error:', error instanceof Error ? error.message : String(error));
return false;
}
}
async function testWorkerEndpoint() {
console.log('\n⚙️ Testing Worker Status Endpoint...');
try {
const response = await fetch('http://localhost:3000/api/workers/whatsapp');
if (response.ok) {
const data = await response.json();
console.log('✅ Worker endpoint working:', data.status);
return true;
} else {
console.log('❌ Worker endpoint failed:', response.status);
return false;
}
} catch (error) {
console.log('❌ Worker endpoint error:', error instanceof Error ? error.message : String(error));
return false;
}
}
async function testAnalyticsEndpoint() {
console.log('\n📈 Testing Analytics Cron Endpoint...');
try {
const response = await fetch('http://localhost:3000/api/cron/whatsapp-analytics', {
method: 'POST'
});
if (response.ok) {
const data = await response.json();
console.log('✅ Analytics endpoint working:', data.success);
return true;
} else {
console.log('❌ Analytics endpoint failed:', response.status);
return false;
}
} catch (error) {
console.log('❌ Analytics endpoint error:', error instanceof Error ? error.message : String(error));
return false;
}
}
async function runTests() {
const results = [];
results.push(await testHealthEndpoint());
results.push(await testWorkerEndpoint());
results.push(await testAnalyticsEndpoint());
const passed = results.filter(r => r).length;
const total = results.length;
console.log('\n📋 Test Results:');
console.log(`✅ Passed: ${passed}/${total}`);
console.log(`❌ Failed: ${total - passed}/${total}`);
if (passed === total) {
console.log('\n🎉 All tests passed! Analytics system is functional.');
} else {
console.log('\n⚠️ Some tests failed. Manual verification needed.');
}
}
// Export for testing
if (typeof module !== 'undefined' && module.exports) {
module.exports = { runTests, testHealthEndpoint, testWorkerEndpoint, testAnalyticsEndpoint };
} else {
// Run tests if in browser environment
runTests();
}