learning_ai_notes/backend/src/modules/workspaces/routes.test.ts
Saravana Achu Mac 8d84bcb841 feat: add DELETE endpoints, role enforcement, telemetry and feature flags
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
2026-03-29 20:47:12 -07:00

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);
});
});