import { describe, expect, it } from "vitest";
import {
  GLOBAL_PERSONAL_TENANT_ID,
  resolvePersonalTenant,
} from "./personalTenant";

describe("resolvePersonalTenant", () => {
  it("uses the fixed global Personal tenant when it is not included in the paged tenant list", () => {
    expect(resolvePersonalTenant([])).toMatchObject({
      id: GLOBAL_PERSONAL_TENANT_ID,
      slug: "personal",
      name: "Personal",
      type: "PERSONAL",
      status: "active",
    });
  });

  it("prefers the tenant returned by the API when available", () => {
    expect(
      resolvePersonalTenant([
        {
          id: "api-personal-id",
          slug: "personal",
          name: "Personal",
          type: "PERSONAL",
          status: "active",
          memberCount: 0,
          createdAt: "2026-05-01T00:00:00Z",
          updatedAt: "2026-05-01T00:00:00Z",
        },
      ]),
    ).toMatchObject({
      id: "api-personal-id",
      slug: "personal",
    });
  });
});
