import { describe, expect, it } from "vitest";
import {
  buildAdminAuthRedirectUris,
  resolveAdminPublicOrigin,
} from "./authConfig";

describe("admin auth config", () => {
  it("uses the explicit public admin origin for staging callback URLs", () => {
    const publicOrigin = resolveAdminPublicOrigin(
      "https://sadmin.hmac.kr",
      "http://127.0.0.1:5173",
    );

    expect(publicOrigin).toBe("https://sadmin.hmac.kr");
    expect(buildAdminAuthRedirectUris(publicOrigin)).toEqual({
      redirectUri: "https://sadmin.hmac.kr/auth/callback",
      postLogoutRedirectUri: "https://sadmin.hmac.kr",
      popupRedirectUri: "https://sadmin.hmac.kr/auth/callback",
    });
  });

  it("falls back to the browser origin when no explicit public origin is set", () => {
    expect(resolveAdminPublicOrigin("", "http://localhost:5173")).toBe(
      "http://localhost:5173",
    );
  });
});
