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
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.
Test invocations appear in the Logs tab with a test badge so they are easily distinguishable from production executions.
Test via the SDK
From Flutter, pass testMode: true to the invoke call:
final result = await Koolbase.functions.invoke(
'send-welcome-email',
body: {'userId': 'test-user-123'},
testMode: true, // mock DB, no real writes
);
print(result.data); // function output with mock DB responsesMock 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', results: [] }
return { ok: true, testResult: result };
}Detecting test mode in your function
ctx.request.__test === true inside the function to conditionally skip external API calls during test runs. This gives you full control over what executes in test mode.