| .. | ||
| api.test.ts | ||
| get-token.ts | ||
| payments.test.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 |