-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-admin-users.js
More file actions
51 lines (43 loc) · 1.48 KB
/
test-admin-users.js
File metadata and controls
51 lines (43 loc) · 1.48 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
const axios = require('axios');
async function testAdminUsers() {
try {
console.log('🧪 Testing Admin Users API...\n');
// Step 1: Login to get token
console.log('1. Logging in...');
const loginResponse = await axios.post('http://localhost:5001/api/admin/login', {
username: 'admin',
password: 'admin123'
});
if (!loginResponse.data.success) {
console.error('❌ Login failed:', loginResponse.data.message);
return;
}
const token = loginResponse.data.token;
console.log('✅ Login successful');
console.log(' Token:', token.substring(0, 20) + '...\n');
// Step 2: Get admin users
console.log('2. Fetching admin users...');
const usersResponse = await axios.get('http://localhost:5001/api/admin/users', {
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json'
}
});
if (usersResponse.data.success) {
console.log('✅ Admin users fetched successfully');
console.log(' Users count:', usersResponse.data.data.length);
console.log(' Users:', usersResponse.data.data.map(u => ({
username: u.username,
email: u.email,
role: u.role,
is_active: u.is_active
})));
} else {
console.error('❌ Failed to fetch users:', usersResponse.data.message);
}
} catch (error) {
console.error('❌ Test failed:', error.response?.data?.message || error.message);
}
}
// Run the test
testAdminUsers();