import { describe, expect, it } from "vitest";
import {
  buildOrgPickerEmbedSrc,
  parseOrgPickerEmbedOptions,
} from "./pickerTypes";

describe("org picker embed options", () => {
  it("builds slug-based tenant scope urls", () => {
    expect(
      buildOrgPickerEmbedSrc({
        mode: "single",
        select: "tenant",
        includeDescendants: true,
        showDescendantToggle: true,
        tenantId: "saman",
        width: 400,
        height: 600,
      }),
    ).toBe(
      "/embed/picker?mode=single&select=tenant&width=400&height=600&tenantSlug=saman",
    );
  });

  it("parses tenantSlug first and keeps legacy tenantId compatibility", () => {
    expect(
      parseOrgPickerEmbedOptions(
        "?tenantId=legacy-id&tenantSlug=saman&companyTenantId=legacy-company",
      ).tenantId,
    ).toBe("saman");
    expect(parseOrgPickerEmbedOptions("?tenantId=legacy-id").tenantId).toBe(
      "legacy-id",
    );
  });
});
