- 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
37 lines
1.1 KiB
TypeScript
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);
|
|
});
|
|
});
|