import { testClient } from "hono/testing";
import { describe, expect, it } from "vitest";
import { createConfig } from "../../config.js";
import { MiddlewareManager } from "../../middlewares/middleware.js";
import { getMainRouter } from "../../routers/index.js";

describe("Authenticated Router", () => {
  // In test mode, createConfig() reads from .env.test
  const config = createConfig();
  MiddlewareManager.initialize(config);
  const app = getMainRouter(config);
  // biome-ignore lint/suspicious/noExplicitAny: testClient requires any for dynamic route access
  const client = testClient(app) as any;

  it("should require authentication", async () => {
    // Try to access a protected route without token
    const res = await client["v1"].users.me.$get();

    // Should fail due to missing authentication
    expect(res.status >= 400).toBeTruthy();
  });

  it("should handle authenticated requests", async () => {
    const token = "this-is-a-very-clean-token";
    const res = await client["v1"].users.me.$get({
      headers: {
        Authorization: `Bearer ${token}`,
        "Content-Type": "application/json",
      },
    });

    // Will fail in test environment but should attempt authentication
    expect(res.status >= 400).toBeTruthy();
  });
});
