import { describe, expect, it } from "vitest";
import { createSchemaField, normalizeSchemaField } from "./tenantSchemaFields";

describe("TenantSchemaPage schema field helpers", () => {
  it("creates text fields without varchar maxLength policy", () => {
    const field = createSchemaField();

    expect(field.type).toBe("text");
    expect("maxLength" in field).toBe(false);
    expect(field.indexed).toBe(false);
  });

  it("does not add maxLength to legacy text schema fields", () => {
    const field = normalizeSchemaField({
      key: "emp_id",
      label: "사번",
      type: "text",
    });

    expect("maxLength" in field).toBe(false);
  });

  it("forces indexed when a field can be used as login ID", () => {
    const field = normalizeSchemaField({
      key: "emp_id",
      label: "사번",
      type: "text",
      indexed: false,
      isLoginId: true,
    });

    expect(field.indexed).toBe(true);
    expect(field.isLoginId).toBe(true);
  });
});
