import { describe, expect, it } from "vitest";
import { normalizeQuery, parsePriceEur } from "../src/core/normalize.js";

describe("normalizeQuery", () => {
  it("strips punctuation and uppercases", () => {
    expect(normalizeQuery("09.C881-11")?.canonical).toBe("09C88111");
    expect(normalizeQuery("w 712/52")?.canonical).toBe("W71252");
    expect(normalizeQuery("  W 712/52 ")?.raw).toBe("W 712/52");
  });

  it("rejects too-short input", () => {
    expect(normalizeQuery("W7")).toBeNull();
    expect(normalizeQuery(" .-/ ")).toBeNull();
    expect(normalizeQuery("W712")).not.toBeNull();
  });
});

describe("parsePriceEur", () => {
  it("parses Latvian store price formats", () => {
    expect(parsePriceEur("8,24 €")).toBe(8.24);
    expect(parsePriceEur("5,42 €")).toBe(5.42);
    expect(parsePriceEur("1 234,56 €")).toBe(1234.56);
    expect(parsePriceEur("1.234,56")).toBe(1234.56);
    expect(parsePriceEur("8.24")).toBe(8.24);
  });

  it("returns NaN when there is no number", () => {
    expect(parsePriceEur("—")).toBeNaN();
  });
});
