learning_ai_notes/backend/src/modules/note-relationships/routes.integration.test.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

63 lines
2.1 KiB
TypeScript

import { afterAll, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest';
import type { FastifyInstance } from 'fastify';
const { extractAuthMock } = vi.hoisted(() => ({
extractAuthMock: vi.fn(async () => ({ sub: 'user_1', type: 'access' })),
}));
vi.mock('../../lib/auth.js', () => ({ extractAuth: extractAuthMock }));
vi.mock('../../lib/product-config.js', () => ({ PRODUCT_ID: 'notelett' }));
import { buildTestApp, resetMemoryDatastore } from '../../test-helpers.js';
import { noteRelationshipRoutes } from './routes.js';
let app: FastifyInstance;
beforeAll(async () => {
app = await buildTestApp(noteRelationshipRoutes);
});
beforeEach(() => {
resetMemoryDatastore();
});
afterAll(async () => {
await app.close();
});
const validRelationship = {
id: 'rel-1',
workspaceId: 'ws-1',
fromNoteId: 'note-1',
toNoteId: 'note-2',
relationshipType: 'related',
};
describe('note-relationships routes — integration', () => {
it('POST /note-relationships creates a relationship and returns 201', async () => {
const res = await app.inject({ method: 'POST', url: '/api/note-relationships', payload: validRelationship });
expect(res.statusCode).toBe(201);
const body = res.json();
expect(body.id).toBe('rel-1');
expect(body.fromNoteId).toBe('note-1');
expect(body.toNoteId).toBe('note-2');
});
it('GET /note-relationships lists relationships by workspaceId', async () => {
await app.inject({ method: 'POST', url: '/api/note-relationships', payload: validRelationship });
const res = await app.inject({ method: 'GET', url: '/api/note-relationships?workspaceId=ws-1' });
expect(res.statusCode).toBe(200);
expect(res.json().items).toHaveLength(1);
});
it('GET /note-relationships requires workspaceId', async () => {
const res = await app.inject({ method: 'GET', url: '/api/note-relationships' });
expect(res.statusCode).toBe(400);
});
it('POST /note-relationships rejects invalid body', async () => {
const res = await app.inject({ method: 'POST', url: '/api/note-relationships', payload: { id: 'x' } });
expect(res.statusCode).toBe(400);
});
});