learning_ai_notes/backend/src/test-helpers.ts
saravanakumardb1 bf2785bcf9 test(backend): add integration tests for all 7 route modules [A5]
- Add test-helpers.ts with buildTestApp() + resetMemoryDatastore()
- notes: 11 tests (CRUD, archive, filter, search, validation)
- workspaces: 7 tests (CRUD, summaries with noteCount, validation)
- note-tasks: 6 tests (CRUD, filter by workspaceId, validation)
- note-artifacts: 7 tests (CRUD, filter by noteId, validation)
- note-relationships: 4 tests (create, list, validation)
- note-agent-actions: 8 tests (CRUD, pending, batch-review, validation)
- saved-views: 8 tests (CRUD, filter by scope, delete, validation)
- Fix listPendingActions to avoid unsupported $in operator in memory provider
- Total: 75 backend tests (was 24)
2026-03-19 08:38:21 -07:00

27 lines
708 B
TypeScript

import Fastify from 'fastify';
import { MemoryDatastoreProvider } from '@bytelyst/datastore';
import { setProvider } from './lib/datastore.js';
export function resetMemoryDatastore(): void {
const provider = new MemoryDatastoreProvider();
setProvider(provider);
}
export async function buildTestApp(
routePlugin: (app: ReturnType<typeof Fastify>) => Promise<void>,
) {
resetMemoryDatastore();
const app = Fastify({ logger: false });
await app.register(routePlugin, { prefix: '/api' });
await app.ready();
return app;
}
export const TEST_USER_ID = 'test-user-1';
export const TEST_PRODUCT_ID = 'notelett';
export function authHeader() {
return { authorization: 'Bearer test-token' };
}