100 lines
3.6 KiB
TypeScript
100 lines
3.6 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import { describe, it } from "node:test";
|
|
|
|
import { createMarkdownReport, createResponse } from "../src/report.js";
|
|
|
|
describe("report", () => {
|
|
it("creates a structured JSON response", () => {
|
|
const response = createResponse({
|
|
query: "usb c cable",
|
|
filters: { includeKeywords: [], excludeKeywords: [], minReviews: 1000 },
|
|
limit: 1,
|
|
maxSearchPages: 2,
|
|
results: [],
|
|
filteredOutCount: 4,
|
|
warnings: ["partial extraction"],
|
|
now: () => new Date("2026-04-15T00:00:00.000Z")
|
|
});
|
|
|
|
assert.equal(response.source.site, "amazon.com");
|
|
assert.equal(response.filteredOutCount, 4);
|
|
assert.equal(response.source.scrapedAt, "2026-04-15T00:00:00.000Z");
|
|
});
|
|
|
|
it("creates concise markdown with product details and warnings", () => {
|
|
const markdown = createMarkdownReport(createResponse({
|
|
query: "usb c cable",
|
|
filters: { includeKeywords: [], excludeKeywords: [] },
|
|
limit: 1,
|
|
maxSearchPages: 2,
|
|
filteredOutCount: 0,
|
|
warnings: ["price missing for one item"],
|
|
now: () => new Date("2026-04-15T00:00:00.000Z"),
|
|
results: [{
|
|
asin: "B0TEST0001",
|
|
title: "USB-C Cable",
|
|
url: "https://www.amazon.com/dp/B0TEST0001",
|
|
price: { amount: 9.99, currency: "USD", display: "$9.99" },
|
|
rating: 4.7,
|
|
reviewCount: 1234,
|
|
delivery: { display: "FREE delivery Tomorrow", free: true },
|
|
specs: [{ name: "Length", value: "6 ft" }],
|
|
bullets: ["Braided cable"],
|
|
matchedFilters: [],
|
|
missingFields: ["starBreakdown"],
|
|
extractionNotes: []
|
|
}]
|
|
}));
|
|
|
|
assert.match(markdown, /USB-C Cable/);
|
|
assert.match(markdown, /\$9\.99/);
|
|
assert.match(markdown, /4\.7 stars/);
|
|
assert.match(markdown, /price missing/);
|
|
assert.match(markdown, /https:\/\/www\.amazon\.com\/dp\/B0TEST0001/);
|
|
});
|
|
|
|
it("creates a chat-safe template with direct product links and constraint status markers", () => {
|
|
const markdown = createMarkdownReport(createResponse({
|
|
query: "sofa bed beige",
|
|
filters: {
|
|
includeKeywords: [],
|
|
excludeKeywords: [],
|
|
minRating: 4,
|
|
minReviews: 200,
|
|
minWidthInches: 77,
|
|
requirePrime: true,
|
|
deliveryBy: "tomorrow"
|
|
},
|
|
limit: 10,
|
|
maxSearchPages: 2,
|
|
filteredOutCount: 3,
|
|
warnings: [],
|
|
now: () => new Date("2026-04-15T00:00:00.000Z"),
|
|
results: [{
|
|
asin: "B0SOFABED1",
|
|
title: "HONBAY Modular Sectional Sleeper",
|
|
url: "https://www.amazon.com/dp/B0SOFABED1",
|
|
price: { amount: 539.99, currency: "USD", display: "$539.99" },
|
|
rating: 4.1,
|
|
reviewCount: 242,
|
|
delivery: { display: "FREE delivery Tomorrow", free: true, prime: true },
|
|
specs: [{ name: "Item Dimensions D x W x H", value: "83.4\"D x 83.4\"W x 35\"H" }],
|
|
bullets: [],
|
|
matchedFilters: [],
|
|
missingFields: ["starBreakdown"],
|
|
extractionNotes: []
|
|
}]
|
|
}));
|
|
|
|
assert.match(markdown, /## Best Matches/);
|
|
assert.doesNotMatch(markdown, /\| # \| Product \| Price \| Rating \| Reviews \| Width \| Prime \| Delivery \| Link \|/);
|
|
assert.doesNotMatch(markdown, /\[Amazon\]\(https:\/\/www\.amazon\.com\/dp\/B0SOFABED1\)/);
|
|
assert.match(markdown, /HONBAY Modular Sectional Sleeper/);
|
|
assert.match(markdown, /Link: https:\/\/www\.amazon\.com\/dp\/B0SOFABED1/);
|
|
assert.match(markdown, /83\.4" OK/);
|
|
assert.match(markdown, /Prime OK/);
|
|
assert.match(markdown, /Tomorrow OK/);
|
|
assert.match(markdown, /Price: \$539\.99/);
|
|
});
|
|
});
|