-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_bug.js
More file actions
46 lines (38 loc) · 2.21 KB
/
test_bug.js
File metadata and controls
46 lines (38 loc) · 2.21 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
const axios = require('axios');
async function test() {
try {
console.log("Logging in as Admin...");
const auth = await axios.post('http://localhost:5000/api/auth/login', { email: 'admin@library.com', password: 'password' });
const token = auth.data.token;
console.log("Token received.");
console.log("Fetching reports: pending_requests...");
try {
const reqs = await axios.get('http://localhost:5000/api/reports?type=pending_requests', { headers: { Authorization: `Bearer ${token}` }});
console.log("Pending Requests:", reqs.data);
} catch(e) { console.error("Report pending_requests failed:", e?.response?.data || e.message); }
console.log("Fetching reports: master_books...");
try {
const reqs = await axios.get('http://localhost:5000/api/reports?type=master_books', { headers: { Authorization: `Bearer ${token}` }});
console.log("Master books:", reqs.data);
} catch(e) { console.error("Report master_books failed:", e?.response?.data || e.message); }
console.log("Logging in as User...");
const authUser = await axios.post('http://localhost:5000/api/auth/login', { email: 'john@library.com', password: 'password' });
const userToken = authUser.data.token;
console.log("Fetching items for User...");
let itemId;
try {
const items = await axios.get('http://localhost:5000/api/items', { headers: { Authorization: `Bearer ${userToken}` }});
if(items.data.length > 0) itemId = items.data[0]._id;
console.log("Found item:", itemId);
} catch(e) { console.error("Items fetch failed:", e?.response?.data || e.message); }
console.log("Creating request...");
try {
// Let's check what exactly is failing in request
const reqRes = await axios.post('http://localhost:5000/api/requests', { itemId }, { headers: { Authorization: `Bearer ${userToken}` }});
console.log("Request created:", reqRes.data);
} catch(e) { console.error("Request post failed:", e?.response?.data || e.message); }
} catch (e) {
console.error("Test failed globally:", e.message);
}
}
test();