learning_ai_notes/backend/src/modules/note-artifacts/routes.test.ts
saravanakumardb1 6acd1a70d4 fix(backend): fix trackEvent call signature and route registration tests
- auth.ts: type requireWriter param as { headers: { authorization?: string } } instead of unknown
- notes/routes.ts: fix 3 trackEvent calls from object form to positional args (event, userId, properties)
- workspaces/routes.ts: fix 1 trackEvent call from object form to positional args
- 5 route registration tests: add missing delete mock to app object for Phase 2 DELETE endpoints
2026-03-31 01:00:32 -07:00

38 lines
1.1 KiB
TypeScript

import { beforeEach, describe, expect, it, vi } from 'vitest';
import { noteArtifactRoutes } 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', () => ({
listNoteArtifacts: vi.fn(async () => ({ items: [], total: 0 })),
getNoteArtifact: vi.fn(async () => null),
createNoteArtifact: vi.fn(async (doc: unknown) => doc),
updateNoteArtifact: vi.fn(async () => null),
}));
describe('noteArtifactRoutes', () => {
beforeEach(() => {
vi.clearAllMocks();
});
it('registers route handlers', async () => {
const app = {
get: vi.fn(),
post: vi.fn(),
patch: vi.fn(),
delete: vi.fn(),
};
await noteArtifactRoutes(app as never);
expect(app.get).toHaveBeenCalledTimes(1);
expect(app.post).toHaveBeenCalledTimes(1);
expect(app.patch).toHaveBeenCalledTimes(1);
expect(app.delete).toHaveBeenCalledTimes(1);
});
});