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 }));
vi.mock('../../lib/product-config.js', () => ({ PRODUCT_ID: 'bytelyst-notes' }));
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(),
    };

    await noteArtifactRoutes(app as never);

    expect(app.get).toHaveBeenCalledTimes(1);
    expect(app.post).toHaveBeenCalledTimes(1);
    expect(app.patch).toHaveBeenCalledTimes(1);
  });
});
