馃 distributed transcription service
thistle.dunkirk.sh
API Integration Tests#
This file (src/index.test.ts) contains comprehensive integration tests for all API endpoints in the Thistle application.
Running the Tests#
Option 1: Manual Server Start (Recommended for Development)#
-
Start the test server in one terminal:
PORT=3001 bun run src/index.ts -
Run the integration tests in another terminal:
bun test src/index.test.ts
Option 2: Run All Tests#
To run all tests (both unit and integration):
bun test
Note: Integration tests will be skipped if the test server is not running on port 3001.
Test Coverage#
The integration tests cover the following endpoint groups:
Authentication Endpoints#
POST /api/auth/register- User registration with validation and rate limitingPOST /api/auth/login- User login with rate limitingPOST /api/auth/logout- User logoutGET /api/auth/me- Get current user information
Session Management#
GET /api/sessions- List user sessionsDELETE /api/sessions- Delete specific session
User Management#
DELETE /api/user- Delete user accountPUT /api/user/email- Update user emailPUT /api/user/password- Update user passwordPUT /api/user/name- Update user namePUT /api/user/avatar- Update user avatar
Passkey Management#
POST /api/passkeys/register/options- Get passkey registration optionsPOST /api/passkeys/register/verify- Verify and create passkeyPOST /api/passkeys/authenticate/options- Get authentication optionsPOST /api/passkeys/authenticate/verify- Verify and authenticate with passkeyGET /api/passkeys- List user passkeysPUT /api/passkeys/:id- Update passkey nameDELETE /api/passkeys/:id- Delete passkey
Health Endpoint#
GET /api/health- Check service health (database, whisper, storage)
Transcription Endpoints#
GET /api/transcriptions- List user transcriptionsPOST /api/transcriptions- Upload audio file and start transcriptionGET /api/transcriptions/:id- Get transcription detailsGET /api/transcriptions/:id/audio- Get audio file with range supportGET /api/transcriptions/:id/stream- SSE stream for transcription updates
Admin Endpoints#
GET /api/admin/users- List all usersGET /api/admin/users/:id/details- Get user detailsDELETE /api/admin/users/:id- Delete userPUT /api/admin/users/:id/role- Update user rolePUT /api/admin/users/:id/name- Update user namePUT /api/admin/users/:id/email- Update user emailPOST /api/admin/users/:id/password-reset- Send password reset emailGET /api/admin/users/:id/sessions- List user sessionsDELETE /api/admin/users/:id/sessions- Delete all user sessionsDELETE /api/admin/users/:id/sessions/:sessionId- Delete specific sessionDELETE /api/admin/users/:id/passkeys/:passkeyId- Delete user passkeyGET /api/admin/transcriptions- List all transcriptionsGET /api/admin/transcriptions/:id/details- Get transcription detailsDELETE /api/admin/transcriptions/:id- Delete transcription
Test Features#
- Automatic cleanup: Test data is cleaned up before and after each test
- Rate limit testing: Validates rate limiting on sensitive endpoints
- Authorization testing: Ensures proper authentication and authorization
- Validation testing: Checks input validation and error handling
- Security testing: Tests for common vulnerabilities
- File upload testing: Validates file type and size restrictions
Test Database#
Tests use the same database as development. Test users and data are identified by email patterns (test%, admin@%) and are automatically cleaned up after tests run.
Continuous Integration#
For CI/CD pipelines, you can use a background server:
# Start server in background
PORT=3001 bun run src/index.ts &
SERVER_PID=$!
# Wait for server to be ready
sleep 2
# Run tests
bun test src/index.test.ts
# Kill server
kill $SERVER_PID
Troubleshooting#
Tests are being skipped#
- Make sure the test server is running on port 3001
- Check that there are no port conflicts
- Verify the server started successfully (check console output)
Tests are failing with connection errors#
- Ensure no firewall is blocking localhost connections
- Try increasing the timeout in the
beforeAllhook - Check that the database is accessible
Rate limit tests are flaky#
- Rate limits are shared across test runs
- Clean test data between runs:
rm thistle.db - Or adjust rate limit test expectations