Test Mode
Run functions with a mock database so you can validate logic without writing real data or triggering side effects.
How test mode works
When a function is invoked with test: true, Koolbase replaces the real database context with a mock. All ctx.db operations return simulated responses — no real records are created, updated, or deleted.
The function code runs fully — external API calls, secret access, and all logic execute normally. Only the database operations are intercepted.
External API calls still execute
ctx.queue: in test mode, ctx.queue.enqueue returns a fake job ({ id: "test-job", test_mode: true }) and queues nothing. Calls to external services — email APIs, payment processors, Slack — still execute. To avoid side effects during testing, guard those calls with ctx.testMode.Test from the dashboard
In the Functions dashboard, the Invoke tab sends requests directly. The Triggers tab has a Play button on each trigger row that opens a test modal — enter a sample payload and click Run Test.
The trigger test modal wraps your sample payload exactly the way a real event would deliver it (payload.record for created/updated, payload.record_id for deleted) — so a function that passes the test handles production events identically. Test invocations appear in the Logs tab with a test badge so they are easily distinguishable from production executions.
Mock database responses
When test mode is active, all ctx.db operations return a simulated response:
export async function handler(ctx) {
// In test mode, ctx.db.insert returns:
// { __test: true, simulated: 'insert', collection: 'users', data: {...} }
const result = await ctx.db.insert('users', { name: 'Test User' });
console.log(result.__test); // true
console.log(result.simulated); // 'insert'
// ctx.db.find returns:
// { __test: true, simulated: 'find', records: [] }
return { ok: true, testResult: result };
}Detecting test mode in your function
ctx.testMode (Dart: ctx['testMode']) inside the function to skip outside calls during a test run. It is true on a test run and false otherwise.