forked from Laisky/one-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-duplicate-calls.js
More file actions
123 lines (100 loc) · 3.76 KB
/
test-duplicate-calls.js
File metadata and controls
123 lines (100 loc) · 3.76 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
// Test script to verify that duplicate API calls are fixed
// This will monitor network requests and count API calls
const puppeteer = require('puppeteer');
async function testDuplicateCalls() {
const browser = await puppeteer.launch({ headless: false });
const page = await browser.newPage();
// Track API calls
const apiCalls = [];
page.on('request', request => {
const url = request.url();
if (url.includes('/api/channel/') || url.includes('/api/user/') || url.includes('/api/token/')) {
apiCalls.push({
url: url,
timestamp: Date.now()
});
console.log(`API Call: ${url}`);
}
});
try {
// Navigate to the application
await page.goto('http://localhost:3001');
await page.waitForTimeout(2000);
// Login if needed
const loginButton = await page.$('button[type="submit"]');
if (loginButton) {
console.log('Logging in...');
await page.type('input[name="username"]', 'root');
await page.type('input[name="password"]', '123456');
await page.click('button[type="submit"]');
await page.waitForTimeout(2000);
}
// Test Channels page
console.log('\n=== Testing Channels Page ===');
await page.goto('http://localhost:3001/channels');
await page.waitForTimeout(3000);
// Clear previous API calls
apiCalls.length = 0;
// Change page size
console.log('Changing page size to 20...');
const pageSizeSelector = await page.$('[role="combobox"]');
if (pageSizeSelector) {
await pageSizeSelector.click();
await page.waitForTimeout(1000);
const option20 = await page.$('[role="option"][data-value="20"]');
if (option20) {
await option20.click();
await page.waitForTimeout(3000);
// Count API calls in the last 3 seconds
const recentCalls = apiCalls.filter(call =>
call.url.includes('/api/channel/') &&
Date.now() - call.timestamp < 3000
);
console.log(`API calls made: ${recentCalls.length}`);
recentCalls.forEach(call => console.log(` - ${call.url}`));
if (recentCalls.length === 1) {
console.log('✅ Channels page: No duplicate API calls');
} else {
console.log(`❌ Channels page: ${recentCalls.length} API calls (should be 1)`);
}
}
}
// Test Users page
console.log('\n=== Testing Users Page ===');
await page.goto('http://localhost:3001/users');
await page.waitForTimeout(3000);
// Clear previous API calls
apiCalls.length = 0;
// Change page size
console.log('Changing page size to 20...');
const userPageSizeSelector = await page.$('[role="combobox"]');
if (userPageSizeSelector) {
await userPageSizeSelector.click();
await page.waitForTimeout(1000);
const option20 = await page.$('[role="option"][data-value="20"]');
if (option20) {
await option20.click();
await page.waitForTimeout(3000);
// Count API calls in the last 3 seconds
const recentCalls = apiCalls.filter(call =>
call.url.includes('/api/user/') &&
Date.now() - call.timestamp < 3000
);
console.log(`API calls made: ${recentCalls.length}`);
recentCalls.forEach(call => console.log(` - ${call.url}`));
if (recentCalls.length === 1) {
console.log('✅ Users page: No duplicate API calls');
} else {
console.log(`❌ Users page: ${recentCalls.length} API calls (should be 1)`);
}
}
}
console.log('\nTest completed!');
} catch (error) {
console.error('Test failed:', error);
} finally {
await browser.close();
}
}
// Run the test
testDuplicateCalls();