import { describe, expect, it } from "vitest";

import { getRouteAccess, isInternalRoute } from "../route-meta";
import { ALL_STATIC_ROUTES, ROUTES } from "../routes";

describe("route meta", () => {
  it("classifies static routes by access level", () => {
    expect(getRouteAccess(ROUTES.splash)).toBe("authOnly");
    expect(getRouteAccess(ROUTES.auth)).toBe("authOnly");
    expect(getRouteAccess(ROUTES.chat)).toBe("guestEntry");
    expect(getRouteAccess(ROUTES.privateRoom)).toBe("guestEntry");
    expect(getRouteAccess(ROUTES.tip)).toBe("public");
    expect(getRouteAccess(ROUTES.externalEntry)).toBe("public");
    expect(getRouteAccess(ROUTES.sidebar)).toBe("session");
    expect(getRouteAccess(ROUTES.subscription)).toBe("realUser");
    expect(getRouteAccess(ROUTES.coinsRules)).toBe("public");
  });

  it("does not keep the removed chat image route as a guarded route", () => {
    expect(getRouteAccess("/chat/image/msg_1")).toBe("public");
  });

  it("includes private room in static routes", () => {
    expect(ALL_STATIC_ROUTES).toContain(ROUTES.privateRoom);
  });

  it("includes tip in static routes", () => {
    expect(ALL_STATIC_ROUTES).toContain(ROUTES.tip);
  });

  it("includes external entry in static routes", () => {
    expect(ALL_STATIC_ROUTES).toContain(ROUTES.externalEntry);
  });

  it("treats unknown routes as public by default", () => {
    expect(getRouteAccess("/unknown")).toBe("public");
  });

  it("accepts only internal redirect targets", () => {
    expect(isInternalRoute("/chat")).toBe(true);
    expect(isInternalRoute("/subscription?type=vip")).toBe(true);
    expect(isInternalRoute("https://example.com/chat")).toBe(false);
    expect(isInternalRoute("//example.com/chat")).toBe(false);
    expect(isInternalRoute(null)).toBe(false);
  });
});
