test(kijiji): add live parser suite
This commit is contained in:
@@ -2,9 +2,12 @@ import { describe, expect, test } from "bun:test";
|
||||
import fetchEbayItems from "../../src/scrapers/ebay";
|
||||
|
||||
const LIVE_RESULT_LIMIT = 3;
|
||||
const LIVE_TEST_TIMEOUT_MS = 30_000;
|
||||
|
||||
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, {
|
||||
maxItems: LIVE_RESULT_LIMIT,
|
||||
});
|
||||
@@ -16,5 +19,7 @@ describe("eBay live parser", () => {
|
||||
expect(listing.listingPrice.cents).toBeGreaterThanOrEqual(0);
|
||||
expect(listing.listingPrice.currency.length).toBeGreaterThan(0);
|
||||
}
|
||||
});
|
||||
},
|
||||
LIVE_TEST_TIMEOUT_MS,
|
||||
);
|
||||
});
|
||||
|
||||
38
packages/core/test/live/kijiji.live.test.ts
Normal file
38
packages/core/test/live/kijiji.live.test.ts
Normal 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,
|
||||
);
|
||||
});
|
||||
Reference in New Issue
Block a user