@@ -13,6 +13,123 @@ describe('Users Endpoint', () => {
1313 const res = await requestWithSupertest . get ( '/users' ) ;
1414 expect ( res . status ) . toEqual ( 200 ) ;
1515 expect ( res . type ) . toEqual ( expect . stringContaining ( 'json' ) ) ;
16- //expect(res.body).toHaveProperty('users')
16+ // expect(res.body).toHaveProperty('users');
17+ } ) ;
18+ } ) ;
19+
20+ describe ( 'Leaderboard Endpoint' , ( ) => {
21+ it ( 'GET /leaderboard should return HTML' , async ( ) => {
22+ const res = await requestWithSupertest . get ( '/leaderboard' ) ;
23+ expect ( res . status ) . toEqual ( 200 ) ;
24+ expect ( res . type ) . toEqual ( expect . stringContaining ( 'html' ) ) ;
25+ } ) ;
26+ } ) ;
27+
28+ describe ( 'Characters API' , ( ) => {
29+ it ( 'GET /api/characters should return a list of characters' , async ( ) => {
30+ const res = await requestWithSupertest . get ( '/api/characters' ) ;
31+ expect ( res . status ) . toEqual ( 200 ) ;
32+ expect ( res . type ) . toEqual ( expect . stringContaining ( 'json' ) ) ;
33+ expect ( Array . isArray ( res . body ) ) . toBe ( true ) ;
34+ } ) ;
35+ } ) ;
36+
37+ describe ( 'Preferences API' , ( ) => {
38+ it ( 'GET /api/preferences should return a list of preferences' , async ( ) => {
39+ const res = await requestWithSupertest . get ( '/api/preferences' ) ;
40+ expect ( res . status ) . toEqual ( 200 ) ;
41+ expect ( res . type ) . toEqual ( expect . stringContaining ( 'json' ) ) ;
42+ expect ( Array . isArray ( res . body ) ) . toBe ( true ) ;
43+ } ) ;
44+ } ) ;
45+
46+ describe ( 'Save Score API' , ( ) => {
47+ it ( 'GET /api/save-score?score=10 should redirect or respond (if logged in)' , async ( ) => {
48+ // This test assumes a session or login is required to save a score.
49+ // If not logged in, you may get a 401 or a redirect.
50+ const res = await requestWithSupertest . get ( '/api/save-score?score=10' ) ;
51+ // Accept either a redirect (302) or forbidden (401/403) or success (200)
52+ expect ( [ 200 , 302 , 401 , 403 ] ) . toContain ( res . status ) ;
53+ } ) ;
54+ } ) ;
55+
56+ describe ( 'Home Page' , ( ) => {
57+ it ( 'GET / should return HTML' , async ( ) => {
58+ const res = await requestWithSupertest . get ( '/' ) ;
59+ expect ( res . status ) . toEqual ( 200 ) ;
60+ expect ( res . type ) . toEqual ( expect . stringContaining ( 'html' ) ) ;
61+ } ) ;
62+ } ) ;
63+
64+ describe ( 'Game Page' , ( ) => {
65+ it ( 'GET /game should return HTML' , async ( ) => {
66+ const res = await requestWithSupertest . get ( '/game' ) ;
67+ expect ( res . status ) . toEqual ( 200 ) ;
68+ expect ( res . type ) . toEqual ( expect . stringContaining ( 'html' ) ) ;
69+ } ) ;
70+ } ) ;
71+
72+ describe ( 'Game Page' , ( ) => {
73+ it ( 'GET /game should return HTML' , async ( ) => {
74+ const res = await requestWithSupertest . get ( '/game' ) ;
75+ expect ( res . status ) . toEqual ( 200 ) ;
76+ expect ( res . type ) . toEqual ( expect . stringContaining ( 'html' ) ) ;
77+ } ) ;
78+ } ) ;
79+
80+ describe ( 'Leaderboard Data API' , ( ) => {
81+ it ( 'GET /api/leaderboard should return a list' , async ( ) => {
82+ const res = await requestWithSupertest . get ( '/api/leaderboard' ) ;
83+ // Accept 200 or 404 if not implemented
84+ expect ( [ 200 , 404 ] ) . toContain ( res . status ) ;
85+ if ( res . status === 200 ) {
86+ expect ( Array . isArray ( res . body ) ) . toBe ( true ) ;
87+ }
88+ } ) ;
89+ } ) ;
90+
91+ describe ( 'Save Score API (POST)' , ( ) => {
92+ it ( 'POST /api/save-score should respond appropriately' , async ( ) => {
93+ const res = await requestWithSupertest
94+ . post ( '/api/save-score' )
95+ . send ( { score : 42 } ) ;
96+ expect ( [ 200 , 302 , 401 , 403 , 404 ] ) . toContain ( res . status ) ;
97+ } ) ;
98+ } ) ;
99+
100+ describe ( 'User Registration' , ( ) => {
101+ it ( 'POST /register should create a new user' , async ( ) => {
102+ const uniqueUsername = `testuser_${ Date . now ( ) } ` ;
103+ const res = await requestWithSupertest
104+ . post ( '/register' )
105+ . send ( {
106+ username : uniqueUsername ,
107+ password : 'testpassword123'
108+ } ) ;
109+ // Accept 200 (success), 201 (created), or 302 (redirect to login/home)
110+ expect ( [ 200 , 201 , 302 ] ) . toContain ( res . status ) ;
111+ } ) ;
112+ } ) ;
113+
114+ describe ( 'User Login' , ( ) => {
115+ it ( 'POST /login should authenticate user with valid credentials' , async ( ) => {
116+ // Use a known user or create one in a beforeAll hook
117+ const res = await requestWithSupertest
118+ . post ( '/login' )
119+ . send ( {
120+ username : 'test' , // replace with a valid username
121+ password : 'test' // replace with the correct password
122+ } ) ;
123+ // Accept 200 (success), 302 (redirect), or 401 (unauthorized if wrong)
124+ expect ( [ 200 , 302 , 401 ] ) . toContain ( res . status ) ;
125+ } ) ;
126+ } ) ;
127+
128+
129+ describe ( 'Protected Route' , ( ) => {
130+ it ( 'GET /profile (or another protected route) should require authentication' , async ( ) => {
131+ const res = await requestWithSupertest . get ( '/profile' ) ; // replace with your protected route
132+ // Should be 401 Unauthorized, 403 Forbidden, or 302 Redirect to login
133+ expect ( [ 401 , 403 , 302 ] ) . toContain ( res . status ) ;
17134 } ) ;
18135} ) ;
0 commit comments