- README with quick start, package overview, links to docs - docs/setup.md — prerequisites, env vars, installation, running, testing - docs/architecture.md — monorepo structure, backend/frontend design - docs/api.md — full endpoint reference with permissions - docs/database.md — schema overview, migrations, multi-tenancy - docs/testing.md — test runner, suites, writing tests - Updated .env.example with all supported variables
2.2 KiB
2.2 KiB
Testing
API Integration Tests
The primary test suite lives at packages/backend/api-tests/. It uses a custom runner that:
- Creates/migrates a
forte_api_testdatabase - Seeds company, lookup tables, RBAC permissions/roles
- Starts the backend on port 8001
- Registers a test user with admin role
- Runs test suites via HTTP requests
- Tears down the server
Running
cd packages/backend
source .env # needs DB credentials
bun run api-test
Filtering
bun run api-test --suite accounts # run only the accounts suite
bun run api-test --tag crud # run tests tagged 'crud'
Suites
| Suite | Tests | Coverage |
|---|---|---|
accounts |
17 | CRUD, search, pagination, sort, billing mode |
members |
19 | CRUD, search, move, isMinor, address inheritance |
files |
7 | Upload, list, get, delete, validation, profile pictures |
rbac |
21 | Permission enforcement, role CRUD, user status, pagination |
Writing Tests
Tests are defined in api-tests/suites/. Each file exports a suite:
import { suite } from '../lib/context.js'
suite('MyDomain', { tags: ['domain'] }, (t) => {
t.test('does something', { tags: ['crud'] }, async () => {
const res = await t.api.post('/v1/endpoint', { name: 'Test' })
t.assert.status(res, 201)
t.assert.equal(res.data.name, 'Test')
})
})
Available on t:
t.api— HTTP client (get,post,patch,del) with auth tokent.token— JWT token stringt.baseUrl— Backend URLt.assert— Assertion helpers (status,equal,ok,includes,greaterThan, etc.)
Assert Methods
| Method | Description |
|---|---|
status(res, code) |
Check HTTP status |
equal(a, b) |
Strict equality |
notEqual(a, b) |
Strict inequality |
ok(value) |
Truthy check |
includes(arr, value) |
Array includes |
contains(str, sub) |
String contains |
greaterThan(a, b) |
Numeric comparison |
Unit Tests
Unit tests use bun:test and live alongside the code or in __tests__/:
cd packages/backend
bun run test
Current unit test coverage: shared utils (date helpers, currency formatting, state normalization).