import { expect, test } from "vitest";

import { pruneFields } from "./prune-fields";

test("drops empty/null/undefined scalars, keeps real scalars", () => {
  const out = pruneFields(
    { a: "x", b: "", c: null, d: undefined, e: 0, f: false },
    new Set(),
    "en",
  );
  expect(out).toEqual({ a: "x", e: 0, f: false });
});

test("a localized_text key keeps only the default-language entry", () => {
  const out = pruneFields(
    { title: { en: "Bowl", sv: "Skål" } },
    new Set(["title"]),
    "sv",
  );
  expect(out).toEqual({ title: { sv: "Skål" } });
});

test("a non-localized object value keeps all non-empty entries", () => {
  const out = pruneFields(
    { dims: { w: "10", h: "", d: "5" } },
    new Set(),
    "en",
  );
  expect(out).toEqual({ dims: { w: "10", d: "5" } });
});

test("an object value left with no entries is dropped entirely", () => {
  const out = pruneFields(
    { title: { en: "Bowl" }, empty: { en: "", sv: "" } },
    new Set(["title", "empty"]),
    "sv",
  );
  expect(out).toEqual({});
});
