-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_api.js
More file actions
35 lines (30 loc) · 1.14 KB
/
Copy pathtest_api.js
File metadata and controls
35 lines (30 loc) · 1.14 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
async function runTests() {
const baseURL = 'http://localhost:5000/api';
console.log('Testing Login API...');
try {
const loginRes = await fetch(`${baseURL}/auth/login`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ email: 'admin@gigflow.com', password: 'admin123' })
});
const loginData = await loginRes.json();
console.log('Login successful:', loginData.success);
const token = loginData.token;
console.log('Testing Get Leads API...');
const leadsRes = await fetch(`${baseURL}/leads`, {
headers: { Authorization: `Bearer ${token}` }
});
const leadsData = await leadsRes.json();
console.log('Leads fetched, count:', leadsData.data.length);
console.log('Testing Stats API...');
const statsRes = await fetch(`${baseURL}/leads/stats`, {
headers: { Authorization: `Bearer ${token}` }
});
const statsData = await statsRes.json();
console.log('Stats fetched:', Object.keys(statsData).length);
console.log('All backend tests passed!');
} catch (error) {
console.error('Test failed:', error);
}
}
runTests();