import { describe, expect, it } from "vitest";
import type { UserSummary } from "../../lib/adminApi";
import { getOrgChartUserDisplayName } from "./userDisplay";

function user(overrides: Partial<UserSummary>): UserSummary {
  return {
    id: "user-1",
    email: "user@example.com",
    name: "홍길동",
    role: "user",
    status: "active",
    createdAt: "",
    updatedAt: "",
    ...overrides,
  };
}

describe("getOrgChartUserDisplayName", () => {
  it("renders name with grade and optional position", () => {
    expect(
      getOrgChartUserDisplayName(
        user({
          grade: "수석",
          position: "팀장",
        }),
      ),
    ).toBe("홍길동 수석(팀장)");
  });

  it("uses tenant appointment grade before the user grade", () => {
    expect(
      getOrgChartUserDisplayName(
        user({
          grade: "책임",
          metadata: {
            additionalAppointments: [
              {
                tenantSlug: "hanmac",
                grade: "수석",
                position: "센터장",
              },
            ],
          },
        }),
        { id: "tenant-1", slug: "hanmac" },
      ),
    ).toBe("홍길동 수석(센터장)");
  });
});
