Integration Tests
This directory contains integration tests for the Formbricks Hub API.
Prerequisites
Before running the tests, ensure:
- PostgreSQL is running (e.g.
make docker-up). make docker-up starts dependency containers: PostgreSQL, the one-shot hub-migrate container, and River UI; it does not start the Hub API or worker. The tests use the connection string from .env (DATABASE_URL) when set; if empty, the default postgres://postgres:postgres@localhost:5432/test_db?sslmode=disable is used. If you set POSTGRES_PORT in .env, keep DATABASE_URL in sync.
- Database schema and River queue migrations have been initialized. The default
make docker-up path runs them through the packaged hub-migrate container, using this checkout's migrations/ directory. If you are editing local migration files after the stack is already running, run make init-db and make river-migrate against your test database.
- API_KEY is set automatically by the tests; you do not need to set it.
Running Tests
Run all integration tests:
go test ./tests/... -v
Run a specific test:
go test ./tests -run TestHealthEndpoint -v
Run tests with coverage:
go test ./tests/... -v -cover
Test Structure
integration_test.go - Main integration tests for all API endpoints
helpers.go - Helper functions for test setup and cleanup
Test Coverage
The integration tests cover:
- ✅ Health endpoint (public)
- ✅ Create feedback records (with/without auth)
- ✅ List feedback records (with tenant and other filters)
- ✅ Get feedback record by ID
- ✅ Update feedback record
- ✅ Delete feedback record
- ✅ Delete feedback records by user
- ✅ Delete tenant data (feedback records, embeddings, webhooks)
- ✅ Webhook CRUD and validation
- ✅ Authentication middleware
- ✅ Error handling
Test API Key
The tests use a predefined API key: test-api-key-12345
The test setup automatically sets this key in the API_KEY environment variable for authentication.
Notes
- Tests use the actual database configured in
.env
- Tests create real data in the database
- Consider using a separate test database for isolation
- Semantic search is covered in handler and service tests; these integration tests focus on database-backed CRUD and webhook routes.