refactor: remove api cookie query overrides

This commit is contained in:
2026-04-21 21:47:37 -04:00
parent 918ee92441
commit 1a2c0cf6b8
3 changed files with 56 additions and 15 deletions

View File

@@ -0,0 +1,53 @@
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,
});
});
});