Testing

Tests run with bun test and call routes through the full pipeline, without an HTTP server.

import { afterAll, beforeAll, expect, test } from 'bun:test'
import { createTestApp, testIdentity, type TestApp } from '@fellowframework/core/testing'

let app: TestApp
beforeAll(async () => { app = await createTestApp({ migrate: true }) })
afterAll(() => app.close())

test('records.documents.get never crosses tenants', async () => {
  const alice = testIdentity({ permissions: ['records.document.*'] })
  const bob = testIdentity({ permissions: ['records.document.*'] })
  const created = await app.call('records.documents.create', { identity: alice, body: { title: 'A', status: 'open' } })
  const response = await app.call('records.documents.get', { identity: bob, params: { id: created.body.id } })
  expect(response.status).toBe(404)
})
  • app.call(routeId, { identity, params, query, body }) returns { status, body }.
  • testIdentity() creates an identity in a fresh random tenant, so tests do not need to clean the database and can run against a shared development database.
  • Omit identity for an anonymous call.

What to test for every route

Success, invalid input (422), anonymous (401), missing permission (403) and cross-tenant access. fellow make:resource generates all of them. A route no test mentions raises warning FW-TEST-001.

Running

  • fellow test [bun test args]: runs tests. Exit 1 means tests failed (code); exit 3 means they could not run (environment, e.g. database unreachable).
  • fellow check --tests: architecture rules, types and tests in one command.