Phase 2 of the execution roadmap:
- Add DELETE endpoints for notes (soft-delete), workspaces, tasks, artifacts, relationships
- Add requireWriter() role enforcement on all write routes (POST/PATCH/DELETE)
- Activate trackEvent() telemetry on note.created, note.updated, note.archived, workspace.created
- Gate notes search behind isFeatureEnabled('notes.enabled')
- Update all test mocks to include role and new auth exports
Made-with: Cursor
39 lines
1.1 KiB
TypeScript
39 lines
1.1 KiB
TypeScript
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
import { workspaceRoutes } from './routes.js';
|
|
|
|
const { extractAuthMock } = vi.hoisted(() => ({
|
|
extractAuthMock: vi.fn(async () => ({ sub: 'user_1' })),
|
|
}));
|
|
|
|
vi.mock('../../lib/auth.js', () => ({ extractAuth: extractAuthMock, requireWriter: extractAuthMock }));
|
|
vi.mock('../../lib/product-config.js', () => ({ PRODUCT_ID: 'notelett' }));
|
|
vi.mock('./repository.js', () => ({
|
|
listWorkspaces: vi.fn(async () => ({ items: [], total: 0 })),
|
|
getWorkspace: vi.fn(async () => null),
|
|
createWorkspace: vi.fn(async (doc: unknown) => doc),
|
|
updateWorkspace: vi.fn(async () => null),
|
|
}));
|
|
vi.mock('../notes/repository.js', () => ({
|
|
countNotesByWorkspaces: vi.fn(async () => new Map()),
|
|
}));
|
|
|
|
describe('workspaceRoutes', () => {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks();
|
|
});
|
|
|
|
it('registers route handlers', async () => {
|
|
const app = {
|
|
get: vi.fn(),
|
|
post: vi.fn(),
|
|
patch: vi.fn(),
|
|
};
|
|
|
|
await workspaceRoutes(app as never);
|
|
|
|
expect(app.get).toHaveBeenCalledTimes(3);
|
|
expect(app.post).toHaveBeenCalledTimes(1);
|
|
expect(app.patch).toHaveBeenCalledTimes(1);
|
|
});
|
|
});
|