feat: expose unstable mode in api routes
This commit is contained in:
@@ -2,10 +2,12 @@ import { afterEach, beforeEach, describe, expect, mock, test } from "bun:test";
|
||||
|
||||
const fetchFacebookItems = mock(() => Promise.resolve([{ title: "item" }]));
|
||||
const fetchEbayItems = mock(() => Promise.resolve([{ title: "item" }]));
|
||||
const fetchKijijiItems = mock(() => Promise.resolve([{ title: "item" }]));
|
||||
|
||||
mock.module("@marketplace-scrapers/core", () => ({
|
||||
fetchFacebookItems,
|
||||
fetchEbayItems,
|
||||
fetchKijijiItems,
|
||||
}));
|
||||
|
||||
describe("API routes", () => {
|
||||
@@ -18,11 +20,16 @@ describe("API routes", () => {
|
||||
fetchEbayItems.mockImplementation(() =>
|
||||
Promise.resolve([{ title: "item" }]),
|
||||
);
|
||||
fetchKijijiItems.mockReset();
|
||||
fetchKijijiItems.mockImplementation(() =>
|
||||
Promise.resolve([{ title: "item" }]),
|
||||
);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
fetchFacebookItems.mockClear();
|
||||
fetchEbayItems.mockClear();
|
||||
fetchKijijiItems.mockClear();
|
||||
});
|
||||
|
||||
test("facebookRoute ignores cookies query parameter", async () => {
|
||||
@@ -56,4 +63,99 @@ describe("API routes", () => {
|
||||
canadaOnly: true,
|
||||
});
|
||||
});
|
||||
|
||||
test("kijijiRoute ignores cookies query parameter", async () => {
|
||||
const { kijijiRoute } = await import("../src/routes/kijiji");
|
||||
|
||||
await kijijiRoute(
|
||||
new Request(
|
||||
"http://localhost/api/kijiji?q=laptop&cookies=s%3D1&maxPages=3",
|
||||
),
|
||||
);
|
||||
|
||||
expect(fetchKijijiItems).toHaveBeenCalledWith(
|
||||
"laptop",
|
||||
4,
|
||||
"https://www.kijiji.ca",
|
||||
{
|
||||
location: undefined,
|
||||
category: undefined,
|
||||
keywords: undefined,
|
||||
sortBy: null,
|
||||
sortOrder: null,
|
||||
maxPages: 3,
|
||||
priceMin: undefined,
|
||||
priceMax: undefined,
|
||||
cookies: "s=1",
|
||||
},
|
||||
{},
|
||||
);
|
||||
});
|
||||
|
||||
test("facebookRoute forwards unstableFilter=true to core", async () => {
|
||||
const { facebookRoute } = await import("../src/routes/facebook");
|
||||
|
||||
await facebookRoute(
|
||||
new Request(
|
||||
"http://localhost/api/facebook?q=laptop&location=toronto&maxItems=3&unstableFilter=true",
|
||||
),
|
||||
);
|
||||
|
||||
expect(fetchFacebookItems).toHaveBeenCalledWith("laptop", 1, "toronto", 3, {
|
||||
hideUnstableResults: true,
|
||||
});
|
||||
});
|
||||
|
||||
test("ebayRoute forwards unstableFilter=true to core", async () => {
|
||||
const { ebayRoute } = await import("../src/routes/ebay");
|
||||
|
||||
await ebayRoute(
|
||||
new Request(
|
||||
"http://localhost/api/ebay?q=laptop&buyItNowOnly=true&unstableFilter=true",
|
||||
),
|
||||
);
|
||||
|
||||
expect(fetchEbayItems).toHaveBeenCalledWith("laptop", 1, {
|
||||
minPrice: undefined,
|
||||
maxPrice: undefined,
|
||||
strictMode: false,
|
||||
exclusions: [],
|
||||
keywords: ["laptop"],
|
||||
buyItNowOnly: true,
|
||||
canadaOnly: true,
|
||||
}, {
|
||||
hideUnstableResults: true,
|
||||
});
|
||||
});
|
||||
|
||||
test("kijijiRoute forwards unstableFilter=true to core", async () => {
|
||||
const { kijijiRoute } = await import("../src/routes/kijiji");
|
||||
|
||||
await kijijiRoute(
|
||||
new Request(
|
||||
"http://localhost/api/kijiji?q=laptop&maxPages=5&unstableFilter=true",
|
||||
),
|
||||
);
|
||||
|
||||
expect(fetchKijijiItems).toHaveBeenCalledWith(
|
||||
"laptop",
|
||||
4,
|
||||
"https://www.kijiji.ca",
|
||||
{
|
||||
location: undefined,
|
||||
category: undefined,
|
||||
keywords: undefined,
|
||||
sortBy: null,
|
||||
sortOrder: null,
|
||||
maxPages: 5,
|
||||
priceMin: undefined,
|
||||
priceMax: undefined,
|
||||
cookies: undefined,
|
||||
},
|
||||
{},
|
||||
{
|
||||
hideUnstableResults: true,
|
||||
},
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user