Files
stef-openclaw-skills/skills/amazon-shopping/tests/report.test.ts
T

56 lines
1.9 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/);
});
});