learning_ai_notes/backend/src/modules/note-agent-actions/routes.test.ts
saravanakumardb1 ee586065dd refactor(web+backend): consolidate types, optimize N+1 queries [D1, A3, A4, D2]
- types.ts: consolidate NoteDoc, WorkspaceDoc, NoteAgentActionDoc etc. from client files
- notes-client.ts: import from types.ts, optimize getNoteDetail with direct GET /notes/:id
- review-client.ts: import from types.ts, use /note-agent-actions/pending (eliminates N+1)
- notes-client.ts: use /workspaces/summaries (eliminates fetch-all-notes for counts)
- backend: add GET /workspaces/summaries with noteCount per workspace
- backend: add GET /note-agent-actions/pending (cross-workspace)
- backend: add countNotesByWorkspaces + listPendingActions repository functions
- Add createNote, archiveNote, restoreNote, createNoteRelationship client functions
- Fix existing tests for new route counts and mock order
2026-03-19 07:32:54 -07:00

37 lines
1.1 KiB
TypeScript

import { beforeEach, describe, expect, it, vi } from 'vitest';
import { noteAgentActionRoutes } from './routes.js';
const { extractAuthMock } = vi.hoisted(() => ({
extractAuthMock: vi.fn(async () => ({ sub: 'user_1' })),
}));
vi.mock('../../lib/auth.js', () => ({ extractAuth: extractAuthMock }));
vi.mock('../../lib/product-config.js', () => ({ PRODUCT_ID: 'notelett' }));
vi.mock('./repository.js', () => ({
listNoteAgentActions: vi.fn(async () => ({ items: [], total: 0 })),
listPendingActions: vi.fn(async () => ({ items: [], total: 0 })),
getNoteAgentAction: vi.fn(async () => null),
createNoteAgentAction: vi.fn(async (doc: unknown) => doc),
updateNoteAgentAction: vi.fn(async () => null),
}));
describe('noteAgentActionRoutes', () => {
beforeEach(() => {
vi.clearAllMocks();
});
it('registers route handlers', async () => {
const app = {
get: vi.fn(),
post: vi.fn(),
patch: vi.fn(),
};
await noteAgentActionRoutes(app as never);
expect(app.get).toHaveBeenCalledTimes(2);
expect(app.post).toHaveBeenCalledTimes(2);
expect(app.patch).toHaveBeenCalledTimes(1);
});
});