feat: add maxItems support to ebay scraper
This commit is contained in:
@@ -552,4 +552,86 @@ describe("eBay Scraper Cookie Handling", () => {
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
test("respects maxItems in default mode", async () => {
|
||||
global.fetch = mock(() =>
|
||||
Promise.resolve({
|
||||
ok: true,
|
||||
text: () =>
|
||||
Promise.resolve(`
|
||||
<html><body>
|
||||
<li class="s-item">
|
||||
<a href="https://www.ebay.ca/itm/1"></a>
|
||||
<h3>First Bundle</h3>
|
||||
<span class="s-item__price">CA $100.00</span>
|
||||
</li>
|
||||
<li class="s-item">
|
||||
<a href="https://www.ebay.ca/itm/2"></a>
|
||||
<h3>Second Bundle</h3>
|
||||
<span class="s-item__price">CA $110.00</span>
|
||||
</li>
|
||||
<li class="s-item">
|
||||
<a href="https://www.ebay.ca/itm/3"></a>
|
||||
<h3>Third Bundle</h3>
|
||||
<span class="s-item__price">CA $70.00</span>
|
||||
</li>
|
||||
</body></html>
|
||||
`),
|
||||
}),
|
||||
) as typeof fetch;
|
||||
|
||||
const results = await fetchEbayItems("laptop", 1000, { maxItems: 2 });
|
||||
|
||||
expect(results).toHaveLength(2);
|
||||
expect(results[0]).toEqual(
|
||||
expect.objectContaining({ title: "First Bundle" }),
|
||||
);
|
||||
expect(results[1]).toEqual(
|
||||
expect.objectContaining({ title: "Second Bundle" }),
|
||||
);
|
||||
});
|
||||
|
||||
test("respects maxItems in unstable mode", async () => {
|
||||
global.fetch = mock(() =>
|
||||
Promise.resolve({
|
||||
ok: true,
|
||||
text: () =>
|
||||
Promise.resolve(`
|
||||
<html><body>
|
||||
<li class="s-item">
|
||||
<a href="https://www.ebay.ca/itm/1"></a>
|
||||
<h3>First Bundle</h3>
|
||||
<span class="s-item__price">CA $100.00</span>
|
||||
</li>
|
||||
<li class="s-item">
|
||||
<a href="https://www.ebay.ca/itm/2"></a>
|
||||
<h3>Second Bundle</h3>
|
||||
<span class="s-item__price">CA $110.00</span>
|
||||
</li>
|
||||
<li class="s-item">
|
||||
<a href="https://www.ebay.ca/itm/3"></a>
|
||||
<h3>Third Bundle</h3>
|
||||
<span class="s-item__price">CA $70.00</span>
|
||||
</li>
|
||||
</body></html>
|
||||
`),
|
||||
}),
|
||||
) as typeof fetch;
|
||||
|
||||
const results = await fetchEbayItems(
|
||||
"laptop",
|
||||
1000,
|
||||
{ maxItems: 2 },
|
||||
{ hideUnstableResults: true },
|
||||
);
|
||||
|
||||
expect(results.results).toHaveLength(2);
|
||||
expect(results.unstableResults).toHaveLength(0);
|
||||
expect(results.results[0]).toEqual(
|
||||
expect.objectContaining({ title: "First Bundle" }),
|
||||
);
|
||||
expect(results.results[1]).toEqual(
|
||||
expect.objectContaining({ title: "Second Bundle" }),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user