fix: align scraper unstable mode behavior

This commit is contained in:
2026-04-22 23:36:00 -04:00
parent c7fc8352ac
commit 08edfa8097
5 changed files with 54 additions and 18 deletions

View File

@@ -38,9 +38,7 @@ describe("eBay Scraper Cookie Handling", () => {
const warnMock = mock(() => {});
console.warn = warnMock;
await fetchEbayItems("laptop", 1000, {
cookies: "s=from-request",
});
await fetchEbayItems("laptop", 1000);
expect(global.fetch).toHaveBeenCalledTimes(1);
@@ -53,6 +51,30 @@ describe("eBay Scraper Cookie Handling", () => {
);
});
test("keeps relative item links on the ebay.ca host", async () => {
global.fetch = mock(() =>
Promise.resolve({
ok: true,
text: () =>
Promise.resolve(`
<html><body>
<li class="s-item">
<a href="/itm/123"></a>
<h3>Stable Laptop Bundle</h3>
<span class="s-item__price">CA $100.00</span>
</li>
</body></html>
`),
}),
) as typeof fetch;
const results = await fetchEbayItems("laptop", 1000);
expect(results).toEqual([
expect.objectContaining({ url: "https://www.ebay.ca/itm/123" }),
]);
});
test("returns results and unstableResults when unstable mode is enabled", async () => {
global.fetch = mock(() =>
Promise.resolve({

View File

@@ -521,7 +521,7 @@ describe("Facebook Marketplace Scraper Core Tests", () => {
});
});
test("unstable mode keeps MAX_ITEMS as the classification boundary", async () => {
test("unstable mode classifies before the final MAX_ITEMS limit", async () => {
const mockSearchHtml = `<html><body><script>"XCometMarketplaceSearchController"</script><script>${JSON.stringify({
payload: {
resultGroups: [
@@ -545,10 +545,10 @@ describe("Facebook Marketplace Scraper Core Tests", () => {
node: {
listing: {
id: "2",
marketplace_listing_title: "Boundary Cheap Chair",
marketplace_listing_title: "Second Boundary Stable Chair",
listing_price: {
amount: "50.00",
formatted_amount: "CA$50",
amount: "110.00",
formatted_amount: "CA$110",
currency: "CAD",
},
is_live: true,
@@ -559,10 +559,10 @@ describe("Facebook Marketplace Scraper Core Tests", () => {
node: {
listing: {
id: "3",
marketplace_listing_title: "Past Boundary Chair",
marketplace_listing_title: "Past Boundary Cheap Chair",
listing_price: {
amount: "110.00",
formatted_amount: "CA$110",
amount: "70.00",
formatted_amount: "CA$70",
currency: "CAD",
},
is_live: true,
@@ -591,9 +591,12 @@ describe("Facebook Marketplace Scraper Core Tests", () => {
});
expect(results).toEqual({
results: [expect.objectContaining({ title: "Boundary Stable Chair" })],
results: [
expect.objectContaining({ title: "Boundary Stable Chair" }),
expect.objectContaining({ title: "Second Boundary Stable Chair" }),
],
unstableResults: [
expect.objectContaining({ title: "Boundary Cheap Chair" }),
expect.objectContaining({ title: "Past Boundary Cheap Chair" }),
],
});
});