import { describe, it, expect } from "vitest";
import { isOnboardingExempt } from "../../root";

describe("isOnboardingExempt", () => {
  it("exempts /onboarding exactly", () => {
    expect(isOnboardingExempt("/onboarding")).toBe(true);
  });

  it("exempts /onboarding sub-paths", () => {
    expect(isOnboardingExempt("/onboarding/step2")).toBe(true);
  });

  it("exempts /api/ prefix paths", () => {
    expect(isOnboardingExempt("/api/auth/callback")).toBe(true);
    expect(isOnboardingExempt("/api/draft/start")).toBe(true);
  });

  it("does not exempt paths that merely start with /api without trailing slash", () => {
    // /api/ has a trailing slash so startsWith("/api/") is used — /apiary would not match
    expect(isOnboardingExempt("/apiary")).toBe(false);
  });

  it("exempts auth pages exactly", () => {
    expect(isOnboardingExempt("/login")).toBe(true);
    expect(isOnboardingExempt("/register")).toBe(true);
    expect(isOnboardingExempt("/check-email")).toBe(true);
    expect(isOnboardingExempt("/forgot-password")).toBe(true);
    expect(isOnboardingExempt("/reset-password")).toBe(true);
  });

  it("does not exempt a path that merely starts with an exempt path without slash", () => {
    expect(isOnboardingExempt("/registered-user")).toBe(false);
    expect(isOnboardingExempt("/loginpage")).toBe(false);
  });

  it("exempts /admin and all sub-paths", () => {
    expect(isOnboardingExempt("/admin")).toBe(true);
    expect(isOnboardingExempt("/admin/users")).toBe(true);
    expect(isOnboardingExempt("/admin/sports-seasons/123")).toBe(true);
  });

  it("does not exempt normal app routes", () => {
    expect(isOnboardingExempt("/")).toBe(false);
    expect(isOnboardingExempt("/leagues/abc")).toBe(false);
    expect(isOnboardingExempt("/settings")).toBe(false);
  });
});
