import { describe, expect, it } from "vitest";
import { shouldStartLoginRedirect } from "../../../common/core/auth";

describe("shouldStartLoginRedirect", () => {
  it("blocks redirects while a login redirect is already in flight", () => {
    expect(
      shouldStartLoginRedirect({
        pathname: "/users",
        isRedirecting: true,
      }),
    ).toBe(false);
  });

  it("blocks redirects from auth callback and login paths", () => {
    expect(
      shouldStartLoginRedirect({
        pathname: "/auth/callback",
        isRedirecting: false,
      }),
    ).toBe(false);
    expect(
      shouldStartLoginRedirect({
        pathname: "/login",
        isRedirecting: false,
      }),
    ).toBe(false);
  });

  it("allows a redirect from protected app paths", () => {
    expect(
      shouldStartLoginRedirect({
        pathname: "/tenants",
        isRedirecting: false,
      }),
    ).toBe(true);
  });
});
