fix(amazon-shopping): verify prime and delivery filters
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { describe, it } from "node:test";
|
||||
|
||||
import { extractWidthInches, formatWidthInches } from "../src/product-metrics.js";
|
||||
import type { ProductSearchResult } from "../src/types.js";
|
||||
|
||||
function product(overrides: Partial<ProductSearchResult>): ProductSearchResult {
|
||||
return {
|
||||
asin: "B0WIDTH001",
|
||||
title: "Base Product",
|
||||
url: "https://www.amazon.com/dp/B0WIDTH001",
|
||||
specs: [],
|
||||
bullets: [],
|
||||
matchedFilters: [],
|
||||
missingFields: [],
|
||||
extractionNotes: [],
|
||||
...overrides
|
||||
};
|
||||
}
|
||||
|
||||
describe("product metrics", () => {
|
||||
it("extracts explicit W dimensions from overall product specs", () => {
|
||||
const width = extractWidthInches(product({
|
||||
specs: [{ name: "Product Dimensions", value: "35\"D x 83.4\"W x 31\"H" }]
|
||||
}));
|
||||
|
||||
assert.equal(width, 83.4);
|
||||
});
|
||||
|
||||
it("uses dimension order labels when W is not repeated in the value", () => {
|
||||
const width = extractWidthInches(product({
|
||||
specs: [{ name: "Item Dimensions D x W x H", value: "35 x 108 x 31 inches" }]
|
||||
}));
|
||||
|
||||
assert.equal(width, 108);
|
||||
});
|
||||
|
||||
it("ignores non-overall width specs before falling back to title width", () => {
|
||||
const width = extractWidthInches(product({
|
||||
title: "83 Inch Sofa Bed",
|
||||
specs: [
|
||||
{ name: "Seat Interior Width", value: "65 Inches" },
|
||||
{ name: "Arm Width", value: "5 Inches" },
|
||||
{ name: "Minimum Required Door Width", value: "72 Inches" }
|
||||
]
|
||||
}));
|
||||
|
||||
assert.equal(width, 83);
|
||||
});
|
||||
|
||||
it("formats unknown and decimal widths", () => {
|
||||
assert.equal(formatWidthInches(undefined), "unknown");
|
||||
assert.equal(formatWidthInches(83.4), "83.4\"");
|
||||
assert.equal(formatWidthInches(108), "108\"");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user