import { expect } from "chai";
import { normalizePlaceholderName } from "../src/modules/admin/admin-catalog.service.js";

/**
 * Pure unit tests for {@link normalizePlaceholderName} — the grouping key
 * that collapses near-duplicate placeholder spellings into one catalog gap.
 * No database, so this file can run standalone (`mocha --no-config`) as
 * well as inside the full suite.
 */
describe("normalizePlaceholderName", () => {
  it("lower-cases, strips accents and collapses whitespace", () => {
    expect(normalizePlaceholderName("  Piment   d'Espelette  ")).to.equal("piment d espelette");
    expect(normalizePlaceholderName("PIMENT D’ESPELETTE")).to.equal("piment d espelette");
    expect(normalizePlaceholderName("piment d espelette")).to.equal("piment d espelette");
  });

  it("neutralises punctuation to a single space", () => {
    expect(normalizePlaceholderName("sel & poivre")).to.equal("sel poivre");
    expect(normalizePlaceholderName("sel, poivre")).to.equal("sel poivre");
    expect(normalizePlaceholderName("fleur-de-sel")).to.equal("fleur de sel");
  });

  it("keeps digits (a quantity baked into the name still distinguishes it)", () => {
    expect(normalizePlaceholderName("Chocolat 70%")).to.equal("chocolat 70");
  });

  it("maps an all-punctuation / empty string to an empty key", () => {
    expect(normalizePlaceholderName("")).to.equal("");
    expect(normalizePlaceholderName("   ")).to.equal("");
    expect(normalizePlaceholderName("--- ///")).to.equal("");
  });
});
