54 lines
1.6 KiB
TypeScript
54 lines
1.6 KiB
TypeScript
import { afterEach, beforeEach, describe, expect, mock, test } from "bun:test";
|
|
|
|
const fetchFacebookItems = mock(() => Promise.resolve([{ title: "item" }]));
|
|
const fetchEbayItems = mock(() => Promise.resolve([{ title: "item" }]));
|
|
|
|
mock.module("@marketplace-scrapers/core", () => ({
|
|
fetchFacebookItems,
|
|
fetchEbayItems,
|
|
}));
|
|
|
|
describe("API routes", () => {
|
|
beforeEach(() => {
|
|
fetchFacebookItems.mockReset();
|
|
fetchFacebookItems.mockImplementation(() => Promise.resolve([{ title: "item" }]));
|
|
fetchEbayItems.mockReset();
|
|
fetchEbayItems.mockImplementation(() => Promise.resolve([{ title: "item" }]));
|
|
});
|
|
|
|
afterEach(() => {
|
|
fetchFacebookItems.mockClear();
|
|
fetchEbayItems.mockClear();
|
|
});
|
|
|
|
test("facebookRoute ignores cookies query parameter", async () => {
|
|
const { facebookRoute } = await import("../src/routes/facebook");
|
|
|
|
await facebookRoute(
|
|
new Request(
|
|
"http://localhost/api/facebook?q=laptop&location=toronto&maxItems=3&cookies=c_user=1",
|
|
),
|
|
);
|
|
|
|
expect(fetchFacebookItems).toHaveBeenCalledWith("laptop", 1, "toronto", 3);
|
|
});
|
|
|
|
test("ebayRoute ignores cookies query parameter", async () => {
|
|
const { ebayRoute } = await import("../src/routes/ebay");
|
|
|
|
await ebayRoute(
|
|
new Request("http://localhost/api/ebay?q=laptop&cookies=s%3D1&buyItNowOnly=true"),
|
|
);
|
|
|
|
expect(fetchEbayItems).toHaveBeenCalledWith("laptop", 1, {
|
|
minPrice: undefined,
|
|
maxPrice: undefined,
|
|
strictMode: false,
|
|
exclusions: [],
|
|
keywords: ["laptop"],
|
|
buyItNowOnly: true,
|
|
canadaOnly: true,
|
|
});
|
|
});
|
|
});
|