fix: align ebay route with spec and validate params
This commit is contained in:
@@ -399,7 +399,7 @@ describe("API routes", () => {
|
||||
expect(body).toHaveLength(0);
|
||||
});
|
||||
|
||||
test("ebayRoute limits total items with maxItems in unstable mode", async () => {
|
||||
test("ebayRoute passes through scraper payload unchanged in unstable mode", async () => {
|
||||
const { ebayRoute } = await import("../src/routes/ebay");
|
||||
|
||||
fetchEbayItems.mockImplementation(() =>
|
||||
@@ -416,10 +416,8 @@ describe("API routes", () => {
|
||||
);
|
||||
|
||||
const body = await response.json();
|
||||
const total = body.results.length + body.unstableResults.length;
|
||||
expect(total).toBe(4);
|
||||
expect(body.results).toHaveLength(3);
|
||||
expect(body.unstableResults).toHaveLength(1);
|
||||
expect(body.unstableResults).toHaveLength(2);
|
||||
expect(body.results[0].title).toBe("a");
|
||||
expect(body.unstableResults[0].title).toBe("d");
|
||||
});
|
||||
@@ -472,4 +470,74 @@ describe("API routes", () => {
|
||||
const body = await response.json();
|
||||
expect(body.message).toBe("Invalid maxItems parameter");
|
||||
});
|
||||
|
||||
test("ebayRoute returns 400 for invalid minPrice", async () => {
|
||||
const { ebayRoute } = await import("../src/routes/ebay");
|
||||
|
||||
const response = await ebayRoute(
|
||||
new Request(
|
||||
"http://localhost/api/ebay?q=laptop&minPrice=abc",
|
||||
),
|
||||
);
|
||||
|
||||
expect(response.status).toBe(400);
|
||||
const body = await response.json();
|
||||
expect(body.message).toBe("Invalid minPrice parameter");
|
||||
});
|
||||
|
||||
test("ebayRoute returns 400 for invalid maxPrice", async () => {
|
||||
const { ebayRoute } = await import("../src/routes/ebay");
|
||||
|
||||
const response = await ebayRoute(
|
||||
new Request(
|
||||
"http://localhost/api/ebay?q=laptop&maxPrice=abc",
|
||||
),
|
||||
);
|
||||
|
||||
expect(response.status).toBe(400);
|
||||
const body = await response.json();
|
||||
expect(body.message).toBe("Invalid maxPrice parameter");
|
||||
});
|
||||
|
||||
test("kijijiRoute returns 400 for invalid maxPages", async () => {
|
||||
const { kijijiRoute } = await import("../src/routes/kijiji");
|
||||
|
||||
const response = await kijijiRoute(
|
||||
new Request(
|
||||
"http://localhost/api/kijiji?q=laptop&maxPages=abc",
|
||||
),
|
||||
);
|
||||
|
||||
expect(response.status).toBe(400);
|
||||
const body = await response.json();
|
||||
expect(body.message).toBe("Invalid maxPages parameter");
|
||||
});
|
||||
|
||||
test("kijijiRoute returns 400 for invalid priceMin", async () => {
|
||||
const { kijijiRoute } = await import("../src/routes/kijiji");
|
||||
|
||||
const response = await kijijiRoute(
|
||||
new Request(
|
||||
"http://localhost/api/kijiji?q=laptop&priceMin=abc",
|
||||
),
|
||||
);
|
||||
|
||||
expect(response.status).toBe(400);
|
||||
const body = await response.json();
|
||||
expect(body.message).toBe("Invalid priceMin parameter");
|
||||
});
|
||||
|
||||
test("kijijiRoute returns 400 for invalid priceMax", async () => {
|
||||
const { kijijiRoute } = await import("../src/routes/kijiji");
|
||||
|
||||
const response = await kijijiRoute(
|
||||
new Request(
|
||||
"http://localhost/api/kijiji?q=laptop&priceMax=abc",
|
||||
),
|
||||
);
|
||||
|
||||
expect(response.status).toBe(400);
|
||||
const body = await response.json();
|
||||
expect(body.message).toBe("Invalid priceMax parameter");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user