|
1 | | -const axios = require('axios'); |
2 | | - |
3 | | -const API_URL = 'http://localhost:3000/api'; |
4 | | - |
5 | | -async function runTests() { |
6 | | - let token = ''; |
7 | | - let userId = ''; |
8 | | - |
9 | | - console.log('--- Testing Auth ---'); |
10 | | - try { |
11 | | - const regRes = await axios.post(`${API_URL}/auth/register`, { |
12 | | - email: 'testuser22@example.com', |
13 | | - username: 'testuser2', |
14 | | - password: 'password123' |
15 | | - }); |
16 | | - console.log('Register:', regRes.status, regRes.data); |
17 | | - } catch (e) { |
18 | | - console.log('Register error (expected if already registered):', e.response?.status, e.response?.data); |
19 | | - } |
20 | | - |
21 | | - try { |
22 | | - const loginRes = await axios.post(`${API_URL}/auth/login`, { |
23 | | - email: 'testuser22@example.com', |
24 | | - password: 'password123' |
25 | | - }); |
26 | | - console.log('Login:', loginRes.status); |
27 | | - token = loginRes.data.token; |
28 | | - userId = loginRes.data.user.id; |
29 | | - } catch (e) { |
30 | | - console.error('Login failed!', e.response?.status, e.response?.data); |
31 | | - return; |
32 | | - } |
33 | | - |
34 | | - console.log('\n--- Testing Courses ---'); |
35 | | - try { |
36 | | - const coursesRes = await axios.get(`${API_URL}/courses`); |
37 | | - console.log('Get courses:', coursesRes.status, `Found ${coursesRes.data.length} courses`); |
38 | | - if (coursesRes.data.length > 0) { |
39 | | - const courseId = coursesRes.data[0].id; |
40 | | - const courseRes = await axios.get(`${API_URL}/courses/${courseId}`); |
41 | | - console.log('Get single course:', courseRes.status, courseRes.data.title); |
42 | | - } |
43 | | - } catch (e) { |
44 | | - console.error('Courses failed!', e.response?.status, e.response?.data); |
45 | | - } |
46 | | - |
47 | | - console.log('\n--- Testing Progress (Happy Path) ---'); |
48 | | - try { |
49 | | - const progRes = await axios.post(`${API_URL}/progress`, { |
50 | | - lessonId: 13, |
51 | | - score: 85 |
52 | | - }, { headers: { Authorization: `Bearer ${token}` } }); |
53 | | - console.log('Submit progress:', progRes.status, progRes.data); |
54 | | - } catch (e) { |
55 | | - console.error('Submit progress failed!', e.response?.status, e.response?.data); |
56 | | - } |
57 | | - |
58 | | - console.log('\n--- Adversarial Probes ---'); |
59 | | - |
60 | | - // Probe 1: Duplicate Registration |
61 | | - try { |
62 | | - const dupRes = await axios.post(`${API_URL}/auth/register`, { |
63 | | - email: 'testuser22@example.com', |
64 | | - username: 'testuser22', |
65 | | - password: 'password123' |
66 | | - }); |
67 | | - console.log('PROBE 1 FAIL: Duplicate registration allowed!', dupRes.status); |
68 | | - } catch (e) { |
69 | | - console.log('PROBE 1 PASS: Duplicate registration rejected with', e.response?.status, e.response?.data); |
70 | | - } |
71 | | - |
72 | | - // Probe 2: Invalid Progress Score (negative) |
73 | | - try { |
74 | | - const badProgRes = await axios.post(`${API_URL}/progress`, { |
75 | | - lessonId: 13, |
76 | | - score: 150 |
77 | | - }, { headers: { Authorization: `Bearer ${token}` } }); |
78 | | - console.log('PROBE 2 FAIL: Negative score allowed!', badProgRes.status, badProgRes.data); |
79 | | - } catch (e) { |
80 | | - console.log('PROBE 2 PASS: Negative score rejected with', e.response?.status, e.response?.data); |
81 | | - } |
82 | | - |
83 | | - // Probe 3: Invalid Course ID |
84 | | - try { |
85 | | - const badCourseRes = await axios.get(`${API_URL}/courses/not-a-number`); |
86 | | - console.log('PROBE 3 FAIL: Invalid course ID allowed!', badCourseRes.status, badCourseRes.data); |
87 | | - } catch (e) { |
88 | | - console.log('PROBE 3 PASS: Invalid course ID rejected with', e.response?.status, e.response?.data); |
89 | | - } |
90 | | -} |
91 | | - |
92 | | -runTests(); |
| 1 | +const express = require('express'); |
| 2 | +const app = express(); |
| 3 | +app.listen(3000, () => { |
| 4 | + console.log('Test server running'); |
| 5 | +}); |
0 commit comments