test(kijiji): add live parser suite

This commit is contained in:
2026-04-30 22:43:52 -04:00
parent ec2a26cedf
commit c1fa5168dc
2 changed files with 55 additions and 12 deletions

View File

@@ -2,9 +2,12 @@ import { describe, expect, test } from "bun:test";
import fetchEbayItems from "../../src/scrapers/ebay"; import fetchEbayItems from "../../src/scrapers/ebay";
const LIVE_RESULT_LIMIT = 3; const LIVE_RESULT_LIMIT = 3;
const LIVE_TEST_TIMEOUT_MS = 30_000;
describe("eBay live parser", () => { describe("eBay live parser", () => {
test("scrapes live search results into listing details", async () => { test(
"scrapes live search results into listing details",
async () => {
const results = await fetchEbayItems("iphone", 1, { const results = await fetchEbayItems("iphone", 1, {
maxItems: LIVE_RESULT_LIMIT, maxItems: LIVE_RESULT_LIMIT,
}); });
@@ -16,5 +19,7 @@ describe("eBay live parser", () => {
expect(listing.listingPrice.cents).toBeGreaterThanOrEqual(0); expect(listing.listingPrice.cents).toBeGreaterThanOrEqual(0);
expect(listing.listingPrice.currency.length).toBeGreaterThan(0); expect(listing.listingPrice.currency.length).toBeGreaterThan(0);
} }
}); },
LIVE_TEST_TIMEOUT_MS,
);
}); });

View File

@@ -0,0 +1,38 @@
import { describe, expect, test } from "bun:test";
import fetchKijijiItems from "../../src/scrapers/kijiji";
const LIVE_TEST_TIMEOUT_MS = 30_000;
describe("Kijiji live parser", () => {
test(
"scrapes live search results into detailed listings",
async () => {
const results = await fetchKijijiItems(
"iphone",
1,
"https://www.kijiji.ca",
{ maxPages: 1 },
{ includeImages: false, sellerDataDepth: "basic" },
);
expect(results.length).toBeGreaterThan(0);
for (const listing of results) {
if (!listing.listingPrice) {
throw new Error(`Expected listing price for ${listing.url}`);
}
if (typeof listing.listingPrice.cents !== "number") {
throw new Error(`Expected listing cents for ${listing.url}`);
}
if (!listing.listingPrice.currency) {
throw new Error(`Expected listing currency for ${listing.url}`);
}
expect(listing.url).toStartWith("https://www.kijiji.ca/");
expect(listing.title.length).toBeGreaterThan(0);
expect(listing.listingPrice.cents).toBeGreaterThanOrEqual(0);
expect(listing.listingPrice.currency.length).toBeGreaterThan(0);
}
},
LIVE_TEST_TIMEOUT_MS,
);
});