kaboot/server/tests
2026-01-15 19:52:05 -07:00
..
api.test.ts Add tests 2026-01-15 19:52:05 -07:00
get-token.ts Fix tests 2026-01-13 15:27:46 -07:00
README.md Phase 2 + 3 complete 2026-01-13 15:20:46 -07:00
run-tests.ts Fix tests 2026-01-13 15:27:46 -07:00

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)

  1. Start the Kaboot frontend: npm run dev (in root directory)
  2. Open http://localhost:5173
  3. Click "Sign In" and log in with Authentik
  4. Open browser DevTools (F12)
  5. Go to Application > Local Storage > http://localhost:5173
  6. Find the key starting with oidc.user:
  7. Click on it and find "access_token" in the JSON value
  8. Copy the token value (without quotes)

Method 2: Service Account

  1. Go to Authentik Admin: http://localhost:9000/if/admin/
  2. Navigate to Directory > Users
  3. Click Create Service Account
  4. Enter a name (e.g., kaboot-test-service)
  5. Note the generated username and token
  6. 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