chore: biome lint and formatting

Signed-off-by: Dmytro Stanchiev <git@dmytros.dev>
This commit is contained in:
2026-04-28 19:21:16 -04:00
parent 49e90d45f8
commit 957e0f137b
10 changed files with 465 additions and 337 deletions

View File

@@ -48,16 +48,16 @@ export async function kijijiRoute(req: Request): Promise<Response> {
location: reqUrl.searchParams.get("location") || undefined,
category: reqUrl.searchParams.get("category") || undefined,
keywords: reqUrl.searchParams.get("keywords") || undefined,
sortBy: (reqUrl.searchParams.get("sortBy") as
| "relevancy"
| "date"
| "price"
| "distance"
| undefined) || undefined,
sortOrder: (reqUrl.searchParams.get("sortOrder") as
| "desc"
| "asc"
| undefined) || undefined,
sortBy:
(reqUrl.searchParams.get("sortBy") as
| "relevancy"
| "date"
| "price"
| "distance"
| undefined) || undefined,
sortOrder:
(reqUrl.searchParams.get("sortOrder") as "desc" | "asc" | undefined) ||
undefined,
maxPages,
priceMin,
priceMax,

View File

@@ -1,4 +1,4 @@
import { afterEach, beforeEach, describe, expect, mock, test } from "bun:test";
import { beforeEach, describe, expect, mock, test } from "bun:test";
const fetchFacebookItems = mock(() => Promise.resolve([{ title: "item" }]));
const fetchEbayItems = mock(() => Promise.resolve([{ title: "item" }]));
@@ -123,17 +123,22 @@ describe("API routes", () => {
),
);
expect(fetchEbayItems).toHaveBeenCalledWith("laptop", 1, {
minPrice: undefined,
maxPrice: undefined,
strictMode: false,
exclusions: [],
keywords: ["laptop"],
buyItNowOnly: true,
canadaOnly: true,
}, {
hideUnstableResults: 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 () => {
@@ -202,9 +207,7 @@ describe("API routes", () => {
const { ebayRoute } = await import("../src/routes/ebay");
await ebayRoute(
new Request(
"http://localhost/api/ebay?q=laptop&buyItNowOnly=true",
),
new Request("http://localhost/api/ebay?q=laptop&buyItNowOnly=true"),
);
expect(fetchEbayItems).toHaveBeenCalledWith("laptop", 1, {
@@ -242,9 +245,7 @@ describe("API routes", () => {
const { kijijiRoute } = await import("../src/routes/kijiji");
await kijijiRoute(
new Request(
"http://localhost/api/kijiji?q=laptop&maxPages=5",
),
new Request("http://localhost/api/kijiji?q=laptop&maxPages=5"),
);
expect(fetchKijijiItems).toHaveBeenCalledWith(
@@ -385,17 +386,17 @@ describe("API routes", () => {
test("ebayRoute forwards maxItems to core in default mode", async () => {
const { ebayRoute } = await import("../src/routes/ebay");
fetchEbayItems.mockImplementation(() =>
Promise.resolve([{ title: "a" }]),
);
fetchEbayItems.mockImplementation(() => Promise.resolve([{ title: "a" }]));
await ebayRoute(
new Request(
"http://localhost/api/ebay?q=laptop&maxItems=2",
),
new Request("http://localhost/api/ebay?q=laptop&maxItems=2"),
);
expect(fetchEbayItems).toHaveBeenCalledWith("laptop", 1, expect.objectContaining({ maxItems: 2 }));
expect(fetchEbayItems).toHaveBeenCalledWith(
"laptop",
1,
expect.objectContaining({ maxItems: 2 }),
);
});
test("ebayRoute passes through scraper payload unchanged in unstable mode", async () => {
@@ -419,9 +420,14 @@ describe("API routes", () => {
expect(body.unstableResults).toHaveLength(2);
expect(body.results[0].title).toBe("a");
expect(body.unstableResults[0].title).toBe("d");
expect(fetchEbayItems).toHaveBeenCalledWith("laptop", 1, expect.objectContaining({ maxItems: 4 }), {
hideUnstableResults: true,
});
expect(fetchEbayItems).toHaveBeenCalledWith(
"laptop",
1,
expect.objectContaining({ maxItems: 4 }),
{
hideUnstableResults: true,
},
);
});
test("ebayRoute forwards maxItems to core in unstable mode", async () => {
@@ -440,9 +446,14 @@ describe("API routes", () => {
),
);
expect(fetchEbayItems).toHaveBeenCalledWith("laptop", 1, expect.objectContaining({ maxItems: 2 }), {
hideUnstableResults: true,
});
expect(fetchEbayItems).toHaveBeenCalledWith(
"laptop",
1,
expect.objectContaining({ maxItems: 2 }),
{
hideUnstableResults: true,
},
);
});
test("ebayRoute returns 404 when unstable results are empty", async () => {
@@ -456,9 +467,7 @@ describe("API routes", () => {
);
const response = await ebayRoute(
new Request(
"http://localhost/api/ebay?q=laptop&unstableFilter=true",
),
new Request("http://localhost/api/ebay?q=laptop&unstableFilter=true"),
);
expect(response.status).toBe(404);
@@ -470,9 +479,7 @@ describe("API routes", () => {
const { ebayRoute } = await import("../src/routes/ebay");
const response = await ebayRoute(
new Request(
"http://localhost/api/ebay?q=laptop&maxItems=abc",
),
new Request("http://localhost/api/ebay?q=laptop&maxItems=abc"),
);
expect(response.status).toBe(400);
@@ -484,9 +491,7 @@ describe("API routes", () => {
const { facebookRoute } = await import("../src/routes/facebook");
const response = await facebookRoute(
new Request(
"http://localhost/api/facebook?q=laptop&maxItems=abc",
),
new Request("http://localhost/api/facebook?q=laptop&maxItems=abc"),
);
expect(response.status).toBe(400);
@@ -498,9 +503,7 @@ describe("API routes", () => {
const { ebayRoute } = await import("../src/routes/ebay");
const response = await ebayRoute(
new Request(
"http://localhost/api/ebay?q=laptop&minPrice=abc",
),
new Request("http://localhost/api/ebay?q=laptop&minPrice=abc"),
);
expect(response.status).toBe(400);
@@ -512,9 +515,7 @@ describe("API routes", () => {
const { ebayRoute } = await import("../src/routes/ebay");
const response = await ebayRoute(
new Request(
"http://localhost/api/ebay?q=laptop&maxPrice=abc",
),
new Request("http://localhost/api/ebay?q=laptop&maxPrice=abc"),
);
expect(response.status).toBe(400);
@@ -526,9 +527,7 @@ describe("API routes", () => {
const { kijijiRoute } = await import("../src/routes/kijiji");
const response = await kijijiRoute(
new Request(
"http://localhost/api/kijiji?q=laptop&maxPages=abc",
),
new Request("http://localhost/api/kijiji?q=laptop&maxPages=abc"),
);
expect(response.status).toBe(400);
@@ -540,9 +539,7 @@ describe("API routes", () => {
const { kijijiRoute } = await import("../src/routes/kijiji");
const response = await kijijiRoute(
new Request(
"http://localhost/api/kijiji?q=laptop&priceMin=abc",
),
new Request("http://localhost/api/kijiji?q=laptop&priceMin=abc"),
);
expect(response.status).toBe(400);
@@ -554,9 +551,7 @@ describe("API routes", () => {
const { kijijiRoute } = await import("../src/routes/kijiji");
const response = await kijijiRoute(
new Request(
"http://localhost/api/kijiji?q=laptop&priceMax=abc",
),
new Request("http://localhost/api/kijiji?q=laptop&priceMax=abc"),
);
expect(response.status).toBe(400);
@@ -568,9 +563,7 @@ describe("API routes", () => {
const { facebookRoute } = await import("../src/routes/facebook");
const response = await facebookRoute(
new Request(
"http://localhost/api/facebook?q=laptop&maxItems=-1",
),
new Request("http://localhost/api/facebook?q=laptop&maxItems=-1"),
);
expect(response.status).toBe(400);
@@ -582,9 +575,7 @@ describe("API routes", () => {
const { ebayRoute } = await import("../src/routes/ebay");
const response = await ebayRoute(
new Request(
"http://localhost/api/ebay?q=laptop&maxItems=-1",
),
new Request("http://localhost/api/ebay?q=laptop&maxItems=-1"),
);
expect(response.status).toBe(400);
@@ -596,9 +587,7 @@ describe("API routes", () => {
const { ebayRoute } = await import("../src/routes/ebay");
const response = await ebayRoute(
new Request(
"http://localhost/api/ebay?q=laptop&minPrice=-5",
),
new Request("http://localhost/api/ebay?q=laptop&minPrice=-5"),
);
expect(response.status).toBe(400);
@@ -610,9 +599,7 @@ describe("API routes", () => {
const { ebayRoute } = await import("../src/routes/ebay");
const response = await ebayRoute(
new Request(
"http://localhost/api/ebay?q=laptop&maxPrice=-10",
),
new Request("http://localhost/api/ebay?q=laptop&maxPrice=-10"),
);
expect(response.status).toBe(400);
@@ -624,9 +611,7 @@ describe("API routes", () => {
const { kijijiRoute } = await import("../src/routes/kijiji");
const response = await kijijiRoute(
new Request(
"http://localhost/api/kijiji?q=laptop&maxPages=-2",
),
new Request("http://localhost/api/kijiji?q=laptop&maxPages=-2"),
);
expect(response.status).toBe(400);
@@ -638,9 +623,7 @@ describe("API routes", () => {
const { kijijiRoute } = await import("../src/routes/kijiji");
const response = await kijijiRoute(
new Request(
"http://localhost/api/kijiji?q=laptop&priceMin=-5",
),
new Request("http://localhost/api/kijiji?q=laptop&priceMin=-5"),
);
expect(response.status).toBe(400);
@@ -652,9 +635,7 @@ describe("API routes", () => {
const { kijijiRoute } = await import("../src/routes/kijiji");
const response = await kijijiRoute(
new Request(
"http://localhost/api/kijiji?q=laptop&priceMax=-10",
),
new Request("http://localhost/api/kijiji?q=laptop&priceMax=-10"),
);
expect(response.status).toBe(400);