refactor: remove api cookie query overrides
This commit is contained in:
53
packages/api-server/test/routes.test.ts
Normal file
53
packages/api-server/test/routes.test.ts
Normal 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,
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user