import { beforeEach, describe, expect, it, vi } from 'vitest';
import { noteTaskRoutes } 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', () => ({
  listNoteTasks: vi.fn(async () => ({ items: [], total: 0 })),
  getNoteTask: vi.fn(async () => null),
  createNoteTask: vi.fn(async (doc: unknown) => doc),
  updateNoteTask: vi.fn(async () => null),
}));

describe('noteTaskRoutes', () => {
  beforeEach(() => {
    vi.clearAllMocks();
  });

  it('registers route handlers', async () => {
    const app = {
      get: vi.fn(),
      post: vi.fn(),
      patch: vi.fn(),
    };

    await noteTaskRoutes(app as never);

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