import { FieldType } from "@capakraken/shared";
import { describe, expect, it } from "vitest";
import { buildDynamicFieldWhereClauses } from "../router/custom-field-filters.js";

describe("buildDynamicFieldWhereClauses", () => {
  it("builds prisma-style clauses for supported field types", () => {
    expect(
      buildDynamicFieldWhereClauses([
        { key: "isRemote", value: "true", type: FieldType.BOOLEAN },
        { key: "seniority", value: "3.5", type: FieldType.NUMBER },
        { key: "tools", value: "houdini", type: FieldType.MULTI_SELECT },
        { key: "notes", value: "lead", type: FieldType.TEXT },
      ]),
    ).toEqual([
      { path: ["isRemote"], equals: true },
      { path: ["seniority"], equals: 3.5 },
      { path: ["tools"], array_contains: "houdini" },
      { path: ["notes"], string_contains: "lead" },
    ]);
  });

  it("skips empty and invalid numeric filters", () => {
    expect(
      buildDynamicFieldWhereClauses([
        { key: "empty", value: "", type: FieldType.TEXT },
        { key: "invalidNumber", value: "abc", type: FieldType.NUMBER },
      ]),
    ).toEqual([]);
  });
});
