Add a centralized game configuration system that allows customizable scoring mechanics and game rules. Users can now set default game configurations that persist across sessions, and individual quizzes can have their own configuration overrides. ## New Features ### Game Configuration Options - Shuffle Questions: Randomize question order when starting a game - Shuffle Answers: Randomize answer positions for each question - Host Participates: Toggle whether the host plays as a competitor or spectates (host now shows as 'Spectator' when not participating) - Streak Bonus: Multiplied points for consecutive correct answers, with configurable threshold and multiplier values - Comeback Bonus: Extra points for players ranked below top 3 - Wrong Answer Penalty: Deduct percentage of max points for incorrect answers (configurable percentage) - First Correct Bonus: Extra points for the first player to answer correctly on each question ### Default Settings Management - New Settings icon in landing page header (authenticated users only) - DefaultConfigModal for editing user-wide default game settings - Default configs are loaded when creating new quizzes - Defaults persist to database via new user API endpoints ### Reusable UI Components - GameConfigPanel: Comprehensive toggle-based settings panel with expandable sub-options, tooltips, and suggested values based on question count - DefaultConfigModal: Modal wrapper for editing default configurations ## Technical Changes ### Frontend - New useUserConfig hook for fetching/saving user default configurations - QuizEditor now uses GameConfigPanel instead of inline toggle checkboxes - GameScreen handles spectator mode with disabled answer buttons - Updated useGame hook with new scoring calculations and config state - Improved useAuthenticatedFetch with deduped silent refresh and redirect-once pattern to prevent multiple auth redirects ### Backend - Added game_config column to quizzes table (JSON storage) - Added default_game_config column to users table - New PATCH endpoint for quiz config updates: /api/quizzes/:id/config - New PUT endpoint for user defaults: /api/users/me/default-config - Auto-migration in connection.ts for existing databases ### Scoring System - New calculatePoints() function in constants.ts handles all scoring logic including streaks, comebacks, penalties, and first-correct bonus - New calculateBasePoints() for time-based point calculation - New getPlayerRank() helper for comeback bonus eligibility ### Tests - Added tests for DefaultConfigModal component - Added tests for GameConfigPanel component - Added tests for QuizEditor config integration - Added tests for useUserConfig hook - Updated API tests for new endpoints ## Type Changes - Added GameConfig interface with all configuration options - Added DEFAULT_GAME_CONFIG constant with sensible defaults - Quiz type now includes optional config property |
||
|---|---|---|
| .. | ||
| api.test.ts | ||
| get-token.ts | ||
| README.md | ||
| run-tests.ts | ||
Kaboot Backend API Tests
Getting a Test Token
Since Authentik uses OAuth2 flows that require browser interaction, you need to obtain a token manually.
Method 1: Browser DevTools (Easiest)
- Start the Kaboot frontend:
npm run dev(in root directory) - Open
http://localhost:5173 - Click "Sign In" and log in with Authentik
- Open browser DevTools (F12)
- Go to Application > Local Storage >
http://localhost:5173 - Find the key starting with
oidc.user: - Click on it and find
"access_token"in the JSON value - Copy the token value (without quotes)
Method 2: Service Account
- Go to Authentik Admin:
http://localhost:9000/if/admin/ - Navigate to Directory > Users
- Click Create Service Account
- Enter a name (e.g.,
kaboot-test-service) - Note the generated username and token
- Use these credentials:
TEST_USERNAME=<service-account-username> \ TEST_PASSWORD=<generated-token> \ npm run test:get-token
Running Tests
cd server
npm install
# Set the token you obtained
export TEST_TOKEN="your-access-token-here"
# Run tests
npm run test
Test Coverage
The test suite covers:
- Health Check: Basic server availability
- Authentication: 401 without token, 401 with invalid token
- User API: GET /api/users/me
- Quiz CRUD:
- GET /api/quizzes (list)
- POST /api/quizzes (create)
- GET /api/quizzes/:id (read)
- PUT /api/quizzes/:id (update)
- DELETE /api/quizzes/:id (delete)
Environment Variables
| Variable | Default | Description |
|---|---|---|
API_URL |
http://localhost:3001 |
Backend API URL |
TEST_TOKEN |
(required) | JWT access token from Authentik |
AUTHENTIK_URL |
http://localhost:9000 |
Authentik server URL |
CLIENT_ID |
kaboot-spa |
OAuth2 client ID |
TEST_USERNAME |
kaboottest |
Username for token request |
TEST_PASSWORD |
kaboottest |
Password for token request |